Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Still puzzled by floats

by blakem (Monsignor)
on Oct 07, 2002 at 06:30 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-19 18:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found