-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-135853: add math.fmax
and math.fmin
#135888
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
base: main
Are you sure you want to change the base?
Conversation
math.fmax
and math.fmin
math.fmax
and math.fmin
[PoC]
0831229
to
afb0a91
Compare
math.fmax
and math.fmin
[PoC]math.fmax
and math.fmin
with self.subTest("math.fmax(INF, x)", x=x): | ||
self.assertEqual(math.fmax(INF, x), INF) | ||
with self.subTest("math.fmax(x, INF)", x=x): | ||
self.assertEqual(math.fmax(x, INF), INF) | ||
|
||
with self.subTest("math.fmax(NINF, x)", x=x): | ||
self.assertEqual(math.fmax(NINF, x), x) | ||
with self.subTest("math.fmax(x, NINF)", x=x): | ||
self.assertEqual(math.fmax(x, NINF), x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The traceback contains the line causing the assertion failure, I don't think that it's worth it to repeat it it subTest():
with self.subTest("math.fmax(INF, x)", x=x): | |
self.assertEqual(math.fmax(INF, x), INF) | |
with self.subTest("math.fmax(x, INF)", x=x): | |
self.assertEqual(math.fmax(x, INF), INF) | |
with self.subTest("math.fmax(NINF, x)", x=x): | |
self.assertEqual(math.fmax(NINF, x), x) | |
with self.subTest("math.fmax(x, NINF)", x=x): | |
self.assertEqual(math.fmax(x, NINF), x) | |
with self.subTest(x=x): | |
self.assertEqual(math.fmax(INF, x), INF) | |
self.assertEqual(math.fmax(x, INF), INF) | |
self.assertEqual(math.fmax(NINF, x), x) | |
self.assertEqual(math.fmax(x, NINF), x) |
with self.subTest("math.fmax(x, NINF)", x=x): | ||
self.assertEqual(math.fmax(x, NINF), x) | ||
|
||
@requires_IEEE_754 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python requires IEEE 754 and NaN support to build: https://docs.python.org/dev/using/configure.html#build-requirements We should maybe start getting rid of this decorator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other Python implementations may use this test suite as well.
with self.subTest("math.fmin(INF, x)", x=x): | ||
self.assertEqual(math.fmin(INF, x), x) | ||
with self.subTest("math.fmin(x, INF)", x=x): | ||
self.assertEqual(math.fmin(x, INF), x) | ||
|
||
with self.subTest("math.fmin(NINF, x)", x=x): | ||
self.assertEqual(math.fmin(NINF, x), NINF) | ||
with self.subTest("math.fmin(x, NINF)", x=x): | ||
self.assertEqual(math.fmin(x, NINF), NINF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with self.subTest("math.fmin(INF, x)", x=x): | |
self.assertEqual(math.fmin(INF, x), x) | |
with self.subTest("math.fmin(x, INF)", x=x): | |
self.assertEqual(math.fmin(x, INF), x) | |
with self.subTest("math.fmin(NINF, x)", x=x): | |
self.assertEqual(math.fmin(NINF, x), NINF) | |
with self.subTest("math.fmin(x, NINF)", x=x): | |
self.assertEqual(math.fmin(x, NINF), NINF) | |
with self.subTest(x=x): | |
self.assertEqual(math.fmin(INF, x), x) | |
self.assertEqual(math.fmin(x, INF), x) | |
self.assertEqual(math.fmin(NINF, x), NINF) | |
self.assertEqual(math.fmin(x, NINF), NINF) |
I've added
math.fmin
andmath.fmax
as I think it'd be nice to have the NaN handling as per C99. I didn't make those functions generic or accept any iterable argument.WDYT of this proposal @skirpichev @rhettinger?
math
#135853📚 Documentation preview 📚: https://cpython-previews--135888.org.readthedocs.build/