Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does

by syphilis (Archbishop)
on Jan 05, 2017 at 22:44 UTC ( [id://1179041]=note: print w/replies, xml ) Need Help??


in reply to Re: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does
in thread Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does

The problem also seems related to Perl version, but I can't say why

It's a known bug.
For your particular example (on Win32, perl-5.22.0):
C:>perl -le "print scalar reverse unpack 'h*', pack 'd<', -48.48;" c0483d70a3d70a3d C:>perl -le "print scalar reverse unpack 'h*', pack 'd<', -4.848e1;" c0483d70a3d70a3e
-48.48 is being assigned correctly, but -4.848e1 is off by one ulp.

These errors are not uncommon and can change between perl versions.

Cheers,
Rob
  • Comment on Re^2: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does
  • Download Code

Replies are listed 'Best First'.
Re^3: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does
by Anonymous Monk on Jan 06, 2017 at 00:39 UTC
    These errors are not uncommon and can change between perl versions.
    And C libraries and compilers and even seemingly-unrelated compiler settings.
      And C libraries and compilers and even seemingly-unrelated compiler settings.

      I strike these errors more in perl than in anything else. (But then, I only ever use perl and C ;-)
      If you know of any such error with the mpfr C library, please report it to the mpfr at loria.fr list.

      I think Jarkko Hietaniemi plans to replace perl's current (homegrown) implementation with netlib's gdtoa ... if he manages to find the tuits.
      It would therefore be a good idea to report any problems with gdtoa to p5p.

      Cheers,
      Rob
        I strike these errors more in perl than in anything else. (But then, I only ever use perl and C ;-)

        Reading the linked bug throws your comment in a bit of a different light:

        As to how glibc gets it "right". I pulled apart the glibc and indeed some "clever" person actually tried to take the advice in C99 literally; strtod uses GMP internally to try to get this right. Yes, GMP.

        But it still gets it wrong:

        [....]

        So they just made a string to number conversion not only use MP math and so be very slow, but they didn't even get the "perfect" behaviour they were seeking. "Excessive cleverness"

        Practically speaking, Perl's implementation is about as good as you could expect from a high performance solution and as far as I can tell confirms to ieee754 rules. If you want the over-engineered version in glibc, then build your Perl with d_strtod=1

        - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-04-26 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found