-
-
Notifications
You must be signed in to change notification settings - Fork 753
Relax a few unittests for double-precision reals #5346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1706,12 +1706,14 @@ pure nothrow @safe unittest // issue 15884 | |
|
|
||
| @safe unittest // issue 15885 | ||
| { | ||
| enum bool realInDoublePrecision = real.mant_dig == double.mant_dig; | ||
|
|
||
| static bool test(const double num0) | ||
| { | ||
| import std.math : feqrel; | ||
| const json0 = JSONValue(num0); | ||
| const num1 = to!double(toJSON(json0)); | ||
| version(Win32) | ||
| static if (realInDoublePrecision) | ||
| return feqrel(num1, num0) >= (double.mant_dig - 1); | ||
| else | ||
| return num1 == num0; | ||
|
|
@@ -1725,8 +1727,11 @@ pure nothrow @safe unittest // issue 15884 | |
| assert(test(30738.22)); | ||
|
|
||
| assert(test(1 + double.epsilon)); | ||
| assert(test(-double.max)); | ||
| assert(test(double.min_normal)); | ||
| static if (realInDoublePrecision) | ||
| assert(test(-double.max / 2)); | ||
| else | ||
| assert(test(-double.max)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the result of this test when it fails? What consequences could the failure have for the API user?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answering my own question (from Relax std.json unittest some more): " I guess that's not too bad; at least it doesn't just silently corrupt data.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may have been a more severe issue (it's been a while since I relaxed them for LDC), I need to recheck. |
||
|
|
||
| const minSub = double.min_normal * double.epsilon; | ||
| assert(test(minSub)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By doing this you may be relaxing the test on platforms where it currently works, inviting regressions.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a list online somewhere of which platforms have
is(double == real)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaik, we use it for the 32/64-bit MSVC targets (i.e., on Windows), PowerPC and 32-bit ARM and possibly others, although
realis still a distinct type (mangling).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I run these tests on Android/ARM, which is one of the platforms where
realis 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AArch64 has 128-bit quadruple reals. The PowerPC doubledouble is implemented in software AFAIK, that's why we use double-precision reals for PowerPC.