Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Simple math gone wrong

by tachyon (Chancellor)
on Sep 04, 2003 at 12:24 UTC ( #288843=note: print w/replies, xml ) Need Help??


in reply to Simple math gone wrong

It all comes back to how the computer actually stores and processes numbers. Floating point numbers are by nature inexact. If you need exact you need to use integer math and then correct for decimal places. See Bug? 1+1 != 2, Filthy Floats or the IEEE stuff here including What Every Computer Scientist Should Know about Floating-Point Arithmetic

If you don't really care to much just use printf/sprintf

printf '%.6f', 1062676995.614963 - 1062676995.594934 __DATA__ 0.020029

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2019-12-13 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?