### Re: eq vs ==

by LanX (Bishop)
 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.

UPDATE:

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".

EXAMPLE:

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!

Create A New User
Node Status?
node history
Node Type: note [id://806200]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2018-06-24 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (126 votes). Check out past polls.

Notices?