Skip to content

Fix issue 15885 - float serialized to JSON loses precision#4345

Merged
andralex merged 1 commit intodlang:masterfrom
tsbockman:issue-15885-tsb
Jun 1, 2016
Merged

Fix issue 15885 - float serialized to JSON loses precision#4345
andralex merged 1 commit intodlang:masterfrom
tsbockman:issue-15885-tsb

Conversation

@tsbockman
Copy link
Contributor

This is a continuation of @bbasile 's PR #4343 .

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
15885 float serialized to JSON loses precision

std/json.d Outdated
import std.stdio;
writefln("%.18g : %.18g : %.18g : %s", num0, num1, num2, feqrel(num2, num0));

version(Windows)
Copy link

@ghost ghost May 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What 's happening on Windows ? If the failure is related to DigitalMars snn.lib then the version should be changed to CRuntime_DigitalMars because MS C standard lib might not have the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What 's happening on Windows ?

I don't know. Win_32 failed on win-farm-2at assert(test(1.223e+24)), so I added the debug printout and re-ran the test... which then passed on win-farm-1.

Originally I thought it was just imprecision in the Windows snprintf() - which is indirectly called by toJSON() - but now I'm wondering if it's actually a code gen bug, or maybe flaky hardware on one/both of the Windows test servers.

@tsbockman tsbockman force-pushed the issue-15885-tsb branch 3 times, most recently from e635222 to 4692b02 Compare May 22, 2016 13:46
@tsbockman
Copy link
Contributor Author

tsbockman commented May 22, 2016

@bbasile I think there is a code gen bug on Win_32:

core.exception.AssertError@std\json.d(1740):
    "1.22300000000000003e+24": 1.22300000000000003e+24 != 1.22300000000000003e+24

And from another run, printing the bit pattern instead:

core.exception.AssertError@std\json.d(1740):
    "1.22300000000000003e+24": 44F02FAF67D2C4A9 != 44F02FAF67D2C4A9

Reducing this could be a pain though, since I don't have a Win_32 development environment of my own right now.

@tsbockman tsbockman force-pushed the issue-15885-tsb branch 3 times, most recently from 12e5883 to 1d87b20 Compare May 22, 2016 20:59
@ghost
Copy link

ghost commented May 29, 2016

We have missed this: https://issues.dlang.org/show_bug.cgi?id=15861. The fix should be OK now !

@tsbockman tsbockman force-pushed the issue-15885-tsb branch 4 times, most recently from 426b117 to 503760c Compare May 30, 2016 01:04
@tsbockman
Copy link
Contributor Author

tsbockman commented May 30, 2016

@bbasile

The fix should be OK now !

You are correct. Excellent!

It's now 100% precise on all platforms except Win32, where the result is sometimes off by a single bit, which is acceptable for floating-point. (Or, at least a vast improvement over the current bugged behaviour.)

@tsbockman
Copy link
Contributor Author

Ping @klickverbot @CyberShadow . This important JSON bug fix passes the auto-tester now; does anyone want to merge it?

@andralex
Copy link
Member

andralex commented Jun 1, 2016

Auto-merge toggled on

@andralex andralex merged commit f4ad734 into dlang:master Jun 1, 2016
@tsbockman tsbockman deleted the issue-15885-tsb branch June 1, 2016 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants