New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
netlib dtoa.c #14019
Comments
From @jhiAs discussed elsewhere [1] there is a well-known solution for ascii-to-double (aka strtod) and double-to-ascii (aka printf, or Gconvert) conversions: the netlib dtoa.c [2]. This code is apparently used by Python, PHP, Java, Firefox, Chrome, Safari I suggest looking into integrating this into Perl. I volunteer myself to doing some of the work. Pros: Cons: Unknowns/musings as of now: [1] https://rt-archive.perl.org/perl5/Ticket/Display.html?id=122219 ("support hexadecimal floats") |
From @jhiInitial investigation comments: - turning off the private memory management More importantly, looks like integrating this will be even more ... intense than expected: the Perl_my_atof and Perl_my_atof2 (and the helper, S_mulexp10) make for interesting reading, especially with the VAX (and Cray) specifics. |
From [Unknown Contact. See original ticket]Initial investigation comments: - turning off the private memory management More importantly, looks like integrating this will be even more ... intense than expected: the Perl_my_atof and Perl_my_atof2 (and the helper, S_mulexp10) make for interesting reading, especially with the VAX (and Cray) specifics. |
From @jhi
Actually, to be more explicit - looks like we are not actually currently even using strtod() as such! The whole area of code is a quilt of numeric overflow ballet, strange cases in various places. Summary: I'm starting to doubt the benefit of bringing in the netlib strtod, however well tested and widely used it is, the current code has been well tested in the platforms Perl runs on. And since we are not really depending on the system strtod:s anyway (except for nan/inf), it looks like for the hexadecimal fp "strtod-ing" it would be better just to implement our own. This would not, however, solve the hexadecimal fp output. |
From [Unknown Contact. See original ticket]
Actually, to be more explicit - looks like we are not actually currently even using strtod() as such! The whole area of code is a quilt of numeric overflow ballet, strange cases in various places. Summary: I'm starting to doubt the benefit of bringing in the netlib strtod, however well tested and widely used it is, the current code has been well tested in the platforms Perl runs on. And since we are not really depending on the system strtod:s anyway (except for nan/inf), it looks like for the hexadecimal fp "strtod-ing" it would be better just to implement our own. This would not, however, solve the hexadecimal fp output. |
From @jhiThen again, dtoa.c is not without is share of security problems, see e.g. https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2009-0689 I also got a pointer to another implementation: http://git.musl-libc.org/cgit/musl/tree/src/internal/floatscan.c Much more minimal (good), and does seemingly 80-bit long doubles (good), |
From [Unknown Contact. See original ticket]Then again, dtoa.c is not without is share of security problems, see e.g. https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2009-0689 I also got a pointer to another implementation: http://git.musl-libc.org/cgit/musl/tree/src/internal/floatscan.c Much more minimal (good), and does seemingly 80-bit long doubles (good), |
From @jhiAfter more inspection: it seems that the gdtoa.tgz (also from netlib) is the "portable" version that handles more platforms, including long doubles. |
From [Unknown Contact. See original ticket]After more inspection: it seems that the gdtoa.tgz (also from netlib) is the "portable" version that handles more platforms, including long doubles. |
From @jhiSome more commentary. Some users of the dtoa.c: * Python: https://hg.python.org/cpython/file/tip/Python/dtoa.c -- possibly relevant Python ticket: http://bugs.python.org/issue9009 I also tried test building gdtoa in OS X with clang, more than a year ago now, and found some nits fixed in the attached patch. I sent the patch to David Gay but haven't heard back from him, in a year or more. Note that is important to use the latest gdtoa (20131209), since the older ones have known issues, e.g. http://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/ (see end) or is tricky to compile (though Perl is saved from this, since we explicitly avoid strict aliasing, for our own good): http://patrakov.blogspot.com/2009/03/dont-use-old-dtoac.html And no, the official gdtoa is not in any kind of version control system. You get a date-stamped tar. Rick Regan's blog is required reading on these matters, see e.g. http://www.exploringbinary.com/inconsistent-rounding-of-printed-floating-point-numbers/ |
From @jhi
My apologies to Mr Gay, it hasn't been more than a year, just a few months. Dont' know where I pulled the one year from. |
From @jhiAdding link to https://rt-archive.perl.org/perl5/Ticket/Display.html?id=127182 since relevant discussion also there. |
From @jhigdtoa 20160219 update from Mr Gay: http://www.ampl.com/netlib/fp/gdtoa.tgz |
Migrated from rt.perl.org#122482 (status was 'new')
Searchable as RT122482$
The text was updated successfully, but these errors were encountered: