Commit 6328f41d authored by Mark Dickinson's avatar Mark Dickinson

Merged revisions 78289 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r78289 | mark.dickinson | 2010-02-21 14:49:52 +0000 (Sun, 21 Feb 2010) | 9 lines

  Merged revisions 78287 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r78287 | mark.dickinson | 2010-02-21 14:42:27 +0000 (Sun, 21 Feb 2010) | 1 line

    Reduce number of random tests in test_strtod, to avoid hogging buildbot time.
  ........
................
parent 8e8effda
...@@ -76,7 +76,7 @@ def strtod(s, mant_dig=53, min_exp = -1021, max_exp = 1024): ...@@ -76,7 +76,7 @@ def strtod(s, mant_dig=53, min_exp = -1021, max_exp = 1024):
hexdigs, hexdigs,
e + 4*hexdigs) e + 4*hexdigs)
TEST_SIZE = 16 TEST_SIZE = 10
@unittest.skipUnless(getattr(sys, 'float_repr_style', '') == 'short', @unittest.skipUnless(getattr(sys, 'float_repr_style', '') == 'short',
"applies only when using short float repr style") "applies only when using short float repr style")
...@@ -109,7 +109,7 @@ class StrtodTests(unittest.TestCase): ...@@ -109,7 +109,7 @@ class StrtodTests(unittest.TestCase):
lower = -(-2**53//5**k) lower = -(-2**53//5**k)
if lower % 2 == 0: if lower % 2 == 0:
lower += 1 lower += 1
for i in range(10 * TEST_SIZE): for i in range(TEST_SIZE):
# Select a random odd n in [2**53/5**k, # Select a random odd n in [2**53/5**k,
# 2**54/5**k). Then n * 10**k gives a halfway case # 2**54/5**k). Then n * 10**k gives a halfway case
# with small number of significant digits. # with small number of significant digits.
...@@ -145,34 +145,29 @@ class StrtodTests(unittest.TestCase): ...@@ -145,34 +145,29 @@ class StrtodTests(unittest.TestCase):
def test_halfway_cases(self): def test_halfway_cases(self):
# test halfway cases for the round-half-to-even rule # test halfway cases for the round-half-to-even rule
for i in range(1000): for i in range(100 * TEST_SIZE):
for j in range(TEST_SIZE): # bit pattern for a random finite positive (or +0.0) float
# bit pattern for a random finite positive (or +0.0) float bits = random.randrange(2047*2**52)
bits = random.randrange(2047*2**52)
# convert bit pattern to a number of the form m * 2**e
# convert bit pattern to a number of the form m * 2**e e, m = divmod(bits, 2**52)
e, m = divmod(bits, 2**52) if e:
if e: m, e = m + 2**52, e - 1
m, e = m + 2**52, e - 1 e -= 1074
e -= 1074
# add 0.5 ulps
# add 0.5 ulps m, e = 2*m + 1, e - 1
m, e = 2*m + 1, e - 1
# convert to a decimal string
# convert to a decimal string if e >= 0:
if e >= 0: digits = m << e
digits = m << e exponent = 0
exponent = 0 else:
else: # m * 2**e = (m * 5**-e) * 10**e
# m * 2**e = (m * 5**-e) * 10**e digits = m * 5**-e
digits = m * 5**-e exponent = e
exponent = e s = '{}e{}'.format(digits, exponent)
s = '{}e{}'.format(digits, exponent) self.check_strtod(s)
self.check_strtod(s)
# get expected answer via struct, to triple check
#fs = struct.unpack('<d', struct.pack('<Q', bits + (bits&1)))[0]
#self.assertEqual(fs, float(s))
def test_boundaries(self): def test_boundaries(self):
# boundaries expressed as triples (n, e, u), where # boundaries expressed as triples (n, e, u), where
...@@ -186,11 +181,10 @@ class StrtodTests(unittest.TestCase): ...@@ -186,11 +181,10 @@ class StrtodTests(unittest.TestCase):
] ]
for n, e, u in boundaries: for n, e, u in boundaries:
for j in range(1000): for j in range(1000):
for i in range(TEST_SIZE): digits = n + random.randrange(-3*u, 3*u)
digits = n + random.randrange(-3*u, 3*u) exponent = e
exponent = e s = '{}e{}'.format(digits, exponent)
s = '{}e{}'.format(digits, exponent) self.check_strtod(s)
self.check_strtod(s)
n *= 10 n *= 10
u *= 10 u *= 10
e -= 1 e -= 1
...@@ -209,7 +203,7 @@ class StrtodTests(unittest.TestCase): ...@@ -209,7 +203,7 @@ class StrtodTests(unittest.TestCase):
def test_bigcomp(self): def test_bigcomp(self):
for ndigs in 5, 10, 14, 15, 16, 17, 18, 19, 20, 40, 41, 50: for ndigs in 5, 10, 14, 15, 16, 17, 18, 19, 20, 40, 41, 50:
dig10 = 10**ndigs dig10 = 10**ndigs
for i in range(100 * TEST_SIZE): for i in range(10 * TEST_SIZE):
digits = random.randrange(dig10) digits = random.randrange(dig10)
exponent = random.randrange(-400, 400) exponent = random.randrange(-400, 400)
s = '{}e{}'.format(digits, exponent) s = '{}e{}'.format(digits, exponent)
......
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