[Python-checkins] CVS: python/dist/src/Lib/test test_long.py,1.10,1.11

Tim Peters tim_one@users.sourceforge.net
Mon, 03 Sep 2001 22:14:21 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv28101/python/Lib/test

Modified Files:
	test_long.py 
Log Message:
Raise OverflowError when appropriate on long->float conversion.  Most of
the fiddling is simply due to that no caller of PyLong_AsDouble ever
checked for failure (so that's fixing old bugs).  PyLong_AsDouble is much
faster for big inputs now too, but that's more of a happy consequence
than a design goal.


Index: test_long.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_long.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test_long.py	2001/09/03 08:35:40	1.10
--- test_long.py	2001/09/04 05:14:18	1.11
***************
*** 329,332 ****
--- 329,368 ----
                                  "TypeError" % ((longx, longy, long(z))))
  
+ # ---------------------------------------- tests of long->float overflow
+ 
+ def test_float_overflow():
+     import math
+ 
+     if verbose:
+         print "long->float overflow"
+ 
+     for x in -2.0, -1.0, 0.0, 1.0, 2.0:
+         verify(float(long(x)) == x)
+ 
+     huge = 1L << 30000
+     mhuge = -huge
+     namespace = {'huge': huge, 'mhuge': mhuge, 'math': math}
+     for test in ["float(huge)", "float(mhuge)",
+                  "complex(huge)", "complex(mhuge)",
+                  "complex(huge, 1)", "complex(mhuge, 1)",
+                  "complex(1, huge)", "complex(1, mhuge)",
+                  "1. + huge", "huge + 1.", "1. + mhuge", "mhuge + 1.",
+                  "1. - huge", "huge - 1.", "1. - mhuge", "mhuge - 1.",
+                  "1. * huge", "huge * 1.", "1. * mhuge", "mhuge * 1.",
+                  "1. // huge", "huge // 1.", "1. // mhuge", "mhuge // 1.",
+                  "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:
+             eval(test, namespace)
+         except OverflowError:
+             pass
+         else:
+             raise TestFailed("expected OverflowError from %s" % test)
  # ---------------------------------------------------------------- do it
  
***************
*** 336,337 ****
--- 372,374 ----
  test_misc()
  test_auto_overflow()
+ test_float_overflow()