http://www.codeguru.com/forum/showthread.php?t=323835
Regards,
Paul McKenzie
Printable View
http://www.codeguru.com/forum/showthread.php?t=323835
Regards,
Paul McKenzie
1/3 cannot be represented by a decimal number, because 3 is not a divisor of 10.Quote:
Originally Posted by sandodo
Similarly, 1/5 cannot be represented by a binary float, because 5 is not a divisor of 2.
Numbers that can be represented by binary floats are sums of powers of two.
It's easy to see that these numbers can be expressed with this form:
integer*2**i where i is a negative or positive integer.
Thanks Paul McKenzie for the helpful link. :wave:
Thanks. the example of 1/3 cannot be represent by decimal number is very good.Quote:
Originally Posted by SuperKoko
However for, cannot understand...... :confused:Code:integer*2**i
Basically, this means that the only decimal fractions that can be represented exactly in binary are sums of powers (negative or positive) of 2.Quote:
Originally Posted by sandodo
For example:
0.5 can be represented exactly in binary, since:
0.5 = 1/2 = 1 * 2^(-1) (where "^" means "to the power of"). The "**" that Superkoko mentioned is the same as "to the power or".
Similarly, 3/16 can be represented in binary exactly since:
3/16 = 3/(2*8) = 3/(2^(-3)).
So basically if the denominator is 1, 2, 4, 8, 16, 32, 64, etc. the number can be represented in binary exactly.
Regards,
Paul McKenzie
The ** is for "to-the-power". +ve as well as -ve.
Right.Quote:
Originally Posted by exterminator
Good thing that you mention it, since it wasn't obvious.
I used the ** operator, in order to avoid confusion with the C xor operator ^.
But, I probably caused confusion with this least used convention.
Thanks a lot to all of you. You guys are great.
All my best!