Decimal string to floating point conversion with correct half-to-even rounding

9il ilyayaroshenko at gmail.com
Sun Jun 21 15:24:14 UTC 2020


Hey everyone,

So excited to finally announce we can correctly parse 
floating-point numbers according to IEEE round half-to-even 
(bankers) rule like in C/C++, Rust, and others.

@nogc, optionally nothrow API is provided as part of Mir 
Algorithm v3.9.0 [0].
The documentation is available [1].

In case you are surprised, you can be sure that neither D 
compilers can correctly parse decimal FP literals [2, 3, 4], nor 
Phobos can correctly parse decimal FP strings [6].

Mir decimal parsing supports up-to quadruple precision.

The conversion error is 0 ULP for normal numbers.

Subnormal numbers with a decimal exponent greater than or equal 
to -512 have upper error bound equal to 1 ULP. Zero error 
bound for subnormal numbers can be supported in the future when 
Mir Ion, the ASDF successor, is ready.

The implementation is based on the paper [7].

The error bounds above are valid for LDC. DMD may have slightly 
larger errors because of the wrong code generation for ulong to 
double conversion [5].

This work has been sponsored by Symmetry Investments and Kaleidic 
Associates.

Best regards,
Ilya

[0] https://github.com/libmir/mir-algorithm
[1] http://mir-algorithm.libmir.org/mir_parse.html#.fromString[2] 
https://issues.dlang.org/show_bug.cgi?id=20951
[3] https://issues.dlang.org/show_bug.cgi?id=20952
[4] https://issues.dlang.org/show_bug.cgi?id=20953
[5] https://issues.dlang.org/show_bug.cgi?id=20963
[6] https://issues.dlang.org/show_bug.cgi?id=20967
[7] https://www.researchgate.net/publication/2295884_How_to_Read_Floating_Point_Numbers_Accurately


More information about the Digitalmars-d-announce mailing list