Skip to content
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

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review suggestions
  • Loading branch information
gordonbondon committed Nov 18, 2024
commit 4c72103a298c65f851ebc12a2f31cff62c74a46c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ protected double eval(VmTyped self, long x, long y) {
protected double eval(VmTyped self, long x, double y) {
return StrictMath.atan2(x, y);
}
holzensp marked this conversation as resolved.
Show resolved Hide resolved

@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);
}
}

public abstract static class gcd extends ExternalMethod2Node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ examples {

["atan2"] {
math.atan2(4, -3)
holzensp marked this conversation as resolved.
Show resolved Hide resolved
math.atan2(4.5, -3.5)
math.atan2(4.5, -3)
math.atan2(4, 3.5)
}

["gcd"] {
Expand Down Expand Up @@ -193,3 +196,10 @@ examples {
math.min(Infinity, -Infinity)
}
}

facts {
["atan2"] {
math.atan2(1, 0) == math.pi / 2
math.atan2(0, -1) == math.pi
}
}
3 changes: 2 additions & 1 deletion stdlib/math.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ external function acos(x: Number): Float
/// [1]: https://en.wikipedia.org/wiki/Inverse_trigonometric_functions
external function atan(x: Number): Float

/// Returns the [4-quadrant inverse tangent][1] of [x] and [y].
/// Returns the [2-argument arctangent][1] of [x] and [y].
///
/// [1]: https://en.wikipedia.org/wiki/Atan2
@Since { version = "0.28.0" }
external function atan2(x: Number, y: Number): Float

/// Returns the [greatest common divisor][1] of [x] and [y].
Expand Down