Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: eq vs ==

by LanX (Canon)
on Nov 10, 2009 at 12:06 UTC ( #806200=note: print w/ replies, xml ) Need Help??

in reply to eq vs ==

The binary floating point representation produces this asymmetry. It's not only what you see as decimal fraction after the point which determines how the binary mantissa is calculated, the digits before also get into the mantissa.


From 23.2 to 0.2 you already skipped 2 decimal steps in exponentiation.

These precision errors resulting from base transformations are periodic, if you just shift the exponent long enough you get the same mantissa at the lower end, such that the difference is again 0 at the "tail".


0.2 = 1/5 can't be represented as a binary fraction without infinite repetition, the same way you can hardly represent 1/7 in a decimal fraction. (NOTE: 10 and 7 are coprime, like 2 and 5 are!)

Now try to calculate (10+1/7)-1/7 to a decimal base but with a finite mantissa!

You'll get

10 + 1/7= 1.01428571428571 * 10^1 1/7= 1.42857142857143 * 10^-1

Clearly, the lower ends of the mantissa to the base ten are not symmetric ...

... but to the base 7 both numbers would be highly symmetric again, no matter what you add before the point. Hence no error!

 13.1 - 0.1  (base 7)

Hope this calculation helps to visualize what happens with "obvious calculations" when switching bases!

Cheers Rolf

PS: Further reading: Humans have too many fingers!

Comment on Re: eq vs ==
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://806200]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2014-09-19 13:12 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (138 votes), past polls