Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^5: [OT: JavaScript] JS remainder operation ('%')

by LanX (Saint)
on Jan 18, 2024 at 13:46 UTC ( [id://11157079]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11157079]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-06-16 19:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.