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

> The problem is that perl takes the correct 17-significant-digit representation and rounds it to a 15-bit-significant-digit number. Therefore, whenever 16 or 17 significant digits are required for correctness, perl fails to deliver.

Wouldn't it be better to s/perl/print/g here?

I agree that print is kind of "lying", and I would love to see this unexpected behavior at least clearly documented in the perldocs.

IMHO your statement is misleading as it is, because it's limited to output by print and doesn't effect internal representation.

Edit

Since print only affects the output one might consider adding something like print_truely feature, for future versions.

Best with accompanying flags in printf for compatibility.

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

Replies are listed 'Best First'.
Re^6: [OT: JavaScript] JS remainder operation ('%')
by syphilis (Archbishop) on Jan 18, 2024 at 14:23 UTC
    Wouldn't it be better to s/perl/print/g here?

    That would be better. (Some might even argue that "perl's interpolation" would be the more strictly accurate replacement - since all print() does is to output what perl has interpolated ... but that sort of thinking is way too moot for me to understand ;-)

    IMHO your statement is misleading as it is, because it's limited to output by print and doesn't effect internal representation.

    I don't quite follow that. The only problem is the print function (or perl's interpolation of NV's or whatever we should call it).
    There's no issue with perl's internal representation of doubles, since 5.30.0.

    Cheers,
    Rob
      > Some might even argue that "perl's interpolation

      That's a very good point!

      But it's not the interpolation, but more generally the stringification .

      use v5.12; use warnings; $a= 1-1e-16; printf "%.16f\n",$a; printf "%.16f\n",("".$a);

      0.9999999999999999 1.0000000000000000

      Consequently this should be documented for stringification, and print should reference it.

      Update

      Apart from mentions in perlglossary and overload there is not much on stringification to be found in perldocs :/

      https://perldoc.perl.org/perlglossary#stringification

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