(self)
| 2781 | self.assertEqual(math.fma(a - 1.0, a + 1.0, 1.0), a*a) |
| 2782 | |
| 2783 | def test_random(self): |
| 2784 | # A collection of randomly generated inputs for which the naive FMA |
| 2785 | # (with two rounds) gives a different result from a singly-rounded FMA. |
| 2786 | |
| 2787 | # tuples (a, b, c, expected) |
| 2788 | test_values = [ |
| 2789 | ('0x1.694adde428b44p-1', '0x1.371b0d64caed7p-1', |
| 2790 | '0x1.f347e7b8deab8p-4', '0x1.19f10da56c8adp-1'), |
| 2791 | ('0x1.605401ccc6ad6p-2', '0x1.ce3a40bf56640p-2', |
| 2792 | '0x1.96e3bf7bf2e20p-2', '0x1.1af6d8aa83101p-1'), |
| 2793 | ('0x1.e5abd653a67d4p-2', '0x1.a2e400209b3e6p-1', |
| 2794 | '0x1.a90051422ce13p-1', '0x1.37d68cc8c0fbbp+0'), |
| 2795 | ('0x1.f94e8efd54700p-2', '0x1.123065c812cebp-1', |
| 2796 | '0x1.458f86fb6ccd0p-1', '0x1.ccdcee26a3ff3p-1'), |
| 2797 | ('0x1.bd926f1eedc96p-1', '0x1.eee9ca68c5740p-1', |
| 2798 | '0x1.960c703eb3298p-2', '0x1.3cdcfb4fdb007p+0'), |
| 2799 | ('0x1.27348350fbccdp-1', '0x1.3b073914a53f1p-1', |
| 2800 | '0x1.e300da5c2b4cbp-1', '0x1.4c51e9a3c4e29p+0'), |
| 2801 | ('0x1.2774f00b3497bp-1', '0x1.7038ec336bff0p-2', |
| 2802 | '0x1.2f6f2ccc3576bp-1', '0x1.99ad9f9c2688bp-1'), |
| 2803 | ('0x1.51d5a99300e5cp-1', '0x1.5cd74abd445a1p-1', |
| 2804 | '0x1.8880ab0bbe530p-1', '0x1.3756f96b91129p+0'), |
| 2805 | ('0x1.73cb965b821b8p-2', '0x1.218fd3d8d5371p-1', |
| 2806 | '0x1.d1ea966a1f758p-2', '0x1.5217b8fd90119p-1'), |
| 2807 | ('0x1.4aa98e890b046p-1', '0x1.954d85dff1041p-1', |
| 2808 | '0x1.122b59317ebdfp-1', '0x1.0bf644b340cc5p+0'), |
| 2809 | ('0x1.e28f29e44750fp-1', '0x1.4bcc4fdcd18fep-1', |
| 2810 | '0x1.fd47f81298259p-1', '0x1.9b000afbc9995p+0'), |
| 2811 | ('0x1.d2e850717fe78p-3', '0x1.1dd7531c303afp-1', |
| 2812 | '0x1.e0869746a2fc2p-2', '0x1.316df6eb26439p-1'), |
| 2813 | ('0x1.cf89c75ee6fbap-2', '0x1.b23decdc66825p-1', |
| 2814 | '0x1.3d1fe76ac6168p-1', '0x1.00d8ea4c12abbp+0'), |
| 2815 | ('0x1.3265ae6f05572p-2', '0x1.16d7ec285f7a2p-1', |
| 2816 | '0x1.0b8405b3827fbp-1', '0x1.5ef33c118a001p-1'), |
| 2817 | ('0x1.c4d1bf55ec1a5p-1', '0x1.bc59618459e12p-2', |
| 2818 | '0x1.ce5b73dc1773dp-1', '0x1.496cf6164f99bp+0'), |
| 2819 | ('0x1.d350026ac3946p-1', '0x1.9a234e149a68cp-2', |
| 2820 | '0x1.f5467b1911fd6p-2', '0x1.b5cee3225caa5p-1'), |
| 2821 | ] |
| 2822 | for a_hex, b_hex, c_hex, expected_hex in test_values: |
| 2823 | with self.subTest(a_hex=a_hex, b_hex=b_hex, c_hex=c_hex, |
| 2824 | expected_hex=expected_hex): |
| 2825 | a = float.fromhex(a_hex) |
| 2826 | b = float.fromhex(b_hex) |
| 2827 | c = float.fromhex(c_hex) |
| 2828 | expected = float.fromhex(expected_hex) |
| 2829 | self.assertEqual(math.fma(a, b, c), expected) |
| 2830 | self.assertEqual(math.fma(b, a, c), expected) |
| 2831 | |
| 2832 | # Custom assertions. |
| 2833 | def assertIsNaN(self, value): |
nothing calls this directly
no test coverage detected