Skip to content

Commit 93c945b

Browse files
authored
Adjust math.degrees to match CPython (#1844)
1 parent 389a844 commit 93c945b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Src/IronPython.Modules/math.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public static partial class PythonMath {
3030
public const double e = Math.E;
3131

3232
private const double degreesToRadians = Math.PI / 180.0;
33+
private const double radiansToDegrees = 180.0 / Math.PI;
34+
3335
private const int Bias = 0x3FE;
3436

3537
public static double degrees(double radians) {
36-
return Check(radians, radians / degreesToRadians);
38+
return Check(radians, radians * radiansToDegrees);
3739
}
3840

3941
public static double radians(double degrees) {

Tests/modules/misc/test_math.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,4 +718,10 @@ def test_integer_ratio(self):
718718
for flt, res in int_ratio_tests:
719719
self.assertEqual(flt.as_integer_ratio(), res)
720720

721+
def test_degrees(self):
722+
# check that IronPython is doing the same conversion as CPython
723+
self.assertNotEqual(0.06825994771674652 / (math.pi / 180), 0.06825994771674652 * (180 / math.pi))
724+
self.assertEqual(0.06825994771674652 * (180 / math.pi), 3.911006913953236)
725+
self.assertEqual(math.degrees(0.06825994771674652), 3.911006913953236)
726+
721727
run_test(__name__)

0 commit comments

Comments
 (0)