Relax a few unittests for double-precision reals#5346
Conversation
|
The issues were encountered with LDC for MSVC and ARM targets (double-precision reals). |
|
LGTM. But I'll defer to someone with stronger grasp of floating-point semantics. |
|
Related: #4345 The round trip should be lossless; if it's not, why not fix it instead of relaxing the tests? Probably one or both of the conversion routines just isn't using enough decimal digits: People generally assume that |
| const json0 = JSONValue(num0); | ||
| const num1 = to!double(toJSON(json0)); | ||
| version(Win32) | ||
| static if (realInDoublePrecision) |
There was a problem hiding this comment.
By doing this you may be relaxing the test on platforms where it currently works, inviting regressions.
There was a problem hiding this comment.
Since when does DMD cover 64-bit reals? Most new Phobos releases come with a few new tests that fail exactly because they're not tested with 64-bit reals, so I keep on upstreaming relaxed unittests for LDC which actually supports and tests targets with double-precision reals.
If you consider the potential being-off-by-1-ulp as bug (for std.format and/or std.json?), the Win32 exception shouldn't have been here already in the first place. I'm just extending that exception to its true scope here.
There was a problem hiding this comment.
Is there a list online somewhere of which platforms have is(double == real)?
There was a problem hiding this comment.
Afaik, we use it for the 32/64-bit MSVC targets (i.e., on Windows), PowerPC and 32-bit ARM and possibly others, although real is still a distinct type (mangling).
There was a problem hiding this comment.
I run these tests on Android/ARM, which is one of the platforms where real is 64-bit, and can confirm that this one only fails because of variability in the last digit, and that this relaxation patch gets it to pass again.
There was a problem hiding this comment.
Is there a list online somewhere of which platforms have is(double == real)?
It would be easier to list those that don't. x86 (80-bit) and PPC (64-bit pair) for sure, I think IA64 (128-bit) is in that list too. Everyone else is a platform where real == double.
There was a problem hiding this comment.
AArch64 has 128-bit quadruple reals. The PowerPC doubledouble is implemented in software AFAIK, that's why we use double-precision reals for PowerPC.
| static if (realInDoublePrecision) | ||
| assert(test(-double.max / 2)); | ||
| else | ||
| assert(test(-double.max)); |
There was a problem hiding this comment.
What is the result of this test when it fails? What consequences could the failure have for the API user?
There was a problem hiding this comment.
Answering my own question (from Relax std.json unittest some more): "test(-double.max) results in an overflow and thrown exception in std.conv.parse!(double, string)."
I guess that's not too bad; at least it doesn't just silently corrupt data.
There was a problem hiding this comment.
This may have been a more severe issue (it's been a while since I relaxed them for LDC), I need to recheck.
Edit: Thanks for checking, didn't see your 2nd post before.
|
The failure of Please give me a chance to fix the root cause rather than weakening the |
;) Sure, thanks! |
|
Unfortunately, fixing
Given the above, I recommend that we go ahead and merge this as-is. (Sorry for the delay.) |
|
ping, looks like this is ready to go. |
|
@kinke Can you please rebase onto master so that github picks up the fact that jenkins is no longer required for a merge? |
A loss-less roundtrip (to string <=> parse) apparently isn't guaranteed when using double-precision reals.
A loss-less roundtrip (to string <=> parse) apparently isn't guaranteed when using double-precision reals.