diff options
author | Tim Peters <tim.peters@gmail.com> | 2001-09-05 00:53:45 (GMT) |
---|---|---|
committer | Tim Peters <tim.peters@gmail.com> | 2001-09-05 00:53:45 (GMT) |
commit | 785261684e0e660dcdce48daf683cec541f4a8f2 (patch) | |
tree | 93a48bc9c7d2bf9725406c756a5535f298e583a0 /Lib/test | |
parent | 63c945392917cd9c228a613d2e965500452bb92e (diff) | |
download | cpython-785261684e0e660dcdce48daf683cec541f4a8f2.zip cpython-785261684e0e660dcdce48daf683cec541f4a8f2.tar.gz cpython-785261684e0e660dcdce48daf683cec541f4a8f2.tar.bz2 |
Return reasonable results for math.log(long) and math.log10(long) (we were
getting Infs, NaNs, or nonsense in 2.1 and before; in yesterday's CVS we
were getting OverflowError; but these functions always make good sense
for positive arguments, no matter how large).
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_long.py | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 104b086..573ef75 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -1,4 +1,4 @@ -from test_support import verify, verbose, TestFailed +from test_support import verify, verbose, TestFailed, fcmp from string import join from random import random, randint @@ -353,9 +353,7 @@ def test_float_overflow(): "1. / huge", "huge / 1.", "1. / mhuge", "mhuge / 1.", "1. ** huge", "huge ** 1.", "1. ** mhuge", "mhuge ** 1.", "math.sin(huge)", "math.sin(mhuge)", - "math.log(huge)", "math.log(mhuge)", # should do better "math.sqrt(huge)", "math.sqrt(mhuge)", # should do better - "math.log10(huge)", "math.log10(mhuge)", # should do better "math.floor(huge)", "math.floor(mhuge)"]: try: @@ -364,6 +362,41 @@ def test_float_overflow(): pass else: raise TestFailed("expected OverflowError from %s" % test) + +# ---------------------------------------------- test huge log and log10 + +def test_logs(): + import math + + if verbose: + print "log and log10" + + LOG10E = math.log10(math.e) + + for exp in range(10) + [100, 1000, 10000]: + value = 10 ** exp + log10 = math.log10(value) + verify(fcmp(log10, exp) == 0) + + # log10(value) == exp, so log(value) == log10(value)/log10(e) == + # exp/LOG10E + expected = exp / LOG10E + log = math.log(value) + verify(fcmp(log, expected) == 0) + + for bad in -(1L << 10000), -2L, 0L: + try: + math.log(bad) + raise TestFailed("expected ValueError from log(<= 0)") + except ValueError: + pass + + try: + math.log10(bad) + raise TestFailed("expected ValueError from log10(<= 0)") + except ValueError: + pass + # ---------------------------------------------------------------- do it test_division() @@ -372,3 +405,4 @@ test_format() test_misc() test_auto_overflow() test_float_overflow() +test_logs() |