Thread overview
[Issue 15885] float serialized to JSON loses precision
Apr 06, 2016
Rory
May 21, 2016
b2.temp@gmx.com
Mar 21, 2020
Basile-z
April 06, 2016
https://issues.dlang.org/show_bug.cgi?id=15885

--- Comment #1 from Rory <rjmcguire@gmail.com> ---
Created attachment 1594
  --> https://issues.dlang.org/attachment.cgi?id=1594&action=edit
possible patch

this patch just makes sure we always output using %f. I'm guessing %g technically has the bug because surely it shouldn't just remove part of the number _by default_

--
May 21, 2016
https://issues.dlang.org/show_bug.cgi?id=15885

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |b2.temp@gmx.com
           Assignee|nobody@puremagic.com        |b2.temp@gmx.com

--- Comment #2 from b2.temp@gmx.com ---
(In reply to Rory from comment #1)
> Created attachment 1594 [details]
> possible patch
> 
> this patch just makes sure we always output using %f. I'm guessing %g technically has the bug because surely it shouldn't just remove part of the number _by default_

%f doesn't work. It breaks some unittest.

the correct format specifier would be "%.9g" (9 comes from the constant
FLT_DECIMAL_DIG).

see https://github.com/dlang/phobos/pull/4343

--
May 22, 2016
https://issues.dlang.org/show_bug.cgi?id=15885

thomas.bockman@gmail.com changed:

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

--- Comment #3 from thomas.bockman@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

--
June 01, 2016
https://issues.dlang.org/show_bug.cgi?id=15885

--- Comment #4 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/7a486d9d038448595c74aa4ef4bd7d9e952a4b64 Fix issue 15885 - numeric values serialized to JSON lose precision.

https://github.com/dlang/phobos/commit/f4ad734aad6e3b2dd4881508d2b15eebb732a26c Merge pull request #4345 from tsbockman/issue-15885-tsb

Fix issue 15885 - float serialized to JSON loses precision

--
June 01, 2016
https://issues.dlang.org/show_bug.cgi?id=15885

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--
October 01, 2016
https://issues.dlang.org/show_bug.cgi?id=15885

--- Comment #5 from github-bugzilla@puremagic.com ---
Commits pushed to stable at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/7a486d9d038448595c74aa4ef4bd7d9e952a4b64 Fix issue 15885 - numeric values serialized to JSON lose precision.

https://github.com/dlang/phobos/commit/f4ad734aad6e3b2dd4881508d2b15eebb732a26c Merge pull request #4345 from tsbockman/issue-15885-tsb

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=15885

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--