summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long_future.py
blob: 4348bbe05ae5beea3c5d627a6c0cad58ae9703e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import division
# When true division is the default, get rid of this and add it to
# test_long.py instead.  In the meantime, it's too obscure to try to
# trick just part of test_long into using future division.

from test_support import TestFailed, verify, verbose

def test_true_division():
    if verbose:
        print "long true division"
    huge = 1L << 40000
    mhuge = -huge
    verify(huge / huge == 1.0)
    verify(mhuge / mhuge == 1.0)
    verify(huge / mhuge == -1.0)
    verify(mhuge / huge == -1.0)
    verify(1 / huge == 0.0)
    verify(1L / huge == 0.0)
    verify(1 / mhuge == 0.0)
    verify(1L / mhuge ==- 0.0)
    verify((666 * huge + (huge >> 1)) / huge == 666.5)
    verify((666 * mhuge + (mhuge >> 1)) / mhuge == 666.5)
    verify((666 * huge + (huge >> 1)) / mhuge == -666.5)
    verify((666 * mhuge + (mhuge >> 1)) / huge == -666.5)
    verify(huge / (huge << 1) == 0.5)

    namespace = {'huge': huge, 'mhuge': mhuge}
    for overflow in ["float(huge)", "float(mhuge)",
                     "huge / 1", "huge / 2L", "huge / -1", "huge / -2L",
                     "mhuge / 100", "mhuge / 100L"]:
        try:
            eval(overflow, namespace)
        except OverflowError:
            pass
        else:
            raise TestFailed("expected OverflowError from %r" % overflow)

test_true_division()