Page 1 of 1

Float -1 to 1 / number of bits

Posted: Tue Feb 12, 2013 12:32 pm
by chackl
Hello!

How many bits does a green float and stream float have between -1 and 1?

Well if a float has 32bit from verry high to verry low - are 32 bit accurate enough for the falues -1 to 1???

Regards

Re: Float -1 to 1 / number of bits

Posted: Tue Feb 12, 2013 1:37 pm
by support
Yes the green Floats are 32 bit, you can see a full explanation here:

http://en.wikipedia.org/wiki/Single-precision_floating-point_format

If you need more precision Ruby uses double precision.

Re: Float -1 to 1 / number of bits

Posted: Tue Feb 12, 2013 5:18 pm
by MyCo
From -1 to 1 there are 31 Bits in use, but when you also require flags like #IND,#INF,#NAN there are 32bits in use, too. As Explanation: if the second MSB is set, the float value is always above or equal abs(2)... so this bit is never used in -1 to 1 range. The resolution between 1 and -1 (including 1 and -1) is 1.073.741.825 steps... But in Float, there is also 0 and -0, so if you don't count that in, there is also one step less.