(self)
| 871 | |
| 872 | @support.requires_IEEE_754 |
| 873 | def test_correctly_rounded_true_division(self): |
| 874 | # more stringent tests than those above, checking that the |
| 875 | # result of true division of ints is always correctly rounded. |
| 876 | # This test should probably be considered CPython-specific. |
| 877 | |
| 878 | # Exercise all the code paths not involving Gb-sized ints. |
| 879 | # ... divisions involving zero |
| 880 | self.check_truediv(123, 0) |
| 881 | self.check_truediv(-456, 0) |
| 882 | self.check_truediv(0, 3) |
| 883 | self.check_truediv(0, -3) |
| 884 | self.check_truediv(0, 0) |
| 885 | # ... overflow or underflow by large margin |
| 886 | self.check_truediv(671 * 12345 * 2**DBL_MAX_EXP, 12345) |
| 887 | self.check_truediv(12345, 345678 * 2**(DBL_MANT_DIG - DBL_MIN_EXP)) |
| 888 | # ... a much larger or smaller than b |
| 889 | self.check_truediv(12345*2**100, 98765) |
| 890 | self.check_truediv(12345*2**30, 98765*7**81) |
| 891 | # ... a / b near a boundary: one of 1, 2**DBL_MANT_DIG, 2**DBL_MIN_EXP, |
| 892 | # 2**DBL_MAX_EXP, 2**(DBL_MIN_EXP-DBL_MANT_DIG) |
| 893 | bases = (0, DBL_MANT_DIG, DBL_MIN_EXP, |
| 894 | DBL_MAX_EXP, DBL_MIN_EXP - DBL_MANT_DIG) |
| 895 | for base in bases: |
| 896 | for exp in range(base - 15, base + 15): |
| 897 | self.check_truediv(75312*2**max(exp, 0), 69187*2**max(-exp, 0)) |
| 898 | self.check_truediv(69187*2**max(exp, 0), 75312*2**max(-exp, 0)) |
| 899 | |
| 900 | # overflow corner case |
| 901 | for m in [1, 2, 7, 17, 12345, 7**100, |
| 902 | -1, -2, -5, -23, -67891, -41**50]: |
| 903 | for n in range(-10, 10): |
| 904 | self.check_truediv(m*DBL_MIN_OVERFLOW + n, m) |
| 905 | self.check_truediv(m*DBL_MIN_OVERFLOW + n, -m) |
| 906 | |
| 907 | # check detection of inexactness in shifting stage |
| 908 | for n in range(250): |
| 909 | # (2**DBL_MANT_DIG+1)/(2**DBL_MANT_DIG) lies halfway |
| 910 | # between two representable floats, and would usually be |
| 911 | # rounded down under round-half-to-even. The tiniest of |
| 912 | # additions to the numerator should cause it to be rounded |
| 913 | # up instead. |
| 914 | self.check_truediv((2**DBL_MANT_DIG + 1)*12345*2**200 + 2**n, |
| 915 | 2**DBL_MANT_DIG*12345) |
| 916 | |
| 917 | # 1/2731 is one of the smallest division cases that's subject |
| 918 | # to double rounding on IEEE 754 machines working internally with |
| 919 | # 64-bit precision. On such machines, the next check would fail, |
| 920 | # were it not explicitly skipped in check_truediv. |
| 921 | self.check_truediv(1, 2731) |
| 922 | |
| 923 | # a particularly bad case for the old algorithm: gives an |
| 924 | # error of close to 3.5 ulps. |
| 925 | self.check_truediv(295147931372582273023, 295147932265116303360) |
| 926 | for i in range(1000): |
| 927 | self.check_truediv(10**(i+1), 10**i) |
| 928 | self.check_truediv(10**i, 10**(i+1)) |
| 929 | |
| 930 | # test round-half-to-even behaviour, normal result |
nothing calls this directly
no test coverage detected