From 091d590d73cefebfff0fca9ccfa0f189d19663e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Wed, 18 Dec 2024 09:55:33 -0500 Subject: [PATCH] Adjust math.degrees to match CPython --- Src/IronPython.Modules/math.cs | 4 +++- Tests/modules/misc/test_math.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Src/IronPython.Modules/math.cs b/Src/IronPython.Modules/math.cs index a7f3910a5..f104210b2 100644 --- a/Src/IronPython.Modules/math.cs +++ b/Src/IronPython.Modules/math.cs @@ -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) { diff --git a/Tests/modules/misc/test_math.py b/Tests/modules/misc/test_math.py index 1eb791932..718abb1e1 100644 --- a/Tests/modules/misc/test_math.py +++ b/Tests/modules/misc/test_math.py @@ -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__)