"be consistent" PerlMonks

### Re: Still puzzled by floats

by blakem (Monsignor)
 on Oct 07, 2002 at 06:30 UTC ( #203258=note: print w/replies, xml ) Need Help??

in reply to Still puzzled by floats

The decimal 0.95 can be represented in base 10 as:
```9/10 + 5/100
How would you represent that in binary?
```1/2 + 1/4 + 1/8 + 1/16 + 0/32 + 0/64 + 1/128 + 1/256 +
0/512 + 0/1024 + 1/2048 + 1/4096 ...
No matter how far you take that series it will *never* be exactly 0.95. The binary representation of 0.95 takes an infinite number of bits.

0.95(10) ≈ 0.1111 0011 0011 0011 0011 0011 0011(2)

But those last four bits repeat forever. Its exactly like writing 1/3 in base 10:

1/3 ≈ 0.33333333333333333333333333333333(10)

-Blake

Create A New User
Node Status?
node history
Node Type: note [id://203258]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2019-08-21 00:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?