in reply to Re^4: [OT: JavaScript] JS remainder operation ('%') (print's float rounding)
in thread [OT: JavaScript] JS remainder operation ('%')

> When using print perl will "smoothen" the last digits of a floating point

> Dunno if it's documented.

Can't find it, shouldn't it be mentioned in print ?

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

  • Comment on Re^5: [OT: JavaScript] JS remainder operation ('%') (print's float rounding)

Replies are listed 'Best First'.
Re^6: [OT: JavaScript] JS remainder operation ('%') (print's float rounding)
by syphilis (Archbishop) on Jan 18, 2024 at 13:59 UTC
    Can't find it, shouldn't it be mentioned in print ?

    Sounds like the logical spot for it. (Maybe we're still trying to come up with a justification ;-)

    I recall reading (somewhere) that 15 digits was chosen because that's the value of float.h's DBL_DIG - and DBL_DIG is described as "DBL_DIG specifies the number of digits of precision of a double".
    So you can see that someone could easily get sucked into thinking that 15 digits was the smart thing to do.

    If you go beyond 15 digits, then you hit the case that 2 different 16-digit numbers can have the same value:
    >perl -le "print 'ok' if 9.999999999999999 == 9.999999999999998;" ok
    That's 2 different 16 digit numbers with the same value. Therefore the "number of digits of precision of a double" must be less than 16.
    But you won't get 2 different 15-digit numbers with the same value.

    Cheers,
    Rob