Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Floating point problems

by bluescreen (Friar)
on Oct 24, 2010 at 15:15 UTC ( [id://867044]=note: print w/replies, xml ) Need Help??


in reply to Re: Floating point problems
in thread Floating point problems

Yeah int is very clear about that, but print isn't.

Am I asking too much if I see something prints 3 the int of that to be 3 ?

Replies are listed 'Best First'.
Re^3: Floating point problems
by BrowserUk (Patriarch) on Oct 24, 2010 at 16:18 UTC
    Am I asking too much if I see something prints 3 the int of that to be 3 ?

    In a word: yes.

    int has a very clearly defined meaning: truncate to an integer. And that behaviour is required for many algorithms.

    It never "rounds-up" as print does:

    printf( "%.16f ", 3-$_ ), print 3-$_ for map 10**-$_, 1 .. 16;; 2.8999999999999999 2.9 2.9900000000000002 2.99 2.9990000000000001 2.999 2.9998999999999998 2.9999 2.9999899999999999 2.99999 2.9999989999999999 2.999999 2.9999999000000002 2.9999999 2.9999999900000001 2.99999999 2.9999999989999999 2.999999999 2.9999999999000000 2.9999999999 2.9999999999900000 2.99999999999 2.9999999999989999 2.999999999999 2.9999999999999001 2.9999999999999 2.9999999999999898 2.99999999999999 2.9999999999999991 3 3.0000000000000000 3

    If you want rounding behaviour rather than truncation, use an appropriate function or module.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-29 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found