-
Notifications
You must be signed in to change notification settings - Fork 280
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
Add math.atan2
#819
base: main
Are you sure you want to change the base?
Add math.atan2
#819
Conversation
@Specialization | ||
protected double eval(VmTyped self, long x, double y) { | ||
return StrictMath.atan2(x, y); | ||
} |
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.
Need to handle all permutations of long
and double
here:
} | |
} | |
@Specialization | |
protected double eval(VmTyped self, double x, double y) { | |
return StrictMath.atan2(x, y); | |
} | |
@Specialization | |
protected double eval(VmTyped self, double x, long y) { | |
return StrictMath.atan2(x, y); | |
} |
@@ -130,6 +130,10 @@ examples { | |||
math.atan(math.tan(-2.34)) | |||
} | |||
|
|||
["atan2"] { | |||
math.atan2(4, -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.
Let's add some more examples that exercise all permutations.
math.atan2(4, -3) | |
math.atan2(4, -3) | |
math.atan2(4.5, -3.5) | |
math.atan2(4.5, -3) | |
math.atan2(4, 3.5) |
Also: maybe a test for correspondence with PI, in the facts
section:
facts {
["atan2"] {
math.atan2(1, 0) == math.pi / 2
math.atan2(0, -1) == math.pi
}
}
/// Returns the [4-quadrant inverse tangent][1] of [x] and [y]. | ||
/// | ||
/// [1]: https://en.wikipedia.org/wiki/Atan2 |
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 we're linking to Wikipedia, let's use verbiage that aligns with it.
Also, need a @Since
annotation.
/// Returns the [4-quadrant inverse tangent][1] of [x] and [y]. | |
/// | |
/// [1]: https://en.wikipedia.org/wiki/Atan2 | |
/// Returns the [2-argument arctangent][1] of [x] and [y]. | |
/// | |
/// [1]: https://en.wikipedia.org/wiki/Atan2 | |
@Since { version = "0.28.0" } |
It might also be helpful to have one more paragraph to describe this function's purpose. Maybe something like: "The result is 𝜃 (theta) when converting cartesian coordinates 𝑥 and 𝑦 to polar coordinates 𝑟 and 𝜃."
No description provided.