Commit 98c8184f authored by Tim Peters's avatar Tim Peters

Test for math.* exceptional behavior only in verbose mode, so that the

oddball platforms (where, e.g., math.exp(+huge) still fails to raise
OverflowError) don't fail the std test suite when run normally.
parent a8268e94
...@@ -24,4 +24,3 @@ sinh ...@@ -24,4 +24,3 @@ sinh
sqrt sqrt
tan tan
tanh tanh
exceptions
...@@ -153,33 +153,43 @@ print 'tanh' ...@@ -153,33 +153,43 @@ print 'tanh'
testit('tanh(0)', math.tanh(0), 0) testit('tanh(0)', math.tanh(0), 0)
testit('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0) testit('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0)
print 'exceptions' # oooooh, *this* is a x-platform gamble! good luck # RED_FLAG 16-Oct-2000 Tim
# While 2.0 is more consistent about exceptions than previous releases, it
try: # still fails this part of the test on some platforms. For now, we only
x = math.exp(-1000000000) # *run* test_exceptions() in verbose mode, so that this isn't normally
except: # tested.
# mathmodule.c is failing to weed out underflows from libm, or
# we've got an fp format with huge dynamic range def test_exceptions():
raise TestFailed("underflowing exp() should not have rasied an exception") print 'exceptions'
if x != 0: try:
raise TestFailed("underflowing exp() should have returned 0") x = math.exp(-1000000000)
except:
# If this fails, probably using a strict IEEE-754 conforming libm, and x # mathmodule.c is failing to weed out underflows from libm, or
# is +Inf afterwards. But Python wants overflows detected by default. # we've got an fp format with huge dynamic range
try: raise TestFailed("underflowing exp() should not have raised "
x = math.exp(1000000000) "an exception")
except OverflowError: if x != 0:
pass raise TestFailed("underflowing exp() should have returned 0")
else:
raise TestFailed("overflowing exp() didn't trigger OverflowError") # If this fails, probably using a strict IEEE-754 conforming libm, and x
# is +Inf afterwards. But Python wants overflows detected by default.
# If this fails, it could be a puzzle. One odd possibility is that try:
# mathmodule.c's CHECK() macro is getting confused while comparing x = math.exp(1000000000)
# Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE except OverflowError:
# as a result (and so raising OverflowError instead). pass
try: else:
x = math.sqrt(-1.0) raise TestFailed("overflowing exp() didn't trigger OverflowError")
except ValueError:
pass # If this fails, it could be a puzzle. One odd possibility is that
else: # mathmodule.c's CHECK() macro is getting confused while comparing
raise TestFailed("sqrt(-1) didn't raise ValueError") # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE
# as a result (and so raising OverflowError instead).
try:
x = math.sqrt(-1.0)
except ValueError:
pass
else:
raise TestFailed("sqrt(-1) didn't raise ValueError")
if verbose:
test_exceptions()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment