|
17 | 17 |
|
18 | 18 | eps = 1E-05 |
19 | 19 | NAN = float('nan') |
| 20 | +NNAN = float('-nan') |
20 | 21 | INF = float('inf') |
21 | 22 | NINF = float('-inf') |
22 | 23 | FLOAT_MAX = sys.float_info.max |
@@ -636,6 +637,92 @@ def testFmod(self): |
636 | 637 | self.assertEqual(math.fmod(0.0, NINF), 0.0) |
637 | 638 | self.assertRaises(ValueError, math.fmod, INF, INF) |
638 | 639 |
|
| 640 | + def test_fmax(self): |
| 641 | + self.assertRaises(TypeError, math.fmax) |
| 642 | + self.assertRaises(TypeError, math.fmax, 'x', 'y') |
| 643 | + |
| 644 | + self.assertEqual(math.fmax(0., 0.), 0.) |
| 645 | + self.assertEqual(math.fmax(1., 2.), 2.) |
| 646 | + self.assertEqual(math.fmax(2., 1.), 2.) |
| 647 | + |
| 648 | + self.assertEqual(math.fmax(+1., +0.), 1.) |
| 649 | + self.assertEqual(math.fmax(+0., +1.), 1.) |
| 650 | + self.assertEqual(math.fmax(+1., -0.), 1.) |
| 651 | + self.assertEqual(math.fmax(-0., +1.), 1.) |
| 652 | + |
| 653 | + self.assertEqual(math.fmax(-1., +0.), 0.) |
| 654 | + self.assertEqual(math.fmax(+0., -1.), 0.) |
| 655 | + self.assertEqual(math.fmax(-1., -0.), 0.) |
| 656 | + self.assertEqual(math.fmax(-0., -1.), 0.) |
| 657 | + |
| 658 | + for x in [NINF, -1., -0., 0., 1., INF]: |
| 659 | + self.assertFalse(math.isnan(x)) |
| 660 | + |
| 661 | + with self.subTest(x=x, is_negative=math.copysign(1, x) < 0): |
| 662 | + self.assertEqual(math.fmax(INF, x), INF) |
| 663 | + self.assertEqual(math.fmax(x, INF), INF) |
| 664 | + self.assertEqual(math.fmax(NINF, x), x) |
| 665 | + self.assertEqual(math.fmax(x, NINF), x) |
| 666 | + |
| 667 | + @requires_IEEE_754 |
| 668 | + def test_fmax_nans(self): |
| 669 | + # When exactly one operand is NaN, the other is returned. |
| 670 | + for x in [NINF, -1., -0., 0., 1., INF]: |
| 671 | + with self.subTest(x=x, is_negative=math.copysign(1, x) < 0): |
| 672 | + self.assertFalse(math.isnan(math.fmax(NAN, x))) |
| 673 | + self.assertFalse(math.isnan(math.fmax(x, NAN))) |
| 674 | + self.assertFalse(math.isnan(math.fmax(NNAN, x))) |
| 675 | + self.assertFalse(math.isnan(math.fmax(x, NNAN))) |
| 676 | + # When both operands are NaNs, fmax() returns NaN (see C11, F.10.9.2) |
| 677 | + # whose sign is implementation-defined (see C11, F.10.0.3). |
| 678 | + self.assertTrue(math.isnan(math.fmax(NAN, NAN))) |
| 679 | + self.assertTrue(math.isnan(math.fmax(NNAN, NNAN))) |
| 680 | + self.assertTrue(math.isnan(math.fmax(NAN, NNAN))) |
| 681 | + self.assertTrue(math.isnan(math.fmax(NNAN, NAN))) |
| 682 | + |
| 683 | + def test_fmin(self): |
| 684 | + self.assertRaises(TypeError, math.fmin) |
| 685 | + self.assertRaises(TypeError, math.fmin, 'x', 'y') |
| 686 | + |
| 687 | + self.assertEqual(math.fmin(0., 0.), 0.) |
| 688 | + self.assertEqual(math.fmin(1., 2.), 1.) |
| 689 | + self.assertEqual(math.fmin(2., 1.), 1.) |
| 690 | + |
| 691 | + self.assertEqual(math.fmin(+1., +0.), 0.) |
| 692 | + self.assertEqual(math.fmin(+0., +1.), 0.) |
| 693 | + self.assertEqual(math.fmin(+1., -0.), 0.) |
| 694 | + self.assertEqual(math.fmin(-0., +1.), 0.) |
| 695 | + |
| 696 | + self.assertEqual(math.fmin(-1., +0.), -1.) |
| 697 | + self.assertEqual(math.fmin(+0., -1.), -1.) |
| 698 | + self.assertEqual(math.fmin(-1., -0.), -1.) |
| 699 | + self.assertEqual(math.fmin(-0., -1.), -1.) |
| 700 | + |
| 701 | + for x in [NINF, -1., -0., 0., 1., INF]: |
| 702 | + self.assertFalse(math.isnan(x)) |
| 703 | + |
| 704 | + with self.subTest(x=x, is_negative=math.copysign(1, x) < 0): |
| 705 | + self.assertEqual(math.fmin(INF, x), x) |
| 706 | + self.assertEqual(math.fmin(x, INF), x) |
| 707 | + self.assertEqual(math.fmin(NINF, x), NINF) |
| 708 | + self.assertEqual(math.fmin(x, NINF), NINF) |
| 709 | + |
| 710 | + @requires_IEEE_754 |
| 711 | + def test_fmin_nans(self): |
| 712 | + # When exactly one operand is NaN, the other is returned. |
| 713 | + for x in [NINF, -1., -0., 0., 1., INF]: |
| 714 | + with self.subTest(x=x, is_negative=math.copysign(1, x) < 0): |
| 715 | + self.assertFalse(math.isnan(math.fmin(NAN, x))) |
| 716 | + self.assertFalse(math.isnan(math.fmin(x, NAN))) |
| 717 | + self.assertFalse(math.isnan(math.fmin(NNAN, x))) |
| 718 | + self.assertFalse(math.isnan(math.fmin(x, NNAN))) |
| 719 | + # When both operands are NaNs, fmin() returns NaN (see C11, F.10.9.3) |
| 720 | + # whose sign is implementation-defined (see C11, F.10.0.3). |
| 721 | + self.assertTrue(math.isnan(math.fmin(NAN, NAN))) |
| 722 | + self.assertTrue(math.isnan(math.fmin(NNAN, NNAN))) |
| 723 | + self.assertTrue(math.isnan(math.fmin(NAN, NNAN))) |
| 724 | + self.assertTrue(math.isnan(math.fmin(NNAN, NAN))) |
| 725 | + |
639 | 726 | def testFrexp(self): |
640 | 727 | self.assertRaises(TypeError, math.frexp) |
641 | 728 |
|
|
0 commit comments