Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: float values and operators

by Zaxo (Archbishop)
on Aug 11, 2004 at 20:17 UTC ( #382083=note: print w/replies, xml ) Need Help??


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

$ perl -e'print 36.8 - (36.6 + 0.2)' -7.105427357601e-15

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^4: float values and operators
by hardburn (Abbot) on Aug 11, 2004 at 20:21 UTC

    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.

      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.

      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://382083]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2018-11-18 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (206 votes). Check out past polls.

    Notices?