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