Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust math.degrees to match CPython #1844

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__)
Loading