-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[APFloat] Correct semantics of minimum/maximum for signaling NaN arguments #109976
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
Merged
asb
merged 3 commits into
llvm:main
from
asb:2024q3-apfloat-minimum-maximum-snan-behaviour
Oct 1, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -607,13 +607,18 @@ TEST(APFloatTest, Minimum) { | |
| APFloat zp(0.0); | ||
| APFloat zn(-0.0); | ||
| APFloat nan = APFloat::getNaN(APFloat::IEEEdouble()); | ||
| APFloat snan = APFloat::getSNaN(APFloat::IEEEdouble()); | ||
|
|
||
| EXPECT_EQ(1.0, minimum(f1, f2).convertToDouble()); | ||
| EXPECT_EQ(1.0, minimum(f2, f1).convertToDouble()); | ||
| EXPECT_EQ(-0.0, minimum(zp, zn).convertToDouble()); | ||
| EXPECT_EQ(-0.0, minimum(zn, zp).convertToDouble()); | ||
| EXPECT_TRUE(std::isnan(minimum(f1, nan).convertToDouble())); | ||
| EXPECT_TRUE(std::isnan(minimum(nan, f1).convertToDouble())); | ||
| EXPECT_TRUE(maximum(snan, f1).isNaN()); | ||
| EXPECT_TRUE(maximum(f1, snan).isNaN()); | ||
| EXPECT_FALSE(maximum(snan, f1).isSignaling()); | ||
| EXPECT_FALSE(maximum(f1, snan).isSignaling()); | ||
| } | ||
|
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. Also test with snan in both positions |
||
|
|
||
| TEST(APFloatTest, Maximum) { | ||
|
|
@@ -622,13 +627,18 @@ TEST(APFloatTest, Maximum) { | |
| APFloat zp(0.0); | ||
| APFloat zn(-0.0); | ||
| APFloat nan = APFloat::getNaN(APFloat::IEEEdouble()); | ||
| APFloat snan = APFloat::getSNaN(APFloat::IEEEdouble()); | ||
|
|
||
| EXPECT_EQ(2.0, maximum(f1, f2).convertToDouble()); | ||
| EXPECT_EQ(2.0, maximum(f2, f1).convertToDouble()); | ||
| EXPECT_EQ(0.0, maximum(zp, zn).convertToDouble()); | ||
| EXPECT_EQ(0.0, maximum(zn, zp).convertToDouble()); | ||
| EXPECT_TRUE(std::isnan(maximum(f1, nan).convertToDouble())); | ||
| EXPECT_TRUE(std::isnan(maximum(nan, f1).convertToDouble())); | ||
| EXPECT_TRUE(maximum(snan, f1).isNaN()); | ||
| EXPECT_TRUE(maximum(f1, snan).isNaN()); | ||
| EXPECT_FALSE(maximum(snan, f1).isSignaling()); | ||
| EXPECT_FALSE(maximum(f1, snan).isSignaling()); | ||
| } | ||
|
|
||
| TEST(APFloatTest, MinimumNumber) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe could use a test that the payload and signbit are preserved, but it's not important
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'm not sure to what degree I should try to closely match the current APFloat implementation vs what the IEEE spec requires. To my cursory reading it looks like it only specifies "a" quiet NaN - but perhaps there's more detail on preserving payload and signbit for NaN operands elsewhere?
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 is not required, but suggested you should try to preserve the payload of one of the input operands for nan producing operations