Verify that the result of a/b is correctly rounded, by comparing it with a pure Python implementation of correctly rounded division. b should be nonzero.
(self, a, b, skip_small=True)
| 840 | self.assertEqual(12 // 3, 4) |
| 841 | |
| 842 | def check_truediv(self, a, b, skip_small=True): |
| 843 | """Verify that the result of a/b is correctly rounded, by |
| 844 | comparing it with a pure Python implementation of correctly |
| 845 | rounded division. b should be nonzero.""" |
| 846 | |
| 847 | # skip check for small a and b: in this case, the current |
| 848 | # implementation converts the arguments to float directly and |
| 849 | # then applies a float division. This can give doubly-rounded |
| 850 | # results on x87-using machines (particularly 32-bit Linux). |
| 851 | if skip_small and max(abs(a), abs(b)) < 2**DBL_MANT_DIG: |
| 852 | return |
| 853 | |
| 854 | try: |
| 855 | # use repr so that we can distinguish between -0.0 and 0.0 |
| 856 | expected = repr(truediv(a, b)) |
| 857 | except OverflowError: |
| 858 | expected = 'overflow' |
| 859 | except ZeroDivisionError: |
| 860 | expected = 'zerodivision' |
| 861 | |
| 862 | try: |
| 863 | got = repr(a / b) |
| 864 | except OverflowError: |
| 865 | got = 'overflow' |
| 866 | except ZeroDivisionError: |
| 867 | got = 'zerodivision' |
| 868 | |
| 869 | self.assertEqual(expected, got, "Incorrectly rounded division {}/{}: " |
| 870 | "expected {}, got {}".format(a, b, expected, got)) |
| 871 | |
| 872 | @support.requires_IEEE_754 |
| 873 | def test_correctly_rounded_true_division(self): |
no test coverage detected