8000 address review · python/cpython@afb0a91 · GitHub
[go: up one dir, main page]

Skip to content

Commit afb0a91

Browse files
committed
address review
< 8000 /div>
1 parent a82d298 commit afb0a91

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

Doc/library/math.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ Floating point arithmetic
253253

254254
Get the larger of two floating-point values, treating NaNs as missing data.
255255

256-
If *x* and *y* are NaNs of same sign *s*, return ``copysign(nan, s)``.
257-
If *x* and *y* are NaNs of different sign, return ``copysign(nan, 1)``.
256+
When both operands are NaNs, return ``nan`` (the sign of the result is
257+
implementation-defined).
258258

259259
.. versionadded:: next
260260

@@ -263,8 +263,8 @@ Floating point arithmetic
263263

264264
Get the smaller of two floating-point values, treating NaNs as missing data.
265265

266-
If *x* and *y* are NaNs of same sign *s*, return ``copysign(nan, s)``.
267-
If *x* and *y* are NaNs of different sign, return ``copysign(nan, -1)``.
266+
When both operands are NaNs, return ``nan`` (the sign of the result is
267+
implementation-defined).
268 10000 268

269269
.. versionadded:: next
270270

Lib/test/test_math.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
test_file = os.path.join(test_dir, 'mathdata', 'cmath_testcases.txt')
3939

4040

41-
def is_signed_nan(x, x0):
42-
"""Check if x is a NaN with the same sign as x0."""
43-
return math.isnan(x) and math.copysign(1, x) == math.copysign(1, x0)
44-
45-
4641
def to_ulps(x):
4742
"""Convert a non-NaN float x to an integer, in such a way that
4843
adjacent floats are converted to adjacent integers. Then
@@ -670,12 +665,11 @@ def test_fmax_nans(self):
670665
self.assertFalse(math.isnan(math.fmax(x, NAN)))
671666
self.assertFalse(math.isnan(math.fmax(NNAN, x)))
672667
self.assertFalse(math.isnan(math.fmax(x, NNAN)))
673-
# When operands are NaNs with identical sign, return this signed NaN.
674-
self.assertTrue(is_signed_nan(math.fmax(NAN, NAN), 1))
675-
self.assertTrue(is_signed_nan(math.fmax(NNAN, NNAN), -1))
676-
# When operands are NaNs of different signs, return the positive NaN.
677-
self.assertTrue(is_signed_nan(math.fmax(NAN, NNAN), 1))
678-
self.assertTrue(is_signed_nan(math.fmax(NNAN, NAN), 1))
668+
# When both operands are NaNs, fmax() returns NaN (see C11, F.10.9.2).
669+
self.assertTrue(math.isnan(math.fmax(NAN, NAN)))
670+
self.assertTrue(math.isnan(math.fmax(NNAN, NNAN)))
671+
self.assertTrue(math.isnan(math.fmax(NAN, NNAN)))
672+
self.assertTrue(math.isnan(math.fmax(NNAN, NAN)))
679673

680674
def test_fmin(self):
681675
self.assertRaises(TypeError, math.fmin)
@@ -718,12 +712,11 @@ def test_fmin_nans(self):
718712
self.assertFalse(math.isnan(math.fmin(x, NAN)))
719713
self.assertFalse(math.isnan(math.fmin(NNAN, x)))
720714
self.assertFalse(math.isnan(math.fmin(x, NNAN)))
721-
# When operands are NaNs with identical sign, return this signed NaN.
722-
self.assertTrue(is_signed_nan(math.fmin(NAN, NAN), 1))
723-
self.assertTrue(is_signed_nan(math.fmin(NNAN, NNAN), -1))
724-
# When operands are NaNs of different signs, return the negative NaN.
725-
self.assertTrue(is_signed_nan(math.fmin(NAN, NNAN), -1))
726-
self.assertTrue(is_signed_nan(math.fmin(NNAN, NAN), -1))
715+
# When both operands are NaNs, fmax() returns NaN (see C11, F.10.9.2).
716+
self.assertTrue(math.isnan(math.fmin(NAN, NAN)))
717+
self.assertTrue(math.isnan(math.fmin(NNAN, NNAN)))
718+
self.assertTrue(math.isnan(math.fmin(NAN, NNAN)))
719+
self.assertTrue(math.isnan(math.fmin(NNAN, NAN)))
727720

728721
def testFrexp(self):
729722
self.assertRaises(TypeError, math.frexp)

Modules/mathmodule.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,17 +1222,12 @@ math.fmax -> double
12221222
/
12231223
12241224
Returns the larger of two floating-point arguments.
1225-
12261225
[clinic start generated code]*/
12271226

12281227
static double
12291228
math_fmax_impl(PyObject *module, double x, double y)
1230-
/*[clinic end generated code: output=00692358d312fee2 input=0dcf618bb27f98c7]*/
1229+
/*[clinic end generated code: output=00692358d312fee2 input=e64ab9f40a60f4f1]*/
12311230
{
1232-
if (isnan(x) && isnan(y)) {
1233-
double s = copysign(1, x);
1234-
return s == copysign(1, y) ? copysign(NAN, s) : NAN;
1235-
}
12361231
return fmax(x, y);
12371232
}
12381233

@@ -1250,11 +1245,6 @@ static double
12501245
math_fmin_impl(PyObject *module, double x, double y)
12511246
/*[clinic end generated code: output=3d5b7826bd292dd9 input=f7b5c91de01d766f]*/
12521247
{
1253-
if (isnan(x) && isnan(y)) {
1254-
double s = copysign(1, x);
1255-
// return ±NAN if both are ±NAN and -NAN otherwise.
1256-
return copysign(NAN, s == copysign(1, y) ? s : -1);
1257-
}
12581248
return fmin(x, y);
12591249
}
12601250

0 commit comments

Comments
 (0)
0