Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: float values and operators

by hardburn (Abbot)
on Aug 11, 2004 at 20:21 UTC ( [id://382086]=note: print w/replies, xml ) Need Help??


in reply to Re^3: float values and operators
in thread float values and operators

Hrm, that's what I get, too. So why doesn't the imprecision show up when you print the variables out?

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^5: float values and operators
by dave_the_m (Monsignor) on Aug 11, 2004 at 21:11 UTC
    Hrm, that's what I get, too. So why doesn't the imprecision show up when you print the variables out?
    Because print doesn't print the full precision of its args. That's what printf is for:
    $ perl585 -e'print 26.6+0.2, "\n"' 26.8 $ perl585 -e'printf "%.20f\n ", 26.6+0.2' 26.80000000000000071054

    Dave.

Re^5: float values and operators
by ysth (Canon) on Aug 11, 2004 at 21:56 UTC
    Because the default is prudently to print using DBL_DIG or LDBL_DIG digits which should be one less than the number of digits necessary to distinguish any possible value. If you feel exceptionally daring, you can override this by configuring perl with something like -Accflags=-DOVR_DBL_DIG=16 or -Accflags=-DOVR_LDBL_DIG=19. I wouldn't recommend it, though.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found