Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: int($x) gives strange result

by ikegami (Patriarch)
on Aug 24, 2009 at 06:34 UTC ( [id://790753]=note: print w/replies, xml ) Need Help??


in reply to int($x) gives strange result

Just like some numbers are periodic in decimal (1/3), some numbers are periodic in binary. 1.15 is one of them.

____ 1.15 (b10) = 1.0010010 (b2)

It can't be represented exactly as a float without infinite storage.

>perl -e"printf qq{%0.16e\n}, 1.15" 1.1499999999999999e+000

Previously mentioned sprintf "works" because it rounds instead of truncating.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found