10a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom __future__ import division
20a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# When true division is the default, get rid of this and add it to
30a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# test_long.py instead.  In the meantime, it's too obscure to try to
40a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# trick just part of test_long into using future division.
50a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
60a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport sys
70a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport random
80a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport math
90a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoimport unittest
100a8c90248264a8b26970b4473770bcc3df8515fJosh Gaofrom test.test_support import run_unittest
110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# decorator for skipping tests on non-IEEE 754 platforms
130a8c90248264a8b26970b4473770bcc3df8515fJosh Gaorequires_IEEE_754 = unittest.skipUnless(
140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    float.__getformat__("double").startswith("IEEE"),
150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    "test requires IEEE 754 doubles")
160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
170a8c90248264a8b26970b4473770bcc3df8515fJosh GaoDBL_MAX = sys.float_info.max
180a8c90248264a8b26970b4473770bcc3df8515fJosh GaoDBL_MAX_EXP = sys.float_info.max_exp
190a8c90248264a8b26970b4473770bcc3df8515fJosh GaoDBL_MIN_EXP = sys.float_info.min_exp
200a8c90248264a8b26970b4473770bcc3df8515fJosh GaoDBL_MANT_DIG = sys.float_info.mant_dig
210a8c90248264a8b26970b4473770bcc3df8515fJosh GaoDBL_MIN_OVERFLOW = 2**DBL_MAX_EXP - 2**(DBL_MAX_EXP - DBL_MANT_DIG - 1)
220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao# pure Python version of correctly-rounded true division
240a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef truediv(a, b):
250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    """Correctly-rounded true division for integers."""
260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    negative = a^b < 0
270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    a, b = abs(a), abs(b)
280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # exceptions:  division by zero, overflow
300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if not b:
310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        raise ZeroDivisionError("division by zero")
320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if a >= DBL_MIN_OVERFLOW * b:
330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        raise OverflowError("int/int too large to represent as a float")
340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao   # find integer d satisfying 2**(d - 1) <= a/b < 2**d
360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    d = a.bit_length() - b.bit_length()
370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if d >= 0 and a >= 2**d * b or d < 0 and a * 2**-d >= b:
380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        d += 1
390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # compute 2**-exp * a / b for suitable exp
410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    exp = max(d, DBL_MIN_EXP) - DBL_MANT_DIG
420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    a, b = a << max(-exp, 0), b << max(exp, 0)
430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    q, r = divmod(a, b)
440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # round-half-to-even: fractional part is r/b, which is > 0.5 iff
460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    # 2*r > b, and == 0.5 iff 2*r == b.
470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    if 2*r > b or 2*r == b and q % 2 == 1:
480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        q += 1
490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    result = math.ldexp(float(q), exp)
510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    return -result if negative else result
520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
530a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoclass TrueDivisionTests(unittest.TestCase):
540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test(self):
550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        huge = 1L << 40000
560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        mhuge = -huge
570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(huge / huge, 1.0)
580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(mhuge / mhuge, 1.0)
590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(huge / mhuge, -1.0)
600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(mhuge / huge, -1.0)
610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(1 / huge, 0.0)
620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(1L / huge, 0.0)
630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(1 / mhuge, 0.0)
640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(1L / mhuge, 0.0)
650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual((666 * huge + (huge >> 1)) / huge, 666.5)
660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual((666 * mhuge + (mhuge >> 1)) / mhuge, 666.5)
670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual((666 * huge + (huge >> 1)) / mhuge, -666.5)
680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual((666 * mhuge + (mhuge >> 1)) / huge, -666.5)
690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(huge / (huge << 1), 0.5)
700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual((1000000 * huge) / huge, 1000000)
710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        namespace = {'huge': huge, 'mhuge': mhuge}
730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for overflow in ["float(huge)", "float(mhuge)",
750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                         "huge / 1", "huge / 2L", "huge / -1", "huge / -2L",
760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                         "mhuge / 100", "mhuge / 100L"]:
770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # If the "eval" does not happen in this module,
780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # true division is not enabled
790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            with self.assertRaises(OverflowError):
800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                eval(overflow, namespace)
810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for underflow in ["1 / huge", "2L / huge", "-1 / huge", "-2L / huge",
830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                         "100 / mhuge", "100L / mhuge"]:
840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            result = eval(underflow, namespace)
850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.assertEqual(result, 0.0, 'expected underflow to 0 '
860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                             'from {!r}'.format(underflow))
870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for zero in ["huge / 0", "huge / 0L", "mhuge / 0", "mhuge / 0L"]:
890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            with self.assertRaises(ZeroDivisionError):
900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                eval(zero, namespace)
910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def check_truediv(self, a, b, skip_small=True):
930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        """Verify that the result of a/b is correctly rounded, by
940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        comparing it with a pure Python implementation of correctly
950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        rounded division.  b should be nonzero."""
960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        a, b = long(a), long(b)
980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # skip check for small a and b: in this case, the current
1000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # implementation converts the arguments to float directly and
1010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # then applies a float division.  This can give doubly-rounded
1020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # results on x87-using machines (particularly 32-bit Linux).
1030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        if skip_small and max(abs(a), abs(b)) < 2**DBL_MANT_DIG:
1040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            return
1050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        try:
1070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # use repr so that we can distinguish between -0.0 and 0.0
1080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            expected = repr(truediv(a, b))
1090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        except OverflowError:
1100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            expected = 'overflow'
1110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        except ZeroDivisionError:
1120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            expected = 'zerodivision'
1130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        try:
1150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            got = repr(a / b)
1160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        except OverflowError:
1170a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            got = 'overflow'
1180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        except ZeroDivisionError:
1190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            got = 'zerodivision'
1200a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.assertEqual(expected, got, "Incorrectly rounded division {}/{}: "
1220a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                         "expected {}, got {}".format(a, b, expected, got))
1230a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1240a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    @requires_IEEE_754
1250a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    def test_correctly_rounded_true_division(self):
1260a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # more stringent tests than those above, checking that the
1270a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # result of true division of ints is always correctly rounded.
1280a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # This test should probably be considered CPython-specific.
1290a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1300a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # Exercise all the code paths not involving Gb-sized ints.
1310a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # ... divisions involving zero
1320a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(123, 0)
1330a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(-456, 0)
1340a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(0, 3)
1350a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(0, -3)
1360a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(0, 0)
1370a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # ... overflow or underflow by large margin
1380a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(671 * 12345 * 2**DBL_MAX_EXP, 12345)
1390a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(12345, 345678 * 2**(DBL_MANT_DIG - DBL_MIN_EXP))
1400a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # ... a much larger or smaller than b
1410a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(12345*2**100, 98765)
1420a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(12345*2**30, 98765*7**81)
1430a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # ... a / b near a boundary: one of 1, 2**DBL_MANT_DIG, 2**DBL_MIN_EXP,
1440a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        #                 2**DBL_MAX_EXP, 2**(DBL_MIN_EXP-DBL_MANT_DIG)
1450a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        bases = (0, DBL_MANT_DIG, DBL_MIN_EXP,
1460a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                 DBL_MAX_EXP, DBL_MIN_EXP - DBL_MANT_DIG)
1470a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for base in bases:
1480a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            for exp in range(base - 15, base + 15):
1490a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(75312*2**max(exp, 0), 69187*2**max(-exp, 0))
1500a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(69187*2**max(exp, 0), 75312*2**max(-exp, 0))
1510a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1520a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # overflow corner case
1530a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for m in [1, 2, 7, 17, 12345, 7**100,
1540a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                  -1, -2, -5, -23, -67891, -41**50]:
1550a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            for n in range(-10, 10):
1560a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(m*DBL_MIN_OVERFLOW + n, m)
1570a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(m*DBL_MIN_OVERFLOW + n, -m)
1580a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1590a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # check detection of inexactness in shifting stage
1600a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for n in range(250):
1610a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # (2**DBL_MANT_DIG+1)/(2**DBL_MANT_DIG) lies halfway
1620a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # between two representable floats, and would usually be
1630a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # rounded down under round-half-to-even.  The tiniest of
1640a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # additions to the numerator should cause it to be rounded
1650a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            # up instead.
1660a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv((2**DBL_MANT_DIG + 1)*12345*2**200 + 2**n,
1670a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                           2**DBL_MANT_DIG*12345)
1680a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1690a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # 1/2731 is one of the smallest division cases that's subject
1700a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # to double rounding on IEEE 754 machines working internally with
1710a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # 64-bit precision.  On such machines, the next check would fail,
1720a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # were it not explicitly skipped in check_truediv.
1730a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(1, 2731)
1740a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1750a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # a particularly bad case for the old algorithm:  gives an
1760a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # error of close to 3.5 ulps.
1770a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        self.check_truediv(295147931372582273023, 295147932265116303360)
1780a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for i in range(1000):
1790a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv(10**(i+1), 10**i)
1800a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv(10**i, 10**(i+1))
1810a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1820a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # test round-half-to-even behaviour, normal result
1830a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for m in [1, 2, 4, 7, 8, 16, 17, 32, 12345, 7**100,
1840a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                  -1, -2, -5, -23, -67891, -41**50]:
1850a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            for n in range(-10, 10):
1860a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(2**DBL_MANT_DIG*m + n, m)
1870a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1880a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # test round-half-to-even, subnormal result
1890a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for n in range(-20, 20):
1900a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv(n, 2**1076)
1910a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
1920a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # largeish random divisions: a/b where |a| <= |b| <=
1930a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # 2*|a|; |ans| is between 0.5 and 1.0, so error should
1940a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # always be bounded by 2**-54 with equality possible only
1950a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # if the least significant bit of q=ans*2**53 is zero.
1960a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for M in [10**10, 10**100, 10**1000]:
1970a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            for i in range(1000):
1980a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                a = random.randrange(1, M)
1990a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                b = random.randrange(a, 2*a+1)
2000a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(a, b)
2010a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(-a, b)
2020a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(a, -b)
2030a8c90248264a8b26970b4473770bcc3df8515fJosh Gao                self.check_truediv(-a, -b)
2040a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2050a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        # and some (genuinely) random tests
2060a8c90248264a8b26970b4473770bcc3df8515fJosh Gao        for _ in range(10000):
2070a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            a_bits = random.randrange(1000)
2080a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            b_bits = random.randrange(1, 1000)
2090a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            x = random.randrange(2**a_bits)
2100a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            y = random.randrange(1, 2**b_bits)
2110a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv(x, y)
2120a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv(x, -y)
2130a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv(-x, y)
2140a8c90248264a8b26970b4473770bcc3df8515fJosh Gao            self.check_truediv(-x, -y)
2150a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2160a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2170a8c90248264a8b26970b4473770bcc3df8515fJosh Gaodef test_main():
2180a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    run_unittest(TrueDivisionTests)
2190a8c90248264a8b26970b4473770bcc3df8515fJosh Gao
2200a8c90248264a8b26970b4473770bcc3df8515fJosh Gaoif __name__ == "__main__":
2210a8c90248264a8b26970b4473770bcc3df8515fJosh Gao    test_main()
222