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

Re^4: float values and operators

by hardburn (Abbot)
on Aug 11, 2004 at 20:21 UTC ( #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 (Prior) 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
Node Status?
node history
Node Type: note [id://382086]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-07-21 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (442 votes). Check out past polls.

    Notices?