1 | n/a | # Tests for the correctly-rounded string -> float conversions |
---|
2 | n/a | # introduced in Python 2.7 and 3.1. |
---|
3 | n/a | |
---|
4 | n/a | import random |
---|
5 | n/a | import unittest |
---|
6 | n/a | import re |
---|
7 | n/a | import sys |
---|
8 | n/a | import test.support |
---|
9 | n/a | |
---|
10 | n/a | if getattr(sys, 'float_repr_style', '') != 'short': |
---|
11 | n/a | raise unittest.SkipTest('correctly-rounded string->float conversions ' |
---|
12 | n/a | 'not available on this system') |
---|
13 | n/a | |
---|
14 | n/a | # Correctly rounded str -> float in pure Python, for comparison. |
---|
15 | n/a | |
---|
16 | n/a | strtod_parser = re.compile(r""" # A numeric string consists of: |
---|
17 | n/a | (?P<sign>[-+])? # an optional sign, followed by |
---|
18 | n/a | (?=\d|\.\d) # a number with at least one digit |
---|
19 | n/a | (?P<int>\d*) # having a (possibly empty) integer part |
---|
20 | n/a | (?:\.(?P<frac>\d*))? # followed by an optional fractional part |
---|
21 | n/a | (?:E(?P<exp>[-+]?\d+))? # and an optional exponent |
---|
22 | n/a | \Z |
---|
23 | n/a | """, re.VERBOSE | re.IGNORECASE).match |
---|
24 | n/a | |
---|
25 | n/a | # Pure Python version of correctly rounded string->float conversion. |
---|
26 | n/a | # Avoids any use of floating-point by returning the result as a hex string. |
---|
27 | n/a | def strtod(s, mant_dig=53, min_exp = -1021, max_exp = 1024): |
---|
28 | n/a | """Convert a finite decimal string to a hex string representing an |
---|
29 | n/a | IEEE 754 binary64 float. Return 'inf' or '-inf' on overflow. |
---|
30 | n/a | This function makes no use of floating-point arithmetic at any |
---|
31 | n/a | stage.""" |
---|
32 | n/a | |
---|
33 | n/a | # parse string into a pair of integers 'a' and 'b' such that |
---|
34 | n/a | # abs(decimal value) = a/b, along with a boolean 'negative'. |
---|
35 | n/a | m = strtod_parser(s) |
---|
36 | n/a | if m is None: |
---|
37 | n/a | raise ValueError('invalid numeric string') |
---|
38 | n/a | fraction = m.group('frac') or '' |
---|
39 | n/a | intpart = int(m.group('int') + fraction) |
---|
40 | n/a | exp = int(m.group('exp') or '0') - len(fraction) |
---|
41 | n/a | negative = m.group('sign') == '-' |
---|
42 | n/a | a, b = intpart*10**max(exp, 0), 10**max(0, -exp) |
---|
43 | n/a | |
---|
44 | n/a | # quick return for zeros |
---|
45 | n/a | if not a: |
---|
46 | n/a | return '-0x0.0p+0' if negative else '0x0.0p+0' |
---|
47 | n/a | |
---|
48 | n/a | # compute exponent e for result; may be one too small in the case |
---|
49 | n/a | # that the rounded value of a/b lies in a different binade from a/b |
---|
50 | n/a | d = a.bit_length() - b.bit_length() |
---|
51 | n/a | d += (a >> d if d >= 0 else a << -d) >= b |
---|
52 | n/a | e = max(d, min_exp) - mant_dig |
---|
53 | n/a | |
---|
54 | n/a | # approximate a/b by number of the form q * 2**e; adjust e if necessary |
---|
55 | n/a | a, b = a << max(-e, 0), b << max(e, 0) |
---|
56 | n/a | q, r = divmod(a, b) |
---|
57 | n/a | if 2*r > b or 2*r == b and q & 1: |
---|
58 | n/a | q += 1 |
---|
59 | n/a | if q.bit_length() == mant_dig+1: |
---|
60 | n/a | q //= 2 |
---|
61 | n/a | e += 1 |
---|
62 | n/a | |
---|
63 | n/a | # double check that (q, e) has the right form |
---|
64 | n/a | assert q.bit_length() <= mant_dig and e >= min_exp - mant_dig |
---|
65 | n/a | assert q.bit_length() == mant_dig or e == min_exp - mant_dig |
---|
66 | n/a | |
---|
67 | n/a | # check for overflow and underflow |
---|
68 | n/a | if e + q.bit_length() > max_exp: |
---|
69 | n/a | return '-inf' if negative else 'inf' |
---|
70 | n/a | if not q: |
---|
71 | n/a | return '-0x0.0p+0' if negative else '0x0.0p+0' |
---|
72 | n/a | |
---|
73 | n/a | # for hex representation, shift so # bits after point is a multiple of 4 |
---|
74 | n/a | hexdigs = 1 + (mant_dig-2)//4 |
---|
75 | n/a | shift = 3 - (mant_dig-2)%4 |
---|
76 | n/a | q, e = q << shift, e - shift |
---|
77 | n/a | return '{}0x{:x}.{:0{}x}p{:+d}'.format( |
---|
78 | n/a | '-' if negative else '', |
---|
79 | n/a | q // 16**hexdigs, |
---|
80 | n/a | q % 16**hexdigs, |
---|
81 | n/a | hexdigs, |
---|
82 | n/a | e + 4*hexdigs) |
---|
83 | n/a | |
---|
84 | n/a | TEST_SIZE = 10 |
---|
85 | n/a | |
---|
86 | n/a | class StrtodTests(unittest.TestCase): |
---|
87 | n/a | def check_strtod(self, s): |
---|
88 | n/a | """Compare the result of Python's builtin correctly rounded |
---|
89 | n/a | string->float conversion (using float) to a pure Python |
---|
90 | n/a | correctly rounded string->float implementation. Fail if the |
---|
91 | n/a | two methods give different results.""" |
---|
92 | n/a | |
---|
93 | n/a | try: |
---|
94 | n/a | fs = float(s) |
---|
95 | n/a | except OverflowError: |
---|
96 | n/a | got = '-inf' if s[0] == '-' else 'inf' |
---|
97 | n/a | except MemoryError: |
---|
98 | n/a | got = 'memory error' |
---|
99 | n/a | else: |
---|
100 | n/a | got = fs.hex() |
---|
101 | n/a | expected = strtod(s) |
---|
102 | n/a | self.assertEqual(expected, got, |
---|
103 | n/a | "Incorrectly rounded str->float conversion for {}: " |
---|
104 | n/a | "expected {}, got {}".format(s, expected, got)) |
---|
105 | n/a | |
---|
106 | n/a | def test_short_halfway_cases(self): |
---|
107 | n/a | # exact halfway cases with a small number of significant digits |
---|
108 | n/a | for k in 0, 5, 10, 15, 20: |
---|
109 | n/a | # upper = smallest integer >= 2**54/5**k |
---|
110 | n/a | upper = -(-2**54//5**k) |
---|
111 | n/a | # lower = smallest odd number >= 2**53/5**k |
---|
112 | n/a | lower = -(-2**53//5**k) |
---|
113 | n/a | if lower % 2 == 0: |
---|
114 | n/a | lower += 1 |
---|
115 | n/a | for i in range(TEST_SIZE): |
---|
116 | n/a | # Select a random odd n in [2**53/5**k, |
---|
117 | n/a | # 2**54/5**k). Then n * 10**k gives a halfway case |
---|
118 | n/a | # with small number of significant digits. |
---|
119 | n/a | n, e = random.randrange(lower, upper, 2), k |
---|
120 | n/a | |
---|
121 | n/a | # Remove any additional powers of 5. |
---|
122 | n/a | while n % 5 == 0: |
---|
123 | n/a | n, e = n // 5, e + 1 |
---|
124 | n/a | assert n % 10 in (1, 3, 7, 9) |
---|
125 | n/a | |
---|
126 | n/a | # Try numbers of the form n * 2**p2 * 10**e, p2 >= 0, |
---|
127 | n/a | # until n * 2**p2 has more than 20 significant digits. |
---|
128 | n/a | digits, exponent = n, e |
---|
129 | n/a | while digits < 10**20: |
---|
130 | n/a | s = '{}e{}'.format(digits, exponent) |
---|
131 | n/a | self.check_strtod(s) |
---|
132 | n/a | # Same again, but with extra trailing zeros. |
---|
133 | n/a | s = '{}e{}'.format(digits * 10**40, exponent - 40) |
---|
134 | n/a | self.check_strtod(s) |
---|
135 | n/a | digits *= 2 |
---|
136 | n/a | |
---|
137 | n/a | # Try numbers of the form n * 5**p2 * 10**(e - p5), p5 |
---|
138 | n/a | # >= 0, with n * 5**p5 < 10**20. |
---|
139 | n/a | digits, exponent = n, e |
---|
140 | n/a | while digits < 10**20: |
---|
141 | n/a | s = '{}e{}'.format(digits, exponent) |
---|
142 | n/a | self.check_strtod(s) |
---|
143 | n/a | # Same again, but with extra trailing zeros. |
---|
144 | n/a | s = '{}e{}'.format(digits * 10**40, exponent - 40) |
---|
145 | n/a | self.check_strtod(s) |
---|
146 | n/a | digits *= 5 |
---|
147 | n/a | exponent -= 1 |
---|
148 | n/a | |
---|
149 | n/a | def test_halfway_cases(self): |
---|
150 | n/a | # test halfway cases for the round-half-to-even rule |
---|
151 | n/a | for i in range(100 * TEST_SIZE): |
---|
152 | n/a | # bit pattern for a random finite positive (or +0.0) float |
---|
153 | n/a | bits = random.randrange(2047*2**52) |
---|
154 | n/a | |
---|
155 | n/a | # convert bit pattern to a number of the form m * 2**e |
---|
156 | n/a | e, m = divmod(bits, 2**52) |
---|
157 | n/a | if e: |
---|
158 | n/a | m, e = m + 2**52, e - 1 |
---|
159 | n/a | e -= 1074 |
---|
160 | n/a | |
---|
161 | n/a | # add 0.5 ulps |
---|
162 | n/a | m, e = 2*m + 1, e - 1 |
---|
163 | n/a | |
---|
164 | n/a | # convert to a decimal string |
---|
165 | n/a | if e >= 0: |
---|
166 | n/a | digits = m << e |
---|
167 | n/a | exponent = 0 |
---|
168 | n/a | else: |
---|
169 | n/a | # m * 2**e = (m * 5**-e) * 10**e |
---|
170 | n/a | digits = m * 5**-e |
---|
171 | n/a | exponent = e |
---|
172 | n/a | s = '{}e{}'.format(digits, exponent) |
---|
173 | n/a | self.check_strtod(s) |
---|
174 | n/a | |
---|
175 | n/a | def test_boundaries(self): |
---|
176 | n/a | # boundaries expressed as triples (n, e, u), where |
---|
177 | n/a | # n*10**e is an approximation to the boundary value and |
---|
178 | n/a | # u*10**e is 1ulp |
---|
179 | n/a | boundaries = [ |
---|
180 | n/a | (10000000000000000000, -19, 1110), # a power of 2 boundary (1.0) |
---|
181 | n/a | (17976931348623159077, 289, 1995), # overflow boundary (2.**1024) |
---|
182 | n/a | (22250738585072013831, -327, 4941), # normal/subnormal (2.**-1022) |
---|
183 | n/a | (0, -327, 4941), # zero |
---|
184 | n/a | ] |
---|
185 | n/a | for n, e, u in boundaries: |
---|
186 | n/a | for j in range(1000): |
---|
187 | n/a | digits = n + random.randrange(-3*u, 3*u) |
---|
188 | n/a | exponent = e |
---|
189 | n/a | s = '{}e{}'.format(digits, exponent) |
---|
190 | n/a | self.check_strtod(s) |
---|
191 | n/a | n *= 10 |
---|
192 | n/a | u *= 10 |
---|
193 | n/a | e -= 1 |
---|
194 | n/a | |
---|
195 | n/a | def test_underflow_boundary(self): |
---|
196 | n/a | # test values close to 2**-1075, the underflow boundary; similar |
---|
197 | n/a | # to boundary_tests, except that the random error doesn't scale |
---|
198 | n/a | # with n |
---|
199 | n/a | for exponent in range(-400, -320): |
---|
200 | n/a | base = 10**-exponent // 2**1075 |
---|
201 | n/a | for j in range(TEST_SIZE): |
---|
202 | n/a | digits = base + random.randrange(-1000, 1000) |
---|
203 | n/a | s = '{}e{}'.format(digits, exponent) |
---|
204 | n/a | self.check_strtod(s) |
---|
205 | n/a | |
---|
206 | n/a | def test_bigcomp(self): |
---|
207 | n/a | for ndigs in 5, 10, 14, 15, 16, 17, 18, 19, 20, 40, 41, 50: |
---|
208 | n/a | dig10 = 10**ndigs |
---|
209 | n/a | for i in range(10 * TEST_SIZE): |
---|
210 | n/a | digits = random.randrange(dig10) |
---|
211 | n/a | exponent = random.randrange(-400, 400) |
---|
212 | n/a | s = '{}e{}'.format(digits, exponent) |
---|
213 | n/a | self.check_strtod(s) |
---|
214 | n/a | |
---|
215 | n/a | def test_parsing(self): |
---|
216 | n/a | # make '0' more likely to be chosen than other digits |
---|
217 | n/a | digits = '000000123456789' |
---|
218 | n/a | signs = ('+', '-', '') |
---|
219 | n/a | |
---|
220 | n/a | # put together random short valid strings |
---|
221 | n/a | # \d*[.\d*]?e |
---|
222 | n/a | for i in range(1000): |
---|
223 | n/a | for j in range(TEST_SIZE): |
---|
224 | n/a | s = random.choice(signs) |
---|
225 | n/a | intpart_len = random.randrange(5) |
---|
226 | n/a | s += ''.join(random.choice(digits) for _ in range(intpart_len)) |
---|
227 | n/a | if random.choice([True, False]): |
---|
228 | n/a | s += '.' |
---|
229 | n/a | fracpart_len = random.randrange(5) |
---|
230 | n/a | s += ''.join(random.choice(digits) |
---|
231 | n/a | for _ in range(fracpart_len)) |
---|
232 | n/a | else: |
---|
233 | n/a | fracpart_len = 0 |
---|
234 | n/a | if random.choice([True, False]): |
---|
235 | n/a | s += random.choice(['e', 'E']) |
---|
236 | n/a | s += random.choice(signs) |
---|
237 | n/a | exponent_len = random.randrange(1, 4) |
---|
238 | n/a | s += ''.join(random.choice(digits) |
---|
239 | n/a | for _ in range(exponent_len)) |
---|
240 | n/a | |
---|
241 | n/a | if intpart_len + fracpart_len: |
---|
242 | n/a | self.check_strtod(s) |
---|
243 | n/a | else: |
---|
244 | n/a | try: |
---|
245 | n/a | float(s) |
---|
246 | n/a | except ValueError: |
---|
247 | n/a | pass |
---|
248 | n/a | else: |
---|
249 | n/a | assert False, "expected ValueError" |
---|
250 | n/a | |
---|
251 | n/a | @test.support.bigmemtest(size=test.support._2G+10, memuse=3, dry_run=False) |
---|
252 | n/a | def test_oversized_digit_strings(self, maxsize): |
---|
253 | n/a | # Input string whose length doesn't fit in an INT. |
---|
254 | n/a | s = "1." + "1" * maxsize |
---|
255 | n/a | with self.assertRaises(ValueError): |
---|
256 | n/a | float(s) |
---|
257 | n/a | del s |
---|
258 | n/a | |
---|
259 | n/a | s = "0." + "0" * maxsize + "1" |
---|
260 | n/a | with self.assertRaises(ValueError): |
---|
261 | n/a | float(s) |
---|
262 | n/a | del s |
---|
263 | n/a | |
---|
264 | n/a | def test_large_exponents(self): |
---|
265 | n/a | # Verify that the clipping of the exponent in strtod doesn't affect the |
---|
266 | n/a | # output values. |
---|
267 | n/a | def positive_exp(n): |
---|
268 | n/a | """ Long string with value 1.0 and exponent n""" |
---|
269 | n/a | return '0.{}1e+{}'.format('0'*(n-1), n) |
---|
270 | n/a | |
---|
271 | n/a | def negative_exp(n): |
---|
272 | n/a | """ Long string with value 1.0 and exponent -n""" |
---|
273 | n/a | return '1{}e-{}'.format('0'*n, n) |
---|
274 | n/a | |
---|
275 | n/a | self.assertEqual(float(positive_exp(10000)), 1.0) |
---|
276 | n/a | self.assertEqual(float(positive_exp(20000)), 1.0) |
---|
277 | n/a | self.assertEqual(float(positive_exp(30000)), 1.0) |
---|
278 | n/a | self.assertEqual(float(negative_exp(10000)), 1.0) |
---|
279 | n/a | self.assertEqual(float(negative_exp(20000)), 1.0) |
---|
280 | n/a | self.assertEqual(float(negative_exp(30000)), 1.0) |
---|
281 | n/a | |
---|
282 | n/a | def test_particular(self): |
---|
283 | n/a | # inputs that produced crashes or incorrectly rounded results with |
---|
284 | n/a | # previous versions of dtoa.c, for various reasons |
---|
285 | n/a | test_strings = [ |
---|
286 | n/a | # issue 7632 bug 1, originally reported failing case |
---|
287 | n/a | '2183167012312112312312.23538020374420446192e-370', |
---|
288 | n/a | # 5 instances of issue 7632 bug 2 |
---|
289 | n/a | '12579816049008305546974391768996369464963024663104e-357', |
---|
290 | n/a | '17489628565202117263145367596028389348922981857013e-357', |
---|
291 | n/a | '18487398785991994634182916638542680759613590482273e-357', |
---|
292 | n/a | '32002864200581033134358724675198044527469366773928e-358', |
---|
293 | n/a | '94393431193180696942841837085033647913224148539854e-358', |
---|
294 | n/a | '73608278998966969345824653500136787876436005957953e-358', |
---|
295 | n/a | '64774478836417299491718435234611299336288082136054e-358', |
---|
296 | n/a | '13704940134126574534878641876947980878824688451169e-357', |
---|
297 | n/a | '46697445774047060960624497964425416610480524760471e-358', |
---|
298 | n/a | # failing case for bug introduced by METD in r77451 (attempted |
---|
299 | n/a | # fix for issue 7632, bug 2), and fixed in r77482. |
---|
300 | n/a | '28639097178261763178489759107321392745108491825303e-311', |
---|
301 | n/a | # two numbers demonstrating a flaw in the bigcomp 'dig == 0' |
---|
302 | n/a | # correction block (issue 7632, bug 3) |
---|
303 | n/a | '1.00000000000000001e44', |
---|
304 | n/a | '1.0000000000000000100000000000000000000001e44', |
---|
305 | n/a | # dtoa.c bug for numbers just smaller than a power of 2 (issue |
---|
306 | n/a | # 7632, bug 4) |
---|
307 | n/a | '99999999999999994487665465554760717039532578546e-47', |
---|
308 | n/a | # failing case for off-by-one error introduced by METD in |
---|
309 | n/a | # r77483 (dtoa.c cleanup), fixed in r77490 |
---|
310 | n/a | '965437176333654931799035513671997118345570045914469' #... |
---|
311 | n/a | '6213413350821416312194420007991306908470147322020121018368e0', |
---|
312 | n/a | # incorrect lsb detection for round-half-to-even when |
---|
313 | n/a | # bc->scale != 0 (issue 7632, bug 6). |
---|
314 | n/a | '104308485241983990666713401708072175773165034278685' #... |
---|
315 | n/a | '682646111762292409330928739751702404658197872319129' #... |
---|
316 | n/a | '036519947435319418387839758990478549477777586673075' #... |
---|
317 | n/a | '945844895981012024387992135617064532141489278815239' #... |
---|
318 | n/a | '849108105951619997829153633535314849999674266169258' #... |
---|
319 | n/a | '928940692239684771590065027025835804863585454872499' #... |
---|
320 | n/a | '320500023126142553932654370362024104462255244034053' #... |
---|
321 | n/a | '203998964360882487378334860197725139151265590832887' #... |
---|
322 | n/a | '433736189468858614521708567646743455601905935595381' #... |
---|
323 | n/a | '852723723645799866672558576993978025033590728687206' #... |
---|
324 | n/a | '296379801363024094048327273913079612469982585674824' #... |
---|
325 | n/a | '156000783167963081616214710691759864332339239688734' #... |
---|
326 | n/a | '656548790656486646106983450809073750535624894296242' #... |
---|
327 | n/a | '072010195710276073042036425579852459556183541199012' #... |
---|
328 | n/a | '652571123898996574563824424330960027873516082763671875e-1075', |
---|
329 | n/a | # demonstration that original fix for issue 7632 bug 1 was |
---|
330 | n/a | # buggy; the exit condition was too strong |
---|
331 | n/a | '247032822920623295e-341', |
---|
332 | n/a | # demonstrate similar problem to issue 7632 bug1: crash |
---|
333 | n/a | # with 'oversized quotient in quorem' message. |
---|
334 | n/a | '99037485700245683102805043437346965248029601286431e-373', |
---|
335 | n/a | '99617639833743863161109961162881027406769510558457e-373', |
---|
336 | n/a | '98852915025769345295749278351563179840130565591462e-372', |
---|
337 | n/a | '99059944827693569659153042769690930905148015876788e-373', |
---|
338 | n/a | '98914979205069368270421829889078356254059760327101e-372', |
---|
339 | n/a | # issue 7632 bug 5: the following 2 strings convert differently |
---|
340 | n/a | '1000000000000000000000000000000000000000e-16', |
---|
341 | n/a | '10000000000000000000000000000000000000000e-17', |
---|
342 | n/a | # issue 7632 bug 7 |
---|
343 | n/a | '991633793189150720000000000000000000000000000000000000000e-33', |
---|
344 | n/a | # And another, similar, failing halfway case |
---|
345 | n/a | '4106250198039490000000000000000000000000000000000000000e-38', |
---|
346 | n/a | # issue 7632 bug 8: the following produced 10.0 |
---|
347 | n/a | '10.900000000000000012345678912345678912345', |
---|
348 | n/a | |
---|
349 | n/a | # two humongous values from issue 7743 |
---|
350 | n/a | '116512874940594195638617907092569881519034793229385' #... |
---|
351 | n/a | '228569165191541890846564669771714896916084883987920' #... |
---|
352 | n/a | '473321268100296857636200926065340769682863349205363' #... |
---|
353 | n/a | '349247637660671783209907949273683040397979984107806' #... |
---|
354 | n/a | '461822693332712828397617946036239581632976585100633' #... |
---|
355 | n/a | '520260770761060725403904123144384571612073732754774' #... |
---|
356 | n/a | '588211944406465572591022081973828448927338602556287' #... |
---|
357 | n/a | '851831745419397433012491884869454462440536895047499' #... |
---|
358 | n/a | '436551974649731917170099387762871020403582994193439' #... |
---|
359 | n/a | '761933412166821484015883631622539314203799034497982' #... |
---|
360 | n/a | '130038741741727907429575673302461380386596501187482' #... |
---|
361 | n/a | '006257527709842179336488381672818798450229339123527' #... |
---|
362 | n/a | '858844448336815912020452294624916993546388956561522' #... |
---|
363 | n/a | '161875352572590420823607478788399460162228308693742' #... |
---|
364 | n/a | '05287663441403533948204085390898399055004119873046875e-1075', |
---|
365 | n/a | |
---|
366 | n/a | '525440653352955266109661060358202819561258984964913' #... |
---|
367 | n/a | '892256527849758956045218257059713765874251436193619' #... |
---|
368 | n/a | '443248205998870001633865657517447355992225852945912' #... |
---|
369 | n/a | '016668660000210283807209850662224417504752264995360' #... |
---|
370 | n/a | '631512007753855801075373057632157738752800840302596' #... |
---|
371 | n/a | '237050247910530538250008682272783660778181628040733' #... |
---|
372 | n/a | '653121492436408812668023478001208529190359254322340' #... |
---|
373 | n/a | '397575185248844788515410722958784640926528544043090' #... |
---|
374 | n/a | '115352513640884988017342469275006999104519620946430' #... |
---|
375 | n/a | '818767147966495485406577703972687838176778993472989' #... |
---|
376 | n/a | '561959000047036638938396333146685137903018376496408' #... |
---|
377 | n/a | '319705333868476925297317136513970189073693314710318' #... |
---|
378 | n/a | '991252811050501448326875232850600451776091303043715' #... |
---|
379 | n/a | '157191292827614046876950225714743118291034780466325' #... |
---|
380 | n/a | '085141343734564915193426994587206432697337118211527' #... |
---|
381 | n/a | '278968731294639353354774788602467795167875117481660' #... |
---|
382 | n/a | '4738791256853675690543663283782215866825e-1180', |
---|
383 | n/a | |
---|
384 | n/a | # exercise exit conditions in bigcomp comparison loop |
---|
385 | n/a | '2602129298404963083833853479113577253105939995688e2', |
---|
386 | n/a | '260212929840496308383385347911357725310593999568896e0', |
---|
387 | n/a | '26021292984049630838338534791135772531059399956889601e-2', |
---|
388 | n/a | '260212929840496308383385347911357725310593999568895e0', |
---|
389 | n/a | '260212929840496308383385347911357725310593999568897e0', |
---|
390 | n/a | '260212929840496308383385347911357725310593999568996e0', |
---|
391 | n/a | '260212929840496308383385347911357725310593999568866e0', |
---|
392 | n/a | # 2**53 |
---|
393 | n/a | '9007199254740992.00', |
---|
394 | n/a | # 2**1024 - 2**970: exact overflow boundary. All values |
---|
395 | n/a | # smaller than this should round to something finite; any value |
---|
396 | n/a | # greater than or equal to this one overflows. |
---|
397 | n/a | '179769313486231580793728971405303415079934132710037' #... |
---|
398 | n/a | '826936173778980444968292764750946649017977587207096' #... |
---|
399 | n/a | '330286416692887910946555547851940402630657488671505' #... |
---|
400 | n/a | '820681908902000708383676273854845817711531764475730' #... |
---|
401 | n/a | '270069855571366959622842914819860834936475292719074' #... |
---|
402 | n/a | '168444365510704342711559699508093042880177904174497792', |
---|
403 | n/a | # 2**1024 - 2**970 - tiny |
---|
404 | n/a | '179769313486231580793728971405303415079934132710037' #... |
---|
405 | n/a | '826936173778980444968292764750946649017977587207096' #... |
---|
406 | n/a | '330286416692887910946555547851940402630657488671505' #... |
---|
407 | n/a | '820681908902000708383676273854845817711531764475730' #... |
---|
408 | n/a | '270069855571366959622842914819860834936475292719074' #... |
---|
409 | n/a | '168444365510704342711559699508093042880177904174497791.999', |
---|
410 | n/a | # 2**1024 - 2**970 + tiny |
---|
411 | n/a | '179769313486231580793728971405303415079934132710037' #... |
---|
412 | n/a | '826936173778980444968292764750946649017977587207096' #... |
---|
413 | n/a | '330286416692887910946555547851940402630657488671505' #... |
---|
414 | n/a | '820681908902000708383676273854845817711531764475730' #... |
---|
415 | n/a | '270069855571366959622842914819860834936475292719074' #... |
---|
416 | n/a | '168444365510704342711559699508093042880177904174497792.001', |
---|
417 | n/a | # 1 - 2**-54, +-tiny |
---|
418 | n/a | '999999999999999944488848768742172978818416595458984375e-54', |
---|
419 | n/a | '9999999999999999444888487687421729788184165954589843749999999e-54', |
---|
420 | n/a | '9999999999999999444888487687421729788184165954589843750000001e-54', |
---|
421 | n/a | # Value found by Rick Regan that gives a result of 2**-968 |
---|
422 | n/a | # under Gay's dtoa.c (as of Nov 04, 2010); since fixed. |
---|
423 | n/a | # (Fixed some time ago in Python's dtoa.c.) |
---|
424 | n/a | '0.0000000000000000000000000000000000000000100000000' #... |
---|
425 | n/a | '000000000576129113423785429971690421191214034235435' #... |
---|
426 | n/a | '087147763178149762956868991692289869941246658073194' #... |
---|
427 | n/a | '51982237978882039897143840789794921875', |
---|
428 | n/a | ] |
---|
429 | n/a | for s in test_strings: |
---|
430 | n/a | self.check_strtod(s) |
---|
431 | n/a | |
---|
432 | n/a | if __name__ == "__main__": |
---|
433 | n/a | unittest.main() |
---|