Add math.atan2 (#819)

This commit is contained in:
Artem Yarmoliuk
2024-11-18 22:11:19 +00:00
committed by GitHub
parent b93cb9b322
commit cc579f8fd6
4 changed files with 54 additions and 0 deletions

View File

@@ -299,6 +299,28 @@ public final class MathNodes {
}
}
public abstract static class atan2 extends ExternalMethod2Node {
@Specialization
protected double eval(VmTyped self, long x, long y) {
return StrictMath.atan2(x, y);
}
@Specialization
protected double eval(VmTyped self, long x, double y) {
return StrictMath.atan2(x, y);
}
@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 {
@TruffleBoundary
@Specialization

View File

@@ -130,6 +130,13 @@ examples {
math.atan(math.tan(-2.34))
}
["atan2"] {
math.atan2(4, -3)
math.atan2(4.5, -3.5)
math.atan2(4.5, -3)
math.atan2(4, 3.5)
}
["gcd"] {
math.gcd(0, 0)
math.gcd(4, 6)
@@ -189,3 +196,10 @@ examples {
math.min(Infinity, -Infinity)
}
}
facts {
["atan2"] {
math.atan2(1, 0) == math.pi / 2
math.atan2(0, -1) == math.pi
}
}

View File

@@ -1,3 +1,9 @@
facts {
["atan2"] {
true
true
}
}
examples {
["minInt"] {
-9223372036854775808
@@ -109,6 +115,12 @@ examples {
1.1415926535897931
0.8015926535897934
}
["atan2"] {
2.214297435588181
2.2318394956455836
2.1587989303424644
0.851966327173272
}
["gcd"] {
0
2