When compiling with -m64 on Windows, std.json fails to pass unittests regarding parsing doubles from string json format into the JSONValue type. Specifically: core.exception.AssertError@jsontest.d(1027): 1.44354e-312 should be 0.23 This does not happen when I leave off -m64. This does not happen when I use -m64 on OSX. I compile with the line: dmd -main -unittest -m64 json.d I downloaded the latest version of std.json to see if this had already been patched; it is still broken. The line number above refers to the version currently on Github. I will likely spend some time investigating this myself, as I must eventually have a solution to this problem.
When porting LDC to Windows, I had to deal with a large number of such issues that manifested in a similar way (absurd floating point results). The root cause always was that the MSVC runtime does not support reals ("long double" in C land, i.e. x87 80 bit floats) at all. This leads to situations where D code is calling a function (say snprintf) with some floating point arguments on the x87 stack, but the called function reads them from the XMM registers or the regular stack. If I remember correctly, DMD also uses 80 bit reals on Win64. This can't work unless it comes with its own string formatting/math/etc. routines. For LDC/MinGW, we just use the MinGW ones which do properly support long doubles, but I'm not sure what the intended solution for DMD is.
Thanks for the insight David! I added a: version (Win64) { alias FloatingType = double; } else { alias FloatingType = real; } to the top and changed the appropriate union type to use that alias. The unittests ran perfectly. I doubt that this is the fix we want to ship, but it seems that your analysis is spot-on.
JavaScript uses double exclusively why use 'real' in JSON to begin with?
Dimitry - Just had the same conversation with a co-worker :). Checked the blame log; was unable to quickly find the person who initially coded it up as real to find the rationale.
(In reply to Mark Isaacson from comment #4) > Dimitry - Just had the same conversation with a co-worker :). Checked the > blame log; was unable to quickly find the person who initially coded it up > as real to find the rationale. That stuff is old... I'd pull a patch that fixes it to double without a second thought. It still leaves the question of ABI violation as something separate. From the bug report I guess that not every test is run on Win64 ATM.
Pull request: https://github.com/D-Programming-Language/phobos/pull/2291
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/333e7e734f30067acbb935adfdf6d2ef64f50b8c Issue 13013 - Converted real to double in std.json.JSONValue https://github.com/D-Programming-Language/phobos/commit/f518343f3e85c7b0ae0a9d2486dd18390dd592d6 Merge pull request #2291 from markisaa/realToDouble Issue 13013 - Converted real to double in std.json.JSONValue
Commit pushed to 2.066 at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/4b98a776cbb4e42cd271c57d238621174d5fb0ff Merge pull request #2291 from markisaa/realToDouble Issue 13013 - Converted real to double in std.json.JSONValue
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/4b98a776cbb4e42cd271c57d238621174d5fb0ff Merge pull request #2291 from markisaa/realToDouble