[Issue 15885] float serialized to JSON loses precision

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat May 21 19:37:51 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15885

thomas.bockman at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thomas.bockman at gmail.com

--- Comment #3 from thomas.bockman at gmail.com ---
The correct format specifier is ACTUALLY "%.18g", assuming that you want full
lossless conversion. This is because:

1) JSON_TYPE.FLOAT is a 64-bit double, not 32-bit float!

2) cast(int)ceil(log(pow(2.0L, F.mant_dig - 1)) / log(10.0L) + 1) decimal
digits are needed to represent some floating-point values, such as (1 +
F.epsilon).

See this DPaste: https://dpaste.dzfl.pl/1bd14e5c3f83#line-25

--


More information about the Digitalmars-d-bugs mailing list