MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_correctly_rounded_true_division

Method test_correctly_rounded_true_division

Lib/test/test_long.py:875–964  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

check_truedivMethod · 0.95
maxFunction · 0.85
randrangeMethod · 0.80

Tested by

no test coverage detected