Skip to content

Commit

Permalink
Adjust math.degrees to match CPython (#1844)
Browse files Browse the repository at this point in the history
  • Loading branch information
slozier authored Dec 18, 2024
1 parent 389a844 commit 93c945b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Src/IronPython.Modules/math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public static partial class PythonMath {
public const double e = Math.E;

private const double degreesToRadians = Math.PI / 180.0;
private const double radiansToDegrees = 180.0 / Math.PI;

private const int Bias = 0x3FE;

public static double degrees(double radians) {
return Check(radians, radians / degreesToRadians);
return Check(radians, radians * radiansToDegrees);
}

public static double radians(double degrees) {
Expand Down
6 changes: 6 additions & 0 deletions Tests/modules/misc/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,10 @@ def test_integer_ratio(self):
for flt, res in int_ratio_tests:
self.assertEqual(flt.as_integer_ratio(), res)

def test_degrees(self):
# check that IronPython is doing the same conversion as CPython
self.assertNotEqual(0.06825994771674652 / (math.pi / 180), 0.06825994771674652 * (180 / math.pi))
self.assertEqual(0.06825994771674652 * (180 / math.pi), 3.911006913953236)
self.assertEqual(math.degrees(0.06825994771674652), 3.911006913953236)

run_test(__name__)

0 comments on commit 93c945b

Please sign in to comment.