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

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

by syphilis (Archbishop)
on Jan 06, 2017 at 03:37 UTC ( [id://1179055]=note: print w/replies, xml ) Need Help??


in reply to Re^3: 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

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

Replies are listed 'Best First'.
Re^5: Converting -4.84800000E+001 to -48.48 doesn't work... but 48.49 does (clever)
by tye (Sage) on Jan 07, 2017 at 19:06 UTC
    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        

      If you want the over-engineered version in glibc, then build your Perl with d_strtod=1

      Another way to get glibc to assign the value is to use POSIX::strtod.
      Unlike my perl-5.22.0, it correctly assigns '-4.848e1':
      C:\>perl -MPOSIX="strtod" -le "print scalar reverse unpack 'h*', pack +'d<',strtod('-4.848e1');" c0483d70a3d70a3d
      In my experience, glibc gets the assignment right for those values that perl gets wrong - though not so much with the non-IEEE "double-double" arrangement, where both are prone to error.
      However, I shouldn't assert that perl is any worse at assigning values than glibc. (I don't know how often glibc gets it wrong when perl gets it right.)

      Cheers,
      Rob

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-28 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found