P
Phil Tomson
First release. This is the first gem I've ever made and I've gotta say
it was pretty-much painless. There's even a C extension involved. Kudos
to the Rubygems folks. Please let me know if there are any problems with
the gem.
From the README:
FixedPt class
-------------
The FixedPt class is used for representing fixed point numbers and
it defines mathematical operations on them.
This class is not very useful unless you are trying to model hardware -
if you're doing that it can be very useful. If you're doing web
development, there's no need to read further.
What's a fixed point number?
-------------------------------------
First off a fixed point number is represented by a limited number of
bits.
You can define that limit when you construct a FixedPt:
fp = FixedPt.new(9.25,6,2)
Which means "construct a fixed point number with the value of 9.25
represented by 6 total bits with the binary point at 2" or in other
words, the number 9.25 with 4 bits for the integer part and 2 bits for
the fractional part,like so:
"1001.01"
^
|+----- That's the binary point. It's just like a decimal point,
but it's for binary numbers.
Actually, to be honest, if you have to ask what a fixed point number is
you probably aren't interested in this package.
Why would I want to use this?
------------------------------
You probably don't want to unless you're modeling a hardware design in
software. ( I suppose you could use FixedPt if you think that math is
just too fast in Ruby these days
For example, say you're doing some sort of Digital Signal Processing
(DSP)and you'd like to implement a particlular algorithm in an FPGA. But
before you reach for the HDL and simulator you want to try an
implementation in a programming language (a real programming language
like Ruby, of course, not Matlab to see if your algorithm works.
However, because you know that you'll be implementing this eventually in
hardware and you also know that you don't have infinite precision in
hardware(generally speaking) so you'd like to see what effect arithmetic on
limited precision numbers (Fixed Point numbers) will have on your algorithm.
How many fractional bits do you need to use to accurately represent
exp(-x) in your design, for example. How many fractional and integral
bits will you need to represent your numbers? These are questions you
can find answers to by using this handy FixedPt class.
Is it slow?
-----------
If you don't have a C compiler, you bet it'll be slow. It's mostly in
pure Ruby. However, there is some sneakiness afoot to help speed things up.
If you do happen to have a C compiler then some of the methods of the
class could end up being implemented in C which will speed things up. I say
'could end up being implemented in C' because it all depends on your
setup, but not to worry, even if you don't have a C compiler and even if
you don't have Ruby setup right to create extensions it'll still work -
just more slowly; about half as fast, actually.
Hopefully, I'll add more C code in the future to speed things up more.
Are there bugs?
---------------
It's a sure bet.
Lots of unit tests need to be written yet.
What else do I need to know?
----------------------------
* You can do math on FixedPt numbers (+-*/)
* You can choose from two different overflow handlers:
1) saturate (the default): FixedPt(9,4,1).to_binary #=>"111.1"
2) truncate: FixedPt(9,4,1,:truncate) #=>"001.0"
* After running your algorithm you can check to see if any of the FixedPt
numbers have overflowed and see what the maximum number was that caused
the overflow. You can then use this information to size your actual
hardware
registers.
Where can I find it?
--------------------
http://rubyforge.org/projects/fixedpt/
How Do I install it?
---------------------
Use gem:
gem install FixedPt-x.y.z.gem
What if I run into some of those bugs?
--------------------------------------
Send me an email:
philtomson<at>gmail.com
License
-------
Ruby's
TODO:
* Add more docs besides this README
* Add examples
it was pretty-much painless. There's even a C extension involved. Kudos
to the Rubygems folks. Please let me know if there are any problems with
the gem.
From the README:
FixedPt class
-------------
The FixedPt class is used for representing fixed point numbers and
it defines mathematical operations on them.
This class is not very useful unless you are trying to model hardware -
if you're doing that it can be very useful. If you're doing web
development, there's no need to read further.
What's a fixed point number?
-------------------------------------
First off a fixed point number is represented by a limited number of
bits.
You can define that limit when you construct a FixedPt:
fp = FixedPt.new(9.25,6,2)
Which means "construct a fixed point number with the value of 9.25
represented by 6 total bits with the binary point at 2" or in other
words, the number 9.25 with 4 bits for the integer part and 2 bits for
the fractional part,like so:
"1001.01"
^
|+----- That's the binary point. It's just like a decimal point,
but it's for binary numbers.
Actually, to be honest, if you have to ask what a fixed point number is
you probably aren't interested in this package.
Why would I want to use this?
------------------------------
You probably don't want to unless you're modeling a hardware design in
software. ( I suppose you could use FixedPt if you think that math is
just too fast in Ruby these days
For example, say you're doing some sort of Digital Signal Processing
(DSP)and you'd like to implement a particlular algorithm in an FPGA. But
before you reach for the HDL and simulator you want to try an
implementation in a programming language (a real programming language
like Ruby, of course, not Matlab to see if your algorithm works.
However, because you know that you'll be implementing this eventually in
hardware and you also know that you don't have infinite precision in
hardware(generally speaking) so you'd like to see what effect arithmetic on
limited precision numbers (Fixed Point numbers) will have on your algorithm.
How many fractional bits do you need to use to accurately represent
exp(-x) in your design, for example. How many fractional and integral
bits will you need to represent your numbers? These are questions you
can find answers to by using this handy FixedPt class.
Is it slow?
-----------
If you don't have a C compiler, you bet it'll be slow. It's mostly in
pure Ruby. However, there is some sneakiness afoot to help speed things up.
If you do happen to have a C compiler then some of the methods of the
class could end up being implemented in C which will speed things up. I say
'could end up being implemented in C' because it all depends on your
setup, but not to worry, even if you don't have a C compiler and even if
you don't have Ruby setup right to create extensions it'll still work -
just more slowly; about half as fast, actually.
Hopefully, I'll add more C code in the future to speed things up more.
Are there bugs?
---------------
It's a sure bet.
Lots of unit tests need to be written yet.
What else do I need to know?
----------------------------
* You can do math on FixedPt numbers (+-*/)
* You can choose from two different overflow handlers:
1) saturate (the default): FixedPt(9,4,1).to_binary #=>"111.1"
2) truncate: FixedPt(9,4,1,:truncate) #=>"001.0"
* After running your algorithm you can check to see if any of the FixedPt
numbers have overflowed and see what the maximum number was that caused
the overflow. You can then use this information to size your actual
hardware
registers.
Where can I find it?
--------------------
http://rubyforge.org/projects/fixedpt/
How Do I install it?
---------------------
Use gem:
gem install FixedPt-x.y.z.gem
What if I run into some of those bugs?
--------------------------------------
Send me an email:
philtomson<at>gmail.com
License
-------
Ruby's
TODO:
* Add more docs besides this README
* Add examples