diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-04 06:17:36 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-04 06:17:36 (GMT) |
commit | e2a600099d3b61327aba5be94d30d40773faa2c9 (patch) | |
tree | 7f9ed79ab6f997c2afbeae21bb097d045c344e66 /Lib | |
parent | 9c1d7fd5f2173dc72ecdb1df7816c7e432437e02 (diff) | |
download | cpython-e2a600099d3b61327aba5be94d30d40773faa2c9.zip cpython-e2a600099d3b61327aba5be94d30d40773faa2c9.tar.gz cpython-e2a600099d3b61327aba5be94d30d40773faa2c9.tar.bz2 |
Change long/long true division to return as many good bits as it can;
e.g., (1L << 40000)/(1L << 40001) returns 0.5, not Inf or NaN or whatever.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_long_future.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_long_future.py b/Lib/test/test_long_future.py new file mode 100644 index 0000000..4348bbe --- /dev/null +++ b/Lib/test/test_long_future.py @@ -0,0 +1,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() |