-
Notifications
You must be signed in to change notification settings - Fork 5.8k
JDK-8302028: Port fdlibm atan2 to Java #12608
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
Conversation
👋 Welcome back darcy! A progress list of the required criteria for merging this PR into |
Diffs of the various ports, starting with the original C vs the transliteration port:
And the transliteration vs the more idiomatic port:
A few notes: I decided to use expression switches, but that is not necessary. Also, in the final switch I used "-z" as a more direct idiom to negate z than the form in the original fdlibm. |
Webrevs
|
The port looks reasonable to me. |
hy = __HI(y); iy = hy&0x7fffffff; | ||
ly = __LO(y); | ||
if(((ix|((lx|-lx)>>31))>0x7ff00000)|| | ||
((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */ |
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 think that >>31
must be replaced by >>>31
.
iy = hy&0x7fff_ffff; | ||
ly = __LO(y); | ||
if (((ix | ((lx | -lx) >> 31)) > 0x7ff0_0000)|| | ||
((iy |((ly | - ly) >> 31)) > 0x7ff0_0000)) // x or y is NaN |
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 think that >> 31
must be replaced by >>> 31
.
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.
Well spotted; corrected the code and added additional tests to catch that case. Thanks.
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.
Well spotted; corrected the code and added additional tests to catch that case. Thanks.
PS From some quick manual inspections, the other recent ports of FDLIBM methods don't look vulnerable to this kind of problem. However, as follow-up work later in 21 I'll implement: JDK-8302800: Augment NaN handling tests of FDLIBM methods.
return switch(m) { | ||
case 0, 1 -> y; // atan(+/-0, +anything) = +/-0 | ||
case 2 -> Math.PI + tiny; // atan(+0, -anything) = pi | ||
default -> -Math.PI - tiny; // atan(-0, -anything) = -pi |
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.
The original switch statement and this switch expression are semantically equivalent only because of our knowledge that m
can only assume values 0, 1, 2, or 3. This requires more reasoning than a more verbatim copy of the original statement. Not sure if it is worth.
The same holds for the switch expressions below.
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.
Yes, the use of switch expressions here is certainly not strictly necessary.
Something that helped convince me it was okay was that the final switch on m in atan2 uses the set of case labels {0, 1, 2, default}., further implying that m can only take on the values {0, 1, 2, 3}.
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.
Reverted to switch statements rather than switch expressions.
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.
Looks good.
@jddarcy This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 33 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
1 similar comment
/integrate |
Going to push as commit fcaf871.
Your commit was automatically rebased without conflicts. |
@jddarcy The command |
Working down the porting list, next stop, atan2.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/12608/head:pull/12608
$ git checkout pull/12608
Update a local copy of the PR:
$ git checkout pull/12608
$ git pull https://git.openjdk.org/jdk pull/12608/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 12608
View PR using the GUI difftool:
$ git pr show -t 12608
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12608.diff