Skip to content

Commit aec2b0b

Browse files
committed
[GR-10582] Math angular conversion functions are not implemented.
1 parent 0d2c5e3 commit aec2b0b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_math.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,3 +1169,27 @@ class TestNoTrunc(object):
11691169
self.assertRaises(TypeError, math.trunc, 1, 2)
11701170
self.assertRaises(TypeError, math.trunc, TestNoTrunc())
11711171

1172+
def testDegrees(self):
1173+
self.assertRaises(TypeError, math.degrees)
1174+
self.ftest('degrees(pi)', math.degrees(math.pi), 180.0)
1175+
self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0)
1176+
self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)
1177+
self.ftest('degrees(0)', math.degrees(0), 0)
1178+
1179+
# test of specializations
1180+
self.ftest('degrees(MyFloat())', math.degrees(MyFloat()), 34.37746770784939)
1181+
self.assertRaises(TypeError, math.degrees, 'ahoj')
1182+
self.ftest('degrees(BIG_INT)', math.degrees(BIG_INT), 5.729573615680451e+32)
1183+
1184+
def testRadians(self):
1185+
self.assertRaises(TypeError, math.radians)
1186+
self.ftest('radians(180)', math.radians(180), math.pi)
1187+
self.ftest('radians(90)', math.radians(90), math.pi/2)
1188+
self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
1189+
self.ftest('radians(0)', math.radians(0), 0)
1190+
1191+
# test of specializations
1192+
self.ftest('radians(MyFloat())', math.radians(MyFloat()), 0.010471975511965976)
1193+
self.assertRaises(TypeError, math.radians, 'ahoj')
1194+
self.ftest('radians(BIG_INT)', math.radians(BIG_INT), 1.7453279312865818e+29)
1195+

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,4 +1689,28 @@ public abstract static class Atan2Node extends PythonBinaryBuiltinNode {
16891689
return atan2DD(convertLeftFloat.execute(left), convertRightFloat.execute(right));
16901690
}
16911691
}
1692+
1693+
@Builtin(name = "degrees", fixedNumOfArguments = 1)
1694+
@GenerateNodeFactory
1695+
public abstract static class DegreesNode extends MathDoubleUnaryBuiltinNode {
1696+
private static final double RAD_TO_DEG = 180.0 / Math.PI;
1697+
1698+
@Override
1699+
@TruffleBoundary
1700+
public double count(double value) {
1701+
return value * RAD_TO_DEG;
1702+
}
1703+
}
1704+
1705+
@Builtin(name = "radians", fixedNumOfArguments = 1)
1706+
@GenerateNodeFactory
1707+
public abstract static class RadiansNode extends MathDoubleUnaryBuiltinNode {
1708+
private static final double DEG_TO_RAD = Math.PI / 180.0;
1709+
1710+
@Override
1711+
@TruffleBoundary
1712+
public double count(double value) {
1713+
return value * DEG_TO_RAD;
1714+
}
1715+
}
16921716
}

0 commit comments

Comments
 (0)