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.