Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_float.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 17891566a478 |
| children | 70e115c34f97 |
| rev | line source |
|---|---|
| 34972 | 1 |
| 2 import unittest, struct | |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
3 import os |
| 34972 | 4 from test import test_support |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
5 import math |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
6 from math import isinf, isnan, copysign, ldexp |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
7 import operator |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
8 import random |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
9 import fractions |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
10 import sys |
|
58278
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
11 import re |
| 34972 | 12 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
13 INF = float("inf") |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
14 NAN = float("nan") |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
15 |
|
58001
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
16 # decorator for skipping tests on non-IEEE 754 platforms |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
17 requires_IEEE_754 = unittest.skipUnless( |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
18 float.__getformat__("double").startswith("IEEE"), |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
19 "test requires IEEE 754 doubles") |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
20 |
|
53619
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
21 #locate file with float format test values |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
22 test_dir = os.path.dirname(__file__) or os.curdir |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
23 format_testfile = os.path.join(test_dir, 'formatfloat_testcases.txt') |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
24 |
|
58278
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
25 finite_decimal_parser = re.compile(r""" # A numeric string consists of: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
26 (?P<sign>[-+])? # an optional sign, followed by |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
27 (?=\d|\.\d) # a number with at least one digit |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
28 (?P<int>\d*) # having a (possibly empty) integer part |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
29 (?:\.(?P<frac>\d*))? # followed by an optional fractional part |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
30 (?:E(?P<exp>[-+]?\d+))? # and an optional exponent |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
31 \Z |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
32 """, re.VERBOSE | re.IGNORECASE | re.UNICODE).match |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
33 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
34 # Pure Python version of correctly rounded string->float conversion. |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
35 # Avoids any use of floating-point by returning the result as a hex string. |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
36 def strtod(s, mant_dig=53, min_exp = -1021, max_exp = 1024): |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
37 """Convert a finite decimal string to a hex string representing an |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
38 IEEE 754 binary64 float. Return 'inf' or '-inf' on overflow. |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
39 This function makes no use of floating-point arithmetic at any |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
40 stage.""" |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
41 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
42 # parse string into a pair of integers 'a' and 'b' such that |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
43 # abs(decimal value) = a/b, and a boolean 'negative'. |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
44 m = finite_decimal_parser(s) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
45 if m is None: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
46 raise ValueError('invalid numeric string') |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
47 fraction = m.group('frac') or '' |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
48 intpart = int(m.group('int') + fraction) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
49 exp = int(m.group('exp') or '0') - len(fraction) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
50 negative = m.group('sign') == '-' |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
51 a, b = intpart*10**max(exp, 0), 10**max(0, -exp) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
52 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
53 # quick return for zeros |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
54 if not a: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
55 return '-0x0.0p+0' if negative else '0x0.0p+0' |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
56 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
57 # compute exponent e for result; may be one too small in the case |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
58 # that the rounded value of a/b lies in a different binade from a/b |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
59 d = a.bit_length() - b.bit_length() |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
60 d += (a >> d if d >= 0 else a << -d) >= b |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
61 e = max(d, min_exp) - mant_dig |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
62 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
63 # approximate a/b by number of the form q * 2**e; adjust e if necessary |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
64 a, b = a << max(-e, 0), b << max(e, 0) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
65 q, r = divmod(a, b) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
66 if 2*r > b or 2*r == b and q & 1: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
67 q += 1 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
68 if q.bit_length() == mant_dig+1: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
69 q //= 2 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
70 e += 1 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
71 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
72 # double check that (q, e) has the right form |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
73 assert q.bit_length() <= mant_dig and e >= min_exp - mant_dig |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
74 assert q.bit_length() == mant_dig or e == min_exp - mant_dig |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
75 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
76 # check for overflow and underflow |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
77 if e + q.bit_length() > max_exp: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
78 return '-inf' if negative else 'inf' |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
79 if not q: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
80 return '-0x0.0p+0' if negative else '0x0.0p+0' |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
81 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
82 # for hex representation, shift so # bits after point is a multiple of 4 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
83 hexdigs = 1 + (mant_dig-2)//4 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
84 shift = 3 - (mant_dig-2)%4 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
85 q, e = q << shift, e - shift |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
86 return '{}0x{:x}.{:0{}x}p{:+d}'.format( |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
87 '-' if negative else '', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
88 q // 16**hexdigs, |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
89 q % 16**hexdigs, |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
90 hexdigs, |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
91 e + 4*hexdigs) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
92 |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
93 class GeneralFloatCases(unittest.TestCase): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
94 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
95 def test_float(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
96 self.assertEqual(float(3.14), 3.14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
97 self.assertEqual(float(314), 314.0) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
98 self.assertEqual(float(314L), 314.0) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
99 self.assertEqual(float(" 3.14 "), 3.14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
100 self.assertRaises(ValueError, float, " 0x3.1 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
101 self.assertRaises(ValueError, float, " -0x3.p-1 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
102 self.assertRaises(ValueError, float, " +0x3.p-1 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
103 self.assertRaises(ValueError, float, "++3.14") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
104 self.assertRaises(ValueError, float, "+-3.14") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
105 self.assertRaises(ValueError, float, "-+3.14") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
106 self.assertRaises(ValueError, float, "--3.14") |
|
49054
e27cf7ee2968
#3796: A test class was not run in test_float.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48816
diff
changeset
|
107 if test_support.have_unicode: |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
108 self.assertEqual(float(unicode(" 3.14 ")), 3.14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
109 self.assertEqual(float(unicode(" \u0663.\u0661\u0664 ",'raw-unicode-escape')), 3.14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
110 |
|
56913
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
111 # extra long strings should no longer be a problem |
|
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
112 # (in 2.6, long unicode inputs to float raised ValueError) |
|
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
113 float('.' + '1'*1000) |
|
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
114 float(unicode('.' + '1'*1000)) |
|
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
115 |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
116 @test_support.run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE') |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
117 def test_float_with_comma(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
118 # set locale to something that doesn't use '.' for the decimal point |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
119 # float must not accept the locale specific decimal point but |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
120 # it still has to accept the normal python syntac |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
121 import locale |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
122 if not locale.localeconv()['decimal_point'] == ',': |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
123 return |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
124 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
125 self.assertEqual(float(" 3.14 "), 3.14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
126 self.assertEqual(float("+3.14 "), 3.14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
127 self.assertEqual(float("-3.14 "), -3.14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
128 self.assertEqual(float(".14 "), .14) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
129 self.assertEqual(float("3. "), 3.0) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
130 self.assertEqual(float("3.e3 "), 3000.0) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
131 self.assertEqual(float("3.2e3 "), 3200.0) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
132 self.assertEqual(float("2.5e-1 "), 0.25) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
133 self.assertEqual(float("5e-1"), 0.5) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
134 self.assertRaises(ValueError, float, " 3,14 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
135 self.assertRaises(ValueError, float, " +3,14 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
136 self.assertRaises(ValueError, float, " -3,14 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
137 self.assertRaises(ValueError, float, " 0x3.1 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
138 self.assertRaises(ValueError, float, " -0x3.p-1 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
139 self.assertRaises(ValueError, float, " +0x3.p-1 ") |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
140 self.assertEqual(float(" 25.e-1 "), 2.5) |
|
49061
fdc0948c95cf
fix missing module
Benjamin Peterson <benjamin@python.org>
parents:
49054
diff
changeset
|
141 self.assertEqual(test_support.fcmp(float(" .25e-1 "), .025), 0) |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
142 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
143 def test_floatconversion(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
144 # Make sure that calls to __float__() work properly |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
145 class Foo0: |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
146 def __float__(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
147 return 42. |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
148 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
149 class Foo1(object): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
150 def __float__(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
151 return 42. |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
152 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
153 class Foo2(float): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
154 def __float__(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
155 return 42. |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
156 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
157 class Foo3(float): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
158 def __new__(cls, value=0.): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
159 return float.__new__(cls, 2*value) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
160 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
161 def __float__(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
162 return self |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
163 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
164 class Foo4(float): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
165 def __float__(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
166 return 42 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
167 |
|
53162
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
168 # Issue 5759: __float__ not called on str subclasses (though it is on |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
169 # unicode subclasses). |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
170 class FooStr(str): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
171 def __float__(self): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
172 return float(str(self)) + 1 |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
173 |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
174 class FooUnicode(unicode): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
175 def __float__(self): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
176 return float(unicode(self)) + 1 |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
177 |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
178 self.assertAlmostEqual(float(Foo0()), 42.) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
179 self.assertAlmostEqual(float(Foo1()), 42.) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
180 self.assertAlmostEqual(float(Foo2()), 42.) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
181 self.assertAlmostEqual(float(Foo3(21)), 42.) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
182 self.assertRaises(TypeError, float, Foo4(42)) |
|
53162
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
183 self.assertAlmostEqual(float(FooUnicode('8')), 9.) |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
184 self.assertAlmostEqual(float(FooStr('8')), 9.) |
|
46649
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
185 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
186 def test_floatasratio(self): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
187 for f, ratio in [ |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
188 (0.875, (7, 8)), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
189 (-0.875, (-7, 8)), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
190 (0.0, (0, 1)), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
191 (11.5, (23, 2)), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
192 ]: |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
193 self.assertEqual(f.as_integer_ratio(), ratio) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
194 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
195 for i in range(10000): |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
196 f = random.random() |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
197 f *= 10 ** random.randint(-100, 100) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
198 n, d = f.as_integer_ratio() |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
199 self.assertEqual(float(n).__truediv__(d), f) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
200 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
201 R = fractions.Fraction |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
202 self.assertEqual(R(0, 1), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
203 R(*float(0.0).as_integer_ratio())) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
204 self.assertEqual(R(5, 2), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
205 R(*float(2.5).as_integer_ratio())) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
206 self.assertEqual(R(1, 2), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
207 R(*float(0.5).as_integer_ratio())) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
208 self.assertEqual(R(4728779608739021, 2251799813685248), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
209 R(*float(2.1).as_integer_ratio())) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
210 self.assertEqual(R(-4728779608739021, 2251799813685248), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
211 R(*float(-2.1).as_integer_ratio())) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
212 self.assertEqual(R(-2100, 1), |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
213 R(*float(-2100.0).as_integer_ratio())) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
214 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
215 self.assertRaises(OverflowError, float('inf').as_integer_ratio) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
216 self.assertRaises(OverflowError, float('-inf').as_integer_ratio) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
217 self.assertRaises(ValueError, float('nan').as_integer_ratio) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
218 |
|
58001
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
219 def assertEqualAndEqualSign(self, a, b): |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
220 # fail unless a == b and a and b have the same sign bit; |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
221 # the only difference from assertEqual is that this test |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
222 # distingishes -0.0 and 0.0. |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
223 self.assertEqual((a, copysign(1.0, a)), (b, copysign(1.0, b))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
224 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
225 @requires_IEEE_754 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
226 def test_float_pow(self): |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
227 # test builtin pow and ** operator for IEEE 754 special cases. |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
228 # Special cases taken from section F.9.4.4 of the C99 specification |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
229 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
230 for pow_op in pow, operator.pow: |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
231 # x**NAN is NAN for any x except 1 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
232 self.assertTrue(isnan(pow_op(-INF, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
233 self.assertTrue(isnan(pow_op(-2.0, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
234 self.assertTrue(isnan(pow_op(-1.0, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
235 self.assertTrue(isnan(pow_op(-0.5, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
236 self.assertTrue(isnan(pow_op(-0.0, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
237 self.assertTrue(isnan(pow_op(0.0, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
238 self.assertTrue(isnan(pow_op(0.5, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
239 self.assertTrue(isnan(pow_op(2.0, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
240 self.assertTrue(isnan(pow_op(INF, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
241 self.assertTrue(isnan(pow_op(NAN, NAN))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
242 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
243 # NAN**y is NAN for any y except +-0 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
244 self.assertTrue(isnan(pow_op(NAN, -INF))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
245 self.assertTrue(isnan(pow_op(NAN, -2.0))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
246 self.assertTrue(isnan(pow_op(NAN, -1.0))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
247 self.assertTrue(isnan(pow_op(NAN, -0.5))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
248 self.assertTrue(isnan(pow_op(NAN, 0.5))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
249 self.assertTrue(isnan(pow_op(NAN, 1.0))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
250 self.assertTrue(isnan(pow_op(NAN, 2.0))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
251 self.assertTrue(isnan(pow_op(NAN, INF))) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
252 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
253 # (+-0)**y raises ZeroDivisionError for y a negative odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
254 self.assertRaises(ZeroDivisionError, pow_op, -0.0, -1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
255 self.assertRaises(ZeroDivisionError, pow_op, 0.0, -1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
256 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
257 # (+-0)**y raises ZeroDivisionError for y finite and negative |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
258 # but not an odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
259 self.assertRaises(ZeroDivisionError, pow_op, -0.0, -2.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
260 self.assertRaises(ZeroDivisionError, pow_op, -0.0, -0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
261 self.assertRaises(ZeroDivisionError, pow_op, 0.0, -2.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
262 self.assertRaises(ZeroDivisionError, pow_op, 0.0, -0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
263 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
264 # (+-0)**y is +-0 for y a positive odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
265 self.assertEqualAndEqualSign(pow_op(-0.0, 1.0), -0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
266 self.assertEqualAndEqualSign(pow_op(0.0, 1.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
267 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
268 # (+-0)**y is 0 for y finite and positive but not an odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
269 self.assertEqualAndEqualSign(pow_op(-0.0, 0.5), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
270 self.assertEqualAndEqualSign(pow_op(-0.0, 2.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
271 self.assertEqualAndEqualSign(pow_op(0.0, 0.5), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
272 self.assertEqualAndEqualSign(pow_op(0.0, 2.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
273 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
274 # (-1)**+-inf is 1 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
275 self.assertEqualAndEqualSign(pow_op(-1.0, -INF), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
276 self.assertEqualAndEqualSign(pow_op(-1.0, INF), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
277 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
278 # 1**y is 1 for any y, even if y is an infinity or nan |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
279 self.assertEqualAndEqualSign(pow_op(1.0, -INF), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
280 self.assertEqualAndEqualSign(pow_op(1.0, -2.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
281 self.assertEqualAndEqualSign(pow_op(1.0, -1.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
282 self.assertEqualAndEqualSign(pow_op(1.0, -0.5), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
283 self.assertEqualAndEqualSign(pow_op(1.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
284 self.assertEqualAndEqualSign(pow_op(1.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
285 self.assertEqualAndEqualSign(pow_op(1.0, 0.5), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
286 self.assertEqualAndEqualSign(pow_op(1.0, 1.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
287 self.assertEqualAndEqualSign(pow_op(1.0, 2.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
288 self.assertEqualAndEqualSign(pow_op(1.0, INF), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
289 self.assertEqualAndEqualSign(pow_op(1.0, NAN), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
290 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
291 # x**+-0 is 1 for any x, even if x is a zero, infinity, or nan |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
292 self.assertEqualAndEqualSign(pow_op(-INF, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
293 self.assertEqualAndEqualSign(pow_op(-2.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
294 self.assertEqualAndEqualSign(pow_op(-1.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
295 self.assertEqualAndEqualSign(pow_op(-0.5, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
296 self.assertEqualAndEqualSign(pow_op(-0.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
297 self.assertEqualAndEqualSign(pow_op(0.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
298 self.assertEqualAndEqualSign(pow_op(0.5, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
299 self.assertEqualAndEqualSign(pow_op(1.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
300 self.assertEqualAndEqualSign(pow_op(2.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
301 self.assertEqualAndEqualSign(pow_op(INF, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
302 self.assertEqualAndEqualSign(pow_op(NAN, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
303 self.assertEqualAndEqualSign(pow_op(-INF, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
304 self.assertEqualAndEqualSign(pow_op(-2.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
305 self.assertEqualAndEqualSign(pow_op(-1.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
306 self.assertEqualAndEqualSign(pow_op(-0.5, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
307 self.assertEqualAndEqualSign(pow_op(-0.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
308 self.assertEqualAndEqualSign(pow_op(0.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
309 self.assertEqualAndEqualSign(pow_op(0.5, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
310 self.assertEqualAndEqualSign(pow_op(1.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
311 self.assertEqualAndEqualSign(pow_op(2.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
312 self.assertEqualAndEqualSign(pow_op(INF, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
313 self.assertEqualAndEqualSign(pow_op(NAN, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
314 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
315 # x**y raises ValueError for finite negative x and non-integral y |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
316 self.assertRaises(ValueError, pow_op, -2.0, -0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
317 self.assertRaises(ValueError, pow_op, -2.0, 0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
318 self.assertRaises(ValueError, pow_op, -1.0, -0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
319 self.assertRaises(ValueError, pow_op, -1.0, 0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
320 self.assertRaises(ValueError, pow_op, -0.5, -0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
321 self.assertRaises(ValueError, pow_op, -0.5, 0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
322 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
323 # x**-INF is INF for abs(x) < 1 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
324 self.assertEqualAndEqualSign(pow_op(-0.5, -INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
325 self.assertEqualAndEqualSign(pow_op(-0.0, -INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
326 self.assertEqualAndEqualSign(pow_op(0.0, -INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
327 self.assertEqualAndEqualSign(pow_op(0.5, -INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
328 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
329 # x**-INF is 0 for abs(x) > 1 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
330 self.assertEqualAndEqualSign(pow_op(-INF, -INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
331 self.assertEqualAndEqualSign(pow_op(-2.0, -INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
332 self.assertEqualAndEqualSign(pow_op(2.0, -INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
333 self.assertEqualAndEqualSign(pow_op(INF, -INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
334 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
335 # x**INF is 0 for abs(x) < 1 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
336 self.assertEqualAndEqualSign(pow_op(-0.5, INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
337 self.assertEqualAndEqualSign(pow_op(-0.0, INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
338 self.assertEqualAndEqualSign(pow_op(0.0, INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
339 self.assertEqualAndEqualSign(pow_op(0.5, INF), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
340 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
341 # x**INF is INF for abs(x) > 1 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
342 self.assertEqualAndEqualSign(pow_op(-INF, INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
343 self.assertEqualAndEqualSign(pow_op(-2.0, INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
344 self.assertEqualAndEqualSign(pow_op(2.0, INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
345 self.assertEqualAndEqualSign(pow_op(INF, INF), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
346 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
347 # (-INF)**y is -0.0 for y a negative odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
348 self.assertEqualAndEqualSign(pow_op(-INF, -1.0), -0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
349 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
350 # (-INF)**y is 0.0 for y negative but not an odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
351 self.assertEqualAndEqualSign(pow_op(-INF, -0.5), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
352 self.assertEqualAndEqualSign(pow_op(-INF, -2.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
353 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
354 # (-INF)**y is -INF for y a positive odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
355 self.assertEqualAndEqualSign(pow_op(-INF, 1.0), -INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
356 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
357 # (-INF)**y is INF for y positive but not an odd integer |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
358 self.assertEqualAndEqualSign(pow_op(-INF, 0.5), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
359 self.assertEqualAndEqualSign(pow_op(-INF, 2.0), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
360 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
361 # INF**y is INF for y positive |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
362 self.assertEqualAndEqualSign(pow_op(INF, 0.5), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
363 self.assertEqualAndEqualSign(pow_op(INF, 1.0), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
364 self.assertEqualAndEqualSign(pow_op(INF, 2.0), INF) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
365 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
366 # INF**y is 0.0 for y negative |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
367 self.assertEqualAndEqualSign(pow_op(INF, -2.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
368 self.assertEqualAndEqualSign(pow_op(INF, -1.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
369 self.assertEqualAndEqualSign(pow_op(INF, -0.5), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
370 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
371 # basic checks not covered by the special cases above |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
372 self.assertEqualAndEqualSign(pow_op(-2.0, -2.0), 0.25) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
373 self.assertEqualAndEqualSign(pow_op(-2.0, -1.0), -0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
374 self.assertEqualAndEqualSign(pow_op(-2.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
375 self.assertEqualAndEqualSign(pow_op(-2.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
376 self.assertEqualAndEqualSign(pow_op(-2.0, 1.0), -2.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
377 self.assertEqualAndEqualSign(pow_op(-2.0, 2.0), 4.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
378 self.assertEqualAndEqualSign(pow_op(-1.0, -2.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
379 self.assertEqualAndEqualSign(pow_op(-1.0, -1.0), -1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
380 self.assertEqualAndEqualSign(pow_op(-1.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
381 self.assertEqualAndEqualSign(pow_op(-1.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
382 self.assertEqualAndEqualSign(pow_op(-1.0, 1.0), -1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
383 self.assertEqualAndEqualSign(pow_op(-1.0, 2.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
384 self.assertEqualAndEqualSign(pow_op(2.0, -2.0), 0.25) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
385 self.assertEqualAndEqualSign(pow_op(2.0, -1.0), 0.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
386 self.assertEqualAndEqualSign(pow_op(2.0, -0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
387 self.assertEqualAndEqualSign(pow_op(2.0, 0.0), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
388 self.assertEqualAndEqualSign(pow_op(2.0, 1.0), 2.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
389 self.assertEqualAndEqualSign(pow_op(2.0, 2.0), 4.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
390 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
391 # 1 ** large and -1 ** large; some libms apparently |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
392 # have problems with these |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
393 self.assertEqualAndEqualSign(pow_op(1.0, -1e100), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
394 self.assertEqualAndEqualSign(pow_op(1.0, 1e100), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
395 self.assertEqualAndEqualSign(pow_op(-1.0, -1e100), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
396 self.assertEqualAndEqualSign(pow_op(-1.0, 1e100), 1.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
397 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
398 # check sign for results that underflow to 0 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
399 self.assertEqualAndEqualSign(pow_op(-2.0, -2000.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
400 self.assertRaises(ValueError, pow_op, -2.0, -2000.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
401 self.assertEqualAndEqualSign(pow_op(-2.0, -2001.0), -0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
402 self.assertEqualAndEqualSign(pow_op(2.0, -2000.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
403 self.assertEqualAndEqualSign(pow_op(2.0, -2000.5), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
404 self.assertEqualAndEqualSign(pow_op(2.0, -2001.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
405 self.assertEqualAndEqualSign(pow_op(-0.5, 2000.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
406 self.assertRaises(ValueError, pow_op, -0.5, 2000.5) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
407 self.assertEqualAndEqualSign(pow_op(-0.5, 2001.0), -0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
408 self.assertEqualAndEqualSign(pow_op(0.5, 2000.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
409 self.assertEqualAndEqualSign(pow_op(0.5, 2000.5), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
410 self.assertEqualAndEqualSign(pow_op(0.5, 2001.0), 0.0) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
411 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
412 # check we don't raise an exception for subnormal results, |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
413 # and validate signs. Tests currently disabled, since |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
414 # they fail on systems where a subnormal result from pow |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
415 # is flushed to zero (e.g. Debian/ia64.) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
416 #self.assertTrue(0.0 < pow_op(0.5, 1048) < 1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
417 #self.assertTrue(0.0 < pow_op(-0.5, 1048) < 1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
418 #self.assertTrue(0.0 < pow_op(0.5, 1047) < 1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
419 #self.assertTrue(0.0 > pow_op(-0.5, 1047) > -1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
420 #self.assertTrue(0.0 < pow_op(2.0, -1048) < 1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
421 #self.assertTrue(0.0 < pow_op(-2.0, -1048) < 1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
422 #self.assertTrue(0.0 < pow_op(2.0, -1047) < 1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
423 #self.assertTrue(0.0 > pow_op(-2.0, -1047) > -1e-315) |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
424 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
425 |
| 34972 | 426 class FormatFunctionsTestCase(unittest.TestCase): |
| 427 | |
| 428 def setUp(self): | |
| 429 self.save_formats = {'double':float.__getformat__('double'), | |
| 430 'float':float.__getformat__('float')} | |
| 431 | |
| 432 def tearDown(self): | |
| 433 float.__setformat__('double', self.save_formats['double']) | |
| 434 float.__setformat__('float', self.save_formats['float']) | |
| 435 | |
| 436 def test_getformat(self): | |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
437 self.assertIn(float.__getformat__('double'), |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
438 ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
439 self.assertIn(float.__getformat__('float'), |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
440 ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) |
| 34972 | 441 self.assertRaises(ValueError, float.__getformat__, 'chicken') |
| 442 self.assertRaises(TypeError, float.__getformat__, 1) | |
| 443 | |
| 444 def test_setformat(self): | |
| 445 for t in 'double', 'float': | |
| 446 float.__setformat__(t, 'unknown') | |
| 447 if self.save_formats[t] == 'IEEE, big-endian': | |
| 448 self.assertRaises(ValueError, float.__setformat__, | |
| 449 t, 'IEEE, little-endian') | |
| 450 elif self.save_formats[t] == 'IEEE, little-endian': | |
| 451 self.assertRaises(ValueError, float.__setformat__, | |
| 452 t, 'IEEE, big-endian') | |
| 453 else: | |
| 454 self.assertRaises(ValueError, float.__setformat__, | |
| 455 t, 'IEEE, big-endian') | |
| 456 self.assertRaises(ValueError, float.__setformat__, | |
| 457 t, 'IEEE, little-endian') | |
| 458 self.assertRaises(ValueError, float.__setformat__, | |
| 459 t, 'chicken') | |
| 460 self.assertRaises(ValueError, float.__setformat__, | |
| 461 'chicken', 'unknown') | |
| 462 | |
| 463 BE_DOUBLE_INF = '\x7f\xf0\x00\x00\x00\x00\x00\x00' | |
| 464 LE_DOUBLE_INF = ''.join(reversed(BE_DOUBLE_INF)) | |
| 465 BE_DOUBLE_NAN = '\x7f\xf8\x00\x00\x00\x00\x00\x00' | |
| 466 LE_DOUBLE_NAN = ''.join(reversed(BE_DOUBLE_NAN)) | |
| 467 | |
| 468 BE_FLOAT_INF = '\x7f\x80\x00\x00' | |
| 469 LE_FLOAT_INF = ''.join(reversed(BE_FLOAT_INF)) | |
| 470 BE_FLOAT_NAN = '\x7f\xc0\x00\x00' | |
| 471 LE_FLOAT_NAN = ''.join(reversed(BE_FLOAT_NAN)) | |
| 472 | |
| 473 # on non-IEEE platforms, attempting to unpack a bit pattern | |
| 474 # representing an infinity or a NaN should raise an exception. | |
| 475 | |
| 476 class UnknownFormatTestCase(unittest.TestCase): | |
| 477 def setUp(self): | |
| 478 self.save_formats = {'double':float.__getformat__('double'), | |
| 479 'float':float.__getformat__('float')} | |
| 480 float.__setformat__('double', 'unknown') | |
| 481 float.__setformat__('float', 'unknown') | |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34972
diff
changeset
|
482 |
| 34972 | 483 def tearDown(self): |
| 484 float.__setformat__('double', self.save_formats['double']) | |
| 485 float.__setformat__('float', self.save_formats['float']) | |
| 486 | |
| 487 def test_double_specials_dont_unpack(self): | |
| 488 for fmt, data in [('>d', BE_DOUBLE_INF), | |
| 489 ('>d', BE_DOUBLE_NAN), | |
| 490 ('<d', LE_DOUBLE_INF), | |
| 491 ('<d', LE_DOUBLE_NAN)]: | |
| 492 self.assertRaises(ValueError, struct.unpack, fmt, data) | |
| 493 | |
| 494 def test_float_specials_dont_unpack(self): | |
| 495 for fmt, data in [('>f', BE_FLOAT_INF), | |
| 496 ('>f', BE_FLOAT_NAN), | |
| 497 ('<f', LE_FLOAT_INF), | |
| 498 ('<f', LE_FLOAT_NAN)]: | |
| 499 self.assertRaises(ValueError, struct.unpack, fmt, data) | |
| 500 | |
| 501 | |
| 502 # on an IEEE platform, all we guarantee is that bit patterns | |
| 503 # representing infinities or NaNs do not raise an exception; all else | |
| 504 # is accident (today). | |
|
42704
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
505 # let's also try to guarantee that -0.0 and 0.0 don't get confused. |
| 34972 | 506 |
| 507 class IEEEFormatTestCase(unittest.TestCase): | |
| 508 if float.__getformat__("double").startswith("IEEE"): | |
| 509 def test_double_specials_do_unpack(self): | |
| 510 for fmt, data in [('>d', BE_DOUBLE_INF), | |
| 511 ('>d', BE_DOUBLE_NAN), | |
| 512 ('<d', LE_DOUBLE_INF), | |
| 513 ('<d', LE_DOUBLE_NAN)]: | |
| 514 struct.unpack(fmt, data) | |
| 515 | |
| 516 if float.__getformat__("float").startswith("IEEE"): | |
| 517 def test_float_specials_do_unpack(self): | |
| 518 for fmt, data in [('>f', BE_FLOAT_INF), | |
| 519 ('>f', BE_FLOAT_NAN), | |
| 520 ('<f', LE_FLOAT_INF), | |
| 521 ('<f', LE_FLOAT_NAN)]: | |
| 522 struct.unpack(fmt, data) | |
| 523 | |
|
42704
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
524 if float.__getformat__("double").startswith("IEEE"): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
525 def test_negative_zero(self): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
526 import math |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
527 def pos_pos(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
528 return 0.0, math.atan2(0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
529 def pos_neg(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
530 return 0.0, math.atan2(-0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
531 def neg_pos(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
532 return -0.0, math.atan2(0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
533 def neg_neg(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
534 return -0.0, math.atan2(-0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
535 self.assertEquals(pos_pos(), neg_pos()) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
536 self.assertEquals(pos_neg(), neg_neg()) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
537 |
|
44482
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
538 if float.__getformat__("double").startswith("IEEE"): |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
539 def test_underflow_sign(self): |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
540 import math |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
541 # check that -1e-1000 gives -0.0, not 0.0 |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
542 self.assertEquals(math.atan2(-1e-1000, -1), math.atan2(-0.0, -1)) |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
543 self.assertEquals(math.atan2(float('-1e-1000'), -1), |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
544 math.atan2(-0.0, -1)) |
| 34972 | 545 |
|
53802
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
546 def test_format(self): |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
547 # these should be rewritten to use both format(x, spec) and |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
548 # x.__format__(spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
549 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
550 self.assertEqual(format(0.0, 'f'), '0.000000') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
551 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
552 # the default is 'g', except for empty format spec |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
553 self.assertEqual(format(0.0, ''), '0.0') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
554 self.assertEqual(format(0.01, ''), '0.01') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
555 self.assertEqual(format(0.01, 'g'), '0.01') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
556 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
557 # empty presentation type should format in the same way as str |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
558 # (issue 5920) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
559 x = 100/7. |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
560 self.assertEqual(format(x, ''), str(x)) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
561 self.assertEqual(format(x, '-'), str(x)) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
562 self.assertEqual(format(x, '>'), str(x)) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
563 self.assertEqual(format(x, '2'), str(x)) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
564 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
565 self.assertEqual(format(1.0, 'f'), '1.000000') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
566 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
567 self.assertEqual(format(-1.0, 'f'), '-1.000000') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
568 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
569 self.assertEqual(format( 1.0, ' f'), ' 1.000000') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
570 self.assertEqual(format(-1.0, ' f'), '-1.000000') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
571 self.assertEqual(format( 1.0, '+f'), '+1.000000') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
572 self.assertEqual(format(-1.0, '+f'), '-1.000000') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
573 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
574 # % formatting |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
575 self.assertEqual(format(-1.0, '%'), '-100.000000%') |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
576 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
577 # conversion to string should fail |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
578 self.assertRaises(ValueError, format, 3.0, "s") |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
579 |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
580 # other format specifiers shouldn't work on floats, |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
581 # in particular int specifiers |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
582 for format_spec in ([chr(x) for x in range(ord('a'), ord('z')+1)] + |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
583 [chr(x) for x in range(ord('A'), ord('Z')+1)]): |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
584 if not format_spec in 'eEfFgGn%': |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
585 self.assertRaises(ValueError, format, 0.0, format_spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
586 self.assertRaises(ValueError, format, 1.0, format_spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
587 self.assertRaises(ValueError, format, -1.0, format_spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
588 self.assertRaises(ValueError, format, 1e100, format_spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
589 self.assertRaises(ValueError, format, -1e100, format_spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
590 self.assertRaises(ValueError, format, 1e-100, format_spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
591 self.assertRaises(ValueError, format, -1e-100, format_spec) |
|
1d8f24d40c2c
Issue #5920: Changed format.__float__ and complex.__float__ to use a precision of 12 when using the empty presentation type. This more closely matches str()'s behavior and reduces surprises when adding alignment flags to an empty format string. Patch by Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
53619
diff
changeset
|
592 |
|
57503
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
593 # issue 3382: 'f' and 'F' with inf's and nan's |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
594 self.assertEqual('{0:f}'.format(INF), 'inf') |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
595 self.assertEqual('{0:F}'.format(INF), 'INF') |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
596 self.assertEqual('{0:f}'.format(-INF), '-inf') |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
597 self.assertEqual('{0:F}'.format(-INF), '-INF') |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
598 self.assertEqual('{0:f}'.format(NAN), 'nan') |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
599 self.assertEqual('{0:F}'.format(NAN), 'NAN') |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
600 |
|
53619
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
601 @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"), |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
602 "test requires IEEE 754 doubles") |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
603 def test_format_testfile(self): |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
604 for line in open(format_testfile): |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
605 if line.startswith('--'): |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
606 continue |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
607 line = line.strip() |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
608 if not line: |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
609 continue |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
610 |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
611 lhs, rhs = map(str.strip, line.split('->')) |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
612 fmt, arg = lhs.split() |
|
57503
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
613 arg = float(arg) |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
614 self.assertEqual(fmt % arg, rhs) |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
615 if not math.isnan(arg) and copysign(1.0, arg) > 0.0: |
|
930aeded900d
Issue #3382: Make '%F' and float.__format__('F') convert results to upper case. Much of the patch came from Mark Dickinson.
Eric Smith <eric@trueblade.com>
parents:
57422
diff
changeset
|
616 self.assertEqual(fmt % -arg, '-' + rhs) |
|
53619
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
617 |
|
53611
a3fcccee8957
Issue #5864: format(1234.5, '.4') gives misleading result
Mark Dickinson <dickinsm@gmail.com>
parents:
53162
diff
changeset
|
618 def test_issue5864(self): |
|
a3fcccee8957
Issue #5864: format(1234.5, '.4') gives misleading result
Mark Dickinson <dickinsm@gmail.com>
parents:
53162
diff
changeset
|
619 self.assertEquals(format(123.456, '.4'), '123.5') |
|
a3fcccee8957
Issue #5864: format(1234.5, '.4') gives misleading result
Mark Dickinson <dickinsm@gmail.com>
parents:
53162
diff
changeset
|
620 self.assertEquals(format(1234.56, '.4'), '1.235e+03') |
|
a3fcccee8957
Issue #5864: format(1234.5, '.4') gives misleading result
Mark Dickinson <dickinsm@gmail.com>
parents:
53162
diff
changeset
|
621 self.assertEquals(format(12345.6, '.4'), '1.235e+04') |
|
a3fcccee8957
Issue #5864: format(1234.5, '.4') gives misleading result
Mark Dickinson <dickinsm@gmail.com>
parents:
53162
diff
changeset
|
622 |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
623 class ReprTestCase(unittest.TestCase): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
624 def test_repr(self): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
625 floats_file = open(os.path.join(os.path.split(__file__)[0], |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
626 'floating_points.txt')) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
627 for line in floats_file: |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
628 line = line.strip() |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
629 if not line or line.startswith('#'): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
630 continue |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
631 v = eval(line) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
632 self.assertEqual(v, eval(repr(v))) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
633 floats_file.close() |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
634 |
|
58191
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
635 @unittest.skipUnless(getattr(sys, 'float_repr_style', '') == 'short', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
636 "applies only when using short float repr style") |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
637 def test_short_repr(self): |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
638 # test short float repr introduced in Python 3.1. One aspect |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
639 # of this repr is that we get some degree of str -> float -> |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
640 # str roundtripping. In particular, for any numeric string |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
641 # containing 15 or fewer significant digits, those exact same |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
642 # digits (modulo trailing zeros) should appear in the output. |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
643 # No more repr(0.03) -> "0.029999999999999999"! |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
644 |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
645 test_strings = [ |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
646 # output always includes *either* a decimal point and at |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
647 # least one digit after that point, or an exponent. |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
648 '0.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
649 '1.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
650 '0.01', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
651 '0.02', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
652 '0.03', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
653 '0.04', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
654 '0.05', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
655 '1.23456789', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
656 '10.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
657 '100.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
658 # values >= 1e16 get an exponent... |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
659 '1000000000000000.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
660 '9999999999999990.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
661 '1e+16', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
662 '1e+17', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
663 # ... and so do values < 1e-4 |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
664 '0.001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
665 '0.001001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
666 '0.00010000000000001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
667 '0.0001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
668 '9.999999999999e-05', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
669 '1e-05', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
670 # values designed to provoke failure if the FPU rounding |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
671 # precision isn't set correctly |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
672 '8.72293771110361e+25', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
673 '7.47005307342313e+26', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
674 '2.86438000439698e+28', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
675 '8.89142905246179e+28', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
676 '3.08578087079232e+35', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
677 ] |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
678 |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
679 for s in test_strings: |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
680 negs = '-'+s |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
681 self.assertEqual(s, repr(float(s))) |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
682 self.assertEqual(negs, repr(float(negs))) |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
683 |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
684 @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"), |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
685 "test requires IEEE 754 doubles") |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
686 class RoundTestCase(unittest.TestCase): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
687 def test_second_argument_type(self): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
688 # any type with an __index__ method should be permitted as |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
689 # a second argument |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
690 self.assertAlmostEqual(round(12.34, True), 12.3) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
691 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
692 class MyIndex(object): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
693 def __index__(self): return 4 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
694 self.assertAlmostEqual(round(-0.123456, MyIndex()), -0.1235) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
695 # but floats should be illegal |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
696 self.assertRaises(TypeError, round, 3.14159, 2.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
697 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
698 def test_inf_nan(self): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
699 # rounding an infinity or nan returns the same number; |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
700 # (in py3k, rounding an infinity or nan raises an error, |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
701 # since the result can't be represented as a long). |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
702 self.assertEqual(round(INF), INF) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
703 self.assertEqual(round(-INF), -INF) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
704 self.assertTrue(math.isnan(round(NAN))) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
705 for n in range(-5, 5): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
706 self.assertEqual(round(INF, n), INF) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
707 self.assertEqual(round(-INF, n), -INF) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
708 self.assertTrue(math.isnan(round(NAN, n))) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
709 |
|
57422
b9b683eedee1
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
Mark Dickinson <dickinsm@gmail.com>
parents:
57324
diff
changeset
|
710 self.assertRaises(TypeError, round, INF, 0.0) |
|
b9b683eedee1
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
Mark Dickinson <dickinsm@gmail.com>
parents:
57324
diff
changeset
|
711 self.assertRaises(TypeError, round, -INF, 1.0) |
|
b9b683eedee1
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
Mark Dickinson <dickinsm@gmail.com>
parents:
57324
diff
changeset
|
712 self.assertRaises(TypeError, round, NAN, "ceci n'est pas un integer") |
|
b9b683eedee1
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
Mark Dickinson <dickinsm@gmail.com>
parents:
57324
diff
changeset
|
713 self.assertRaises(TypeError, round, -0.0, 1j) |
|
b9b683eedee1
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
Mark Dickinson <dickinsm@gmail.com>
parents:
57324
diff
changeset
|
714 |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
715 def test_large_n(self): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
716 for n in [324, 325, 400, 2**31-1, 2**31, 2**32, 2**100]: |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
717 self.assertEqual(round(123.456, n), 123.456) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
718 self.assertEqual(round(-123.456, n), -123.456) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
719 self.assertEqual(round(1e300, n), 1e300) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
720 self.assertEqual(round(1e-320, n), 1e-320) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
721 self.assertEqual(round(1e150, 300), 1e150) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
722 self.assertEqual(round(1e300, 307), 1e300) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
723 self.assertEqual(round(-3.1415, 308), -3.1415) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
724 self.assertEqual(round(1e150, 309), 1e150) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
725 self.assertEqual(round(1.4e-315, 315), 1e-315) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
726 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
727 def test_small_n(self): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
728 for n in [-308, -309, -400, 1-2**31, -2**31, -2**31-1, -2**100]: |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
729 self.assertEqual(round(123.456, n), 0.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
730 self.assertEqual(round(-123.456, n), -0.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
731 self.assertEqual(round(1e300, n), 0.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
732 self.assertEqual(round(1e-320, n), 0.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
733 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
734 def test_overflow(self): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
735 self.assertRaises(OverflowError, round, 1.6e308, -308) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
736 self.assertRaises(OverflowError, round, -1.7e308, -308) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
737 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
738 @unittest.skipUnless(getattr(sys, 'float_repr_style', '') == 'short', |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
739 "test applies only when using short float repr style") |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
740 def test_previous_round_bugs(self): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
741 # particular cases that have occurred in bug reports |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
742 self.assertEqual(round(562949953421312.5, 1), |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
743 562949953421312.5) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
744 self.assertEqual(round(56294995342131.5, 3), |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
745 56294995342131.5) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
746 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
747 @unittest.skipUnless(getattr(sys, 'float_repr_style', '') == 'short', |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
748 "test applies only when using short float repr style") |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
749 def test_halfway_cases(self): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
750 # Halfway cases need special attention, since the current |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
751 # implementation has to deal with them specially. Note that |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
752 # 2.x rounds halfway values up (i.e., away from zero) while |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
753 # 3.x does round-half-to-even. |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
754 self.assertAlmostEqual(round(0.125, 2), 0.13) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
755 self.assertAlmostEqual(round(0.375, 2), 0.38) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
756 self.assertAlmostEqual(round(0.625, 2), 0.63) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
757 self.assertAlmostEqual(round(0.875, 2), 0.88) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
758 self.assertAlmostEqual(round(-0.125, 2), -0.13) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
759 self.assertAlmostEqual(round(-0.375, 2), -0.38) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
760 self.assertAlmostEqual(round(-0.625, 2), -0.63) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
761 self.assertAlmostEqual(round(-0.875, 2), -0.88) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
762 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
763 self.assertAlmostEqual(round(0.25, 1), 0.3) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
764 self.assertAlmostEqual(round(0.75, 1), 0.8) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
765 self.assertAlmostEqual(round(-0.25, 1), -0.3) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
766 self.assertAlmostEqual(round(-0.75, 1), -0.8) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
767 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
768 self.assertEqual(round(-6.5, 0), -7.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
769 self.assertEqual(round(-5.5, 0), -6.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
770 self.assertEqual(round(-1.5, 0), -2.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
771 self.assertEqual(round(-0.5, 0), -1.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
772 self.assertEqual(round(0.5, 0), 1.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
773 self.assertEqual(round(1.5, 0), 2.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
774 self.assertEqual(round(2.5, 0), 3.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
775 self.assertEqual(round(3.5, 0), 4.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
776 self.assertEqual(round(4.5, 0), 5.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
777 self.assertEqual(round(5.5, 0), 6.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
778 self.assertEqual(round(6.5, 0), 7.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
779 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
780 # same but without an explicit second argument; in 3.x these |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
781 # will give integers |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
782 self.assertEqual(round(-6.5), -7.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
783 self.assertEqual(round(-5.5), -6.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
784 self.assertEqual(round(-1.5), -2.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
785 self.assertEqual(round(-0.5), -1.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
786 self.assertEqual(round(0.5), 1.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
787 self.assertEqual(round(1.5), 2.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
788 self.assertEqual(round(2.5), 3.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
789 self.assertEqual(round(3.5), 4.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
790 self.assertEqual(round(4.5), 5.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
791 self.assertEqual(round(5.5), 6.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
792 self.assertEqual(round(6.5), 7.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
793 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
794 self.assertEqual(round(-25.0, -1), -30.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
795 self.assertEqual(round(-15.0, -1), -20.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
796 self.assertEqual(round(-5.0, -1), -10.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
797 self.assertEqual(round(5.0, -1), 10.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
798 self.assertEqual(round(15.0, -1), 20.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
799 self.assertEqual(round(25.0, -1), 30.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
800 self.assertEqual(round(35.0, -1), 40.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
801 self.assertEqual(round(45.0, -1), 50.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
802 self.assertEqual(round(55.0, -1), 60.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
803 self.assertEqual(round(65.0, -1), 70.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
804 self.assertEqual(round(75.0, -1), 80.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
805 self.assertEqual(round(85.0, -1), 90.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
806 self.assertEqual(round(95.0, -1), 100.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
807 self.assertEqual(round(12325.0, -1), 12330.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
808 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
809 self.assertEqual(round(350.0, -2), 400.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
810 self.assertEqual(round(450.0, -2), 500.0) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
811 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
812 self.assertAlmostEqual(round(0.5e21, -21), 1e21) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
813 self.assertAlmostEqual(round(1.5e21, -21), 2e21) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
814 self.assertAlmostEqual(round(2.5e21, -21), 3e21) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
815 self.assertAlmostEqual(round(5.5e21, -21), 6e21) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
816 self.assertAlmostEqual(round(8.5e21, -21), 9e21) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
817 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
818 self.assertAlmostEqual(round(-1.5e22, -22), -2e22) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
819 self.assertAlmostEqual(round(-0.5e22, -22), -1e22) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
820 self.assertAlmostEqual(round(0.5e22, -22), 1e22) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
821 self.assertAlmostEqual(round(1.5e22, -22), 2e22) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
822 |
|
57536
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
823 @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"), |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
824 "test requires IEEE 754 doubles") |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
825 def test_format_specials(self): |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
826 # Test formatting of nans and infs. |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
827 |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
828 def test(fmt, value, expected): |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
829 # Test with both % and format(). |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
830 self.assertEqual(fmt % value, expected, fmt) |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
831 if not '#' in fmt: |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
832 # Until issue 7094 is implemented, format() for floats doesn't |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
833 # support '#' formatting |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
834 fmt = fmt[1:] # strip off the % |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
835 self.assertEqual(format(value, fmt), expected, fmt) |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
836 |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
837 for fmt in ['%e', '%f', '%g', '%.0e', '%.6f', '%.20g', |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
838 '%#e', '%#f', '%#g', '%#.20e', '%#.15f', '%#.3g']: |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
839 pfmt = '%+' + fmt[1:] |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
840 sfmt = '% ' + fmt[1:] |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
841 test(fmt, INF, 'inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
842 test(fmt, -INF, '-inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
843 test(fmt, NAN, 'nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
844 test(fmt, -NAN, 'nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
845 # When asking for a sign, it's always provided. nans are |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
846 # always positive. |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
847 test(pfmt, INF, '+inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
848 test(pfmt, -INF, '-inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
849 test(pfmt, NAN, '+nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
850 test(pfmt, -NAN, '+nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
851 # When using ' ' for a sign code, only infs can be negative. |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
852 # Others have a space. |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
853 test(sfmt, INF, ' inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
854 test(sfmt, -INF, '-inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
855 test(sfmt, NAN, ' nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
856 test(sfmt, -NAN, ' nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
857 |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
858 |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
859 # Beginning with Python 2.6 float has cross platform compatible |
|
47889
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
860 # ways to create and represent inf and nan |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
861 class InfNanTest(unittest.TestCase): |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
862 def test_inf_from_str(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
863 self.assertTrue(isinf(float("inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
864 self.assertTrue(isinf(float("+inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
865 self.assertTrue(isinf(float("-inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
866 self.assertTrue(isinf(float("infinity"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
867 self.assertTrue(isinf(float("+infinity"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
868 self.assertTrue(isinf(float("-infinity"))) |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
869 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
870 self.assertEqual(repr(float("inf")), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
871 self.assertEqual(repr(float("+inf")), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
872 self.assertEqual(repr(float("-inf")), "-inf") |
|
47889
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
873 self.assertEqual(repr(float("infinity")), "inf") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
874 self.assertEqual(repr(float("+infinity")), "inf") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
875 self.assertEqual(repr(float("-infinity")), "-inf") |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
876 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
877 self.assertEqual(repr(float("INF")), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
878 self.assertEqual(repr(float("+Inf")), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
879 self.assertEqual(repr(float("-iNF")), "-inf") |
|
47889
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
880 self.assertEqual(repr(float("Infinity")), "inf") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
881 self.assertEqual(repr(float("+iNfInItY")), "inf") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
882 self.assertEqual(repr(float("-INFINITY")), "-inf") |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
883 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
884 self.assertEqual(str(float("inf")), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
885 self.assertEqual(str(float("+inf")), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
886 self.assertEqual(str(float("-inf")), "-inf") |
|
47889
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
887 self.assertEqual(str(float("infinity")), "inf") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
888 self.assertEqual(str(float("+infinity")), "inf") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
889 self.assertEqual(str(float("-infinity")), "-inf") |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
890 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
891 self.assertRaises(ValueError, float, "info") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
892 self.assertRaises(ValueError, float, "+info") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
893 self.assertRaises(ValueError, float, "-info") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
894 self.assertRaises(ValueError, float, "in") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
895 self.assertRaises(ValueError, float, "+in") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
896 self.assertRaises(ValueError, float, "-in") |
|
47889
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
897 self.assertRaises(ValueError, float, "infinit") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
898 self.assertRaises(ValueError, float, "+Infin") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
899 self.assertRaises(ValueError, float, "-INFI") |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
900 self.assertRaises(ValueError, float, "infinitys") |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
901 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
902 def test_inf_as_str(self): |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
903 self.assertEqual(repr(1e300 * 1e300), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
904 self.assertEqual(repr(-1e300 * 1e300), "-inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
905 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
906 self.assertEqual(str(1e300 * 1e300), "inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
907 self.assertEqual(str(-1e300 * 1e300), "-inf") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
908 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
909 def test_nan_from_str(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
910 self.assertTrue(isnan(float("nan"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
911 self.assertTrue(isnan(float("+nan"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
912 self.assertTrue(isnan(float("-nan"))) |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
913 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
914 self.assertEqual(repr(float("nan")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
915 self.assertEqual(repr(float("+nan")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
916 self.assertEqual(repr(float("-nan")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
917 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
918 self.assertEqual(repr(float("NAN")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
919 self.assertEqual(repr(float("+NAn")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
920 self.assertEqual(repr(float("-NaN")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
921 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
922 self.assertEqual(str(float("nan")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
923 self.assertEqual(str(float("+nan")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
924 self.assertEqual(str(float("-nan")), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
925 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
926 self.assertRaises(ValueError, float, "nana") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
927 self.assertRaises(ValueError, float, "+nana") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
928 self.assertRaises(ValueError, float, "-nana") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
929 self.assertRaises(ValueError, float, "na") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
930 self.assertRaises(ValueError, float, "+na") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
931 self.assertRaises(ValueError, float, "-na") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
932 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
933 def test_nan_as_str(self): |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
934 self.assertEqual(repr(1e300 * 1e300 * 0), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
935 self.assertEqual(repr(-1e300 * 1e300 * 0), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
936 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
937 self.assertEqual(str(1e300 * 1e300 * 0), "nan") |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
938 self.assertEqual(str(-1e300 * 1e300 * 0), "nan") |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
939 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
940 def notest_float_nan(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
941 self.assertTrue(NAN.is_nan()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
942 self.assertFalse(INF.is_nan()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
943 self.assertFalse((0.).is_nan()) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
944 |
|
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
945 def notest_float_inf(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
946 self.assertTrue(INF.is_inf()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
947 self.assertFalse(NAN.is_inf()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
948 self.assertFalse((0.).is_inf()) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
949 |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
950 fromHex = float.fromhex |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
951 toHex = float.hex |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
952 class HexFloatTestCase(unittest.TestCase): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
953 MAX = fromHex('0x.fffffffffffff8p+1024') # max normal |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
954 MIN = fromHex('0x1p-1022') # min normal |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
955 TINY = fromHex('0x0.0000000000001p-1022') # min subnormal |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
956 EPS = fromHex('0x0.0000000000001p0') # diff between 1.0 and next float up |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
957 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
958 def identical(self, x, y): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
959 # check that floats x and y are identical, or that both |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
960 # are NaNs |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
961 if isnan(x) or isnan(y): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
962 if isnan(x) == isnan(y): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
963 return |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
964 elif x == y and (x != 0.0 or copysign(1.0, x) == copysign(1.0, y)): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
965 return |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
966 self.fail('%r not identical to %r' % (x, y)) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
967 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
968 def test_ends(self): |
|
47970
9cb28ad5a41c
Fix float.from_hex tests. It appears that Linux/ia64 doesn't like
Mark Dickinson <dickinsm@gmail.com>
parents:
47966
diff
changeset
|
969 self.identical(self.MIN, ldexp(1.0, -1022)) |
|
9cb28ad5a41c
Fix float.from_hex tests. It appears that Linux/ia64 doesn't like
Mark Dickinson <dickinsm@gmail.com>
parents:
47966
diff
changeset
|
970 self.identical(self.TINY, ldexp(1.0, -1074)) |
|
9cb28ad5a41c
Fix float.from_hex tests. It appears that Linux/ia64 doesn't like
Mark Dickinson <dickinsm@gmail.com>
parents:
47966
diff
changeset
|
971 self.identical(self.EPS, ldexp(1.0, -52)) |
|
9cb28ad5a41c
Fix float.from_hex tests. It appears that Linux/ia64 doesn't like
Mark Dickinson <dickinsm@gmail.com>
parents:
47966
diff
changeset
|
972 self.identical(self.MAX, 2.*(ldexp(1.0, 1023) - ldexp(1.0, 970))) |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
973 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
974 def test_invalid_inputs(self): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
975 invalid_inputs = [ |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
976 'infi', # misspelt infinities and nans |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
977 '-Infinit', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
978 '++inf', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
979 '-+Inf', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
980 '--nan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
981 '+-NaN', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
982 'snan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
983 'NaNs', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
984 'nna', |
|
54000
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
985 'an', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
986 'nf', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
987 'nfinity', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
988 'inity', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
989 'iinity', |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
990 '0xnan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
991 '', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
992 ' ', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
993 'x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
994 '0xX1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
995 '+ 0x1.0p0', # internal whitespace |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
996 '- 0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
997 '0 x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
998 '0x 1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
999 '0x1 2.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1000 '+0x1 .0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1001 '0x1. 0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1002 '-0x1.0 1p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1003 '-0x1.0 p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1004 '+0x1.0p +0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1005 '0x1.0p -0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1006 '0x1.0p 0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1007 '+0x1.0p+ 0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1008 '-0x1.0p- 0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1009 '++0x1.0p-0', # double signs |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1010 '--0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1011 '+-0x1.0p+0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1012 '-+0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1013 '0x1.0p++0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1014 '+0x1.0p+-0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1015 '-0x1.0p-+0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1016 '0x1.0p--0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1017 '0x1.0.p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1018 '0x.p0', # no hex digits before or after point |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1019 '0x1,p0', # wrong decimal point character |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1020 '0x1pa', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1021 u'0x1p\uff10', # fullwidth Unicode digits |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1022 u'\uff10x1p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1023 u'0x\uff11p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1024 u'0x1.\uff10p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1025 '0x1p0 \n 0x2p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1026 '0x1p0\0 0x1p0', # embedded null byte is not end of string |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1027 ] |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1028 for x in invalid_inputs: |
|
48816
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
1029 try: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
1030 result = fromHex(x) |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
1031 except ValueError: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
1032 pass |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
1033 else: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
1034 self.fail('Expected float.fromhex(%r) to raise ValueError; ' |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
1035 'got %r instead' % (x, result)) |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1036 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1037 |
|
54000
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1038 def test_whitespace(self): |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1039 value_pairs = [ |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1040 ('inf', INF), |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1041 ('-Infinity', -INF), |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1042 ('nan', NAN), |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1043 ('1.0', 1.0), |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1044 ('-0x.2', -0.125), |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1045 ('-0.0', -0.0) |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1046 ] |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1047 whitespace = [ |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1048 '', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1049 ' ', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1050 '\t', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1051 '\n', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1052 '\n \t', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1053 '\f', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1054 '\v', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1055 '\r' |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1056 ] |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1057 for inp, expected in value_pairs: |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1058 for lead in whitespace: |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1059 for trail in whitespace: |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1060 got = fromHex(lead + inp + trail) |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1061 self.identical(got, expected) |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1062 |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1063 |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1064 def test_from_hex(self): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1065 MIN = self.MIN; |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1066 MAX = self.MAX; |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1067 TINY = self.TINY; |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1068 EPS = self.EPS; |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1069 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1070 # two spellings of infinity, with optional signs; case-insensitive |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1071 self.identical(fromHex('inf'), INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1072 self.identical(fromHex('+Inf'), INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1073 self.identical(fromHex('-INF'), -INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1074 self.identical(fromHex('iNf'), INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1075 self.identical(fromHex('Infinity'), INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1076 self.identical(fromHex('+INFINITY'), INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1077 self.identical(fromHex('-infinity'), -INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1078 self.identical(fromHex('-iNFiNitY'), -INF) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1079 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1080 # nans with optional sign; case insensitive |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1081 self.identical(fromHex('nan'), NAN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1082 self.identical(fromHex('+NaN'), NAN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1083 self.identical(fromHex('-NaN'), NAN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1084 self.identical(fromHex('-nAN'), NAN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1085 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1086 # variations in input format |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1087 self.identical(fromHex('1'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1088 self.identical(fromHex('+1'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1089 self.identical(fromHex('1.'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1090 self.identical(fromHex('1.0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1091 self.identical(fromHex('1.0p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1092 self.identical(fromHex('01'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1093 self.identical(fromHex('01.'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1094 self.identical(fromHex('0x1'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1095 self.identical(fromHex('0x1.'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1096 self.identical(fromHex('0x1.0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1097 self.identical(fromHex('+0x1.0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1098 self.identical(fromHex('0x1p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1099 self.identical(fromHex('0X1p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1100 self.identical(fromHex('0X1P0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1101 self.identical(fromHex('0x1P0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1102 self.identical(fromHex('0x1.p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1103 self.identical(fromHex('0x1.0p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1104 self.identical(fromHex('0x.1p4'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1105 self.identical(fromHex('0x.1p04'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1106 self.identical(fromHex('0x.1p004'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1107 self.identical(fromHex('0x1p+0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1108 self.identical(fromHex('0x1P-0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1109 self.identical(fromHex('+0x1p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1110 self.identical(fromHex('0x01p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1111 self.identical(fromHex('0x1p00'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1112 self.identical(fromHex(u'0x1p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1113 self.identical(fromHex(' 0x1p0 '), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1114 self.identical(fromHex('\n 0x1p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1115 self.identical(fromHex('0x1p0 \t'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1116 self.identical(fromHex('0xap0'), 10.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1117 self.identical(fromHex('0xAp0'), 10.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1118 self.identical(fromHex('0xaP0'), 10.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1119 self.identical(fromHex('0xAP0'), 10.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1120 self.identical(fromHex('0xbep0'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1121 self.identical(fromHex('0xBep0'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1122 self.identical(fromHex('0xbEp0'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1123 self.identical(fromHex('0XBE0P-4'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1124 self.identical(fromHex('0xBEp0'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1125 self.identical(fromHex('0xB.Ep4'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1126 self.identical(fromHex('0x.BEp8'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1127 self.identical(fromHex('0x.0BEp12'), 190.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1128 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1129 # moving the point around |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1130 pi = fromHex('0x1.921fb54442d18p1') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1131 self.identical(fromHex('0x.006487ed5110b46p11'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1132 self.identical(fromHex('0x.00c90fdaa22168cp10'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1133 self.identical(fromHex('0x.01921fb54442d18p9'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1134 self.identical(fromHex('0x.03243f6a8885a3p8'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1135 self.identical(fromHex('0x.06487ed5110b46p7'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1136 self.identical(fromHex('0x.0c90fdaa22168cp6'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1137 self.identical(fromHex('0x.1921fb54442d18p5'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1138 self.identical(fromHex('0x.3243f6a8885a3p4'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1139 self.identical(fromHex('0x.6487ed5110b46p3'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1140 self.identical(fromHex('0x.c90fdaa22168cp2'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1141 self.identical(fromHex('0x1.921fb54442d18p1'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1142 self.identical(fromHex('0x3.243f6a8885a3p0'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1143 self.identical(fromHex('0x6.487ed5110b46p-1'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1144 self.identical(fromHex('0xc.90fdaa22168cp-2'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1145 self.identical(fromHex('0x19.21fb54442d18p-3'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1146 self.identical(fromHex('0x32.43f6a8885a3p-4'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1147 self.identical(fromHex('0x64.87ed5110b46p-5'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1148 self.identical(fromHex('0xc9.0fdaa22168cp-6'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1149 self.identical(fromHex('0x192.1fb54442d18p-7'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1150 self.identical(fromHex('0x324.3f6a8885a3p-8'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1151 self.identical(fromHex('0x648.7ed5110b46p-9'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1152 self.identical(fromHex('0xc90.fdaa22168cp-10'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1153 self.identical(fromHex('0x1921.fb54442d18p-11'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1154 # ... |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1155 self.identical(fromHex('0x1921fb54442d1.8p-47'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1156 self.identical(fromHex('0x3243f6a8885a3p-48'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1157 self.identical(fromHex('0x6487ed5110b46p-49'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1158 self.identical(fromHex('0xc90fdaa22168cp-50'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1159 self.identical(fromHex('0x1921fb54442d18p-51'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1160 self.identical(fromHex('0x3243f6a8885a30p-52'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1161 self.identical(fromHex('0x6487ed5110b460p-53'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1162 self.identical(fromHex('0xc90fdaa22168c0p-54'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1163 self.identical(fromHex('0x1921fb54442d180p-55'), pi) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1164 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1165 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1166 # results that should overflow... |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1167 self.assertRaises(OverflowError, fromHex, '-0x1p1024') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1168 self.assertRaises(OverflowError, fromHex, '0x1p+1025') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1169 self.assertRaises(OverflowError, fromHex, '+0X1p1030') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1170 self.assertRaises(OverflowError, fromHex, '-0x1p+1100') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1171 self.assertRaises(OverflowError, fromHex, '0X1p123456789123456789') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1172 self.assertRaises(OverflowError, fromHex, '+0X.8p+1025') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1173 self.assertRaises(OverflowError, fromHex, '+0x0.8p1025') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1174 self.assertRaises(OverflowError, fromHex, '-0x0.4p1026') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1175 self.assertRaises(OverflowError, fromHex, '0X2p+1023') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1176 self.assertRaises(OverflowError, fromHex, '0x2.p1023') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1177 self.assertRaises(OverflowError, fromHex, '-0x2.0p+1023') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1178 self.assertRaises(OverflowError, fromHex, '+0X4p+1022') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1179 self.assertRaises(OverflowError, fromHex, '0x1.ffffffffffffffp+1023') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1180 self.assertRaises(OverflowError, fromHex, '-0X1.fffffffffffff9p1023') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1181 self.assertRaises(OverflowError, fromHex, '0X1.fffffffffffff8p1023') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1182 self.assertRaises(OverflowError, fromHex, '+0x3.fffffffffffffp1022') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1183 self.assertRaises(OverflowError, fromHex, '0x3fffffffffffffp+970') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1184 self.assertRaises(OverflowError, fromHex, '0x10000000000000000p960') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1185 self.assertRaises(OverflowError, fromHex, '-0Xffffffffffffffffp960') |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1186 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1187 # ...and those that round to +-max float |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1188 self.identical(fromHex('+0x1.fffffffffffffp+1023'), MAX) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1189 self.identical(fromHex('-0X1.fffffffffffff7p1023'), -MAX) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1190 self.identical(fromHex('0X1.fffffffffffff7fffffffffffffp1023'), MAX) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1191 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1192 # zeros |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1193 self.identical(fromHex('0x0p0'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1194 self.identical(fromHex('0x0p1000'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1195 self.identical(fromHex('-0x0p1023'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1196 self.identical(fromHex('0X0p1024'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1197 self.identical(fromHex('-0x0p1025'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1198 self.identical(fromHex('0X0p2000'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1199 self.identical(fromHex('0x0p123456789123456789'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1200 self.identical(fromHex('-0X0p-0'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1201 self.identical(fromHex('-0X0p-1000'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1202 self.identical(fromHex('0x0p-1023'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1203 self.identical(fromHex('-0X0p-1024'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1204 self.identical(fromHex('-0x0p-1025'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1205 self.identical(fromHex('-0x0p-1072'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1206 self.identical(fromHex('0X0p-1073'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1207 self.identical(fromHex('-0x0p-1074'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1208 self.identical(fromHex('0x0p-1075'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1209 self.identical(fromHex('0X0p-1076'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1210 self.identical(fromHex('-0X0p-2000'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1211 self.identical(fromHex('-0x0p-123456789123456789'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1212 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1213 # values that should underflow to 0 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1214 self.identical(fromHex('0X1p-1075'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1215 self.identical(fromHex('-0X1p-1075'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1216 self.identical(fromHex('-0x1p-123456789123456789'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1217 self.identical(fromHex('0x1.00000000000000001p-1075'), TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1218 self.identical(fromHex('-0x1.1p-1075'), -TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1219 self.identical(fromHex('0x1.fffffffffffffffffp-1075'), TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1220 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1221 # check round-half-even is working correctly near 0 ... |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1222 self.identical(fromHex('0x1p-1076'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1223 self.identical(fromHex('0X2p-1076'), 0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1224 self.identical(fromHex('0X3p-1076'), TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1225 self.identical(fromHex('0x4p-1076'), TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1226 self.identical(fromHex('0X5p-1076'), TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1227 self.identical(fromHex('0X6p-1076'), 2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1228 self.identical(fromHex('0x7p-1076'), 2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1229 self.identical(fromHex('0X8p-1076'), 2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1230 self.identical(fromHex('0X9p-1076'), 2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1231 self.identical(fromHex('0xap-1076'), 2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1232 self.identical(fromHex('0Xbp-1076'), 3*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1233 self.identical(fromHex('0xcp-1076'), 3*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1234 self.identical(fromHex('0Xdp-1076'), 3*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1235 self.identical(fromHex('0Xep-1076'), 4*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1236 self.identical(fromHex('0xfp-1076'), 4*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1237 self.identical(fromHex('0x10p-1076'), 4*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1238 self.identical(fromHex('-0x1p-1076'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1239 self.identical(fromHex('-0X2p-1076'), -0.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1240 self.identical(fromHex('-0x3p-1076'), -TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1241 self.identical(fromHex('-0X4p-1076'), -TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1242 self.identical(fromHex('-0x5p-1076'), -TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1243 self.identical(fromHex('-0x6p-1076'), -2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1244 self.identical(fromHex('-0X7p-1076'), -2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1245 self.identical(fromHex('-0X8p-1076'), -2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1246 self.identical(fromHex('-0X9p-1076'), -2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1247 self.identical(fromHex('-0Xap-1076'), -2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1248 self.identical(fromHex('-0xbp-1076'), -3*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1249 self.identical(fromHex('-0xcp-1076'), -3*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1250 self.identical(fromHex('-0Xdp-1076'), -3*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1251 self.identical(fromHex('-0xep-1076'), -4*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1252 self.identical(fromHex('-0Xfp-1076'), -4*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1253 self.identical(fromHex('-0X10p-1076'), -4*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1254 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1255 # ... and near MIN ... |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1256 self.identical(fromHex('0x0.ffffffffffffd6p-1022'), MIN-3*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1257 self.identical(fromHex('0x0.ffffffffffffd8p-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1258 self.identical(fromHex('0x0.ffffffffffffdap-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1259 self.identical(fromHex('0x0.ffffffffffffdcp-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1260 self.identical(fromHex('0x0.ffffffffffffdep-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1261 self.identical(fromHex('0x0.ffffffffffffe0p-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1262 self.identical(fromHex('0x0.ffffffffffffe2p-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1263 self.identical(fromHex('0x0.ffffffffffffe4p-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1264 self.identical(fromHex('0x0.ffffffffffffe6p-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1265 self.identical(fromHex('0x0.ffffffffffffe8p-1022'), MIN-2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1266 self.identical(fromHex('0x0.ffffffffffffeap-1022'), MIN-TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1267 self.identical(fromHex('0x0.ffffffffffffecp-1022'), MIN-TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1268 self.identical(fromHex('0x0.ffffffffffffeep-1022'), MIN-TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1269 self.identical(fromHex('0x0.fffffffffffff0p-1022'), MIN-TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1270 self.identical(fromHex('0x0.fffffffffffff2p-1022'), MIN-TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1271 self.identical(fromHex('0x0.fffffffffffff4p-1022'), MIN-TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1272 self.identical(fromHex('0x0.fffffffffffff6p-1022'), MIN-TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1273 self.identical(fromHex('0x0.fffffffffffff8p-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1274 self.identical(fromHex('0x0.fffffffffffffap-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1275 self.identical(fromHex('0x0.fffffffffffffcp-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1276 self.identical(fromHex('0x0.fffffffffffffep-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1277 self.identical(fromHex('0x1.00000000000000p-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1278 self.identical(fromHex('0x1.00000000000002p-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1279 self.identical(fromHex('0x1.00000000000004p-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1280 self.identical(fromHex('0x1.00000000000006p-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1281 self.identical(fromHex('0x1.00000000000008p-1022'), MIN) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1282 self.identical(fromHex('0x1.0000000000000ap-1022'), MIN+TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1283 self.identical(fromHex('0x1.0000000000000cp-1022'), MIN+TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1284 self.identical(fromHex('0x1.0000000000000ep-1022'), MIN+TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1285 self.identical(fromHex('0x1.00000000000010p-1022'), MIN+TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1286 self.identical(fromHex('0x1.00000000000012p-1022'), MIN+TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1287 self.identical(fromHex('0x1.00000000000014p-1022'), MIN+TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1288 self.identical(fromHex('0x1.00000000000016p-1022'), MIN+TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1289 self.identical(fromHex('0x1.00000000000018p-1022'), MIN+2*TINY) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1290 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1291 # ... and near 1.0. |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1292 self.identical(fromHex('0x0.fffffffffffff0p0'), 1.0-EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1293 self.identical(fromHex('0x0.fffffffffffff1p0'), 1.0-EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1294 self.identical(fromHex('0X0.fffffffffffff2p0'), 1.0-EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1295 self.identical(fromHex('0x0.fffffffffffff3p0'), 1.0-EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1296 self.identical(fromHex('0X0.fffffffffffff4p0'), 1.0-EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1297 self.identical(fromHex('0X0.fffffffffffff5p0'), 1.0-EPS/2) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1298 self.identical(fromHex('0X0.fffffffffffff6p0'), 1.0-EPS/2) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1299 self.identical(fromHex('0x0.fffffffffffff7p0'), 1.0-EPS/2) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1300 self.identical(fromHex('0x0.fffffffffffff8p0'), 1.0-EPS/2) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1301 self.identical(fromHex('0X0.fffffffffffff9p0'), 1.0-EPS/2) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1302 self.identical(fromHex('0X0.fffffffffffffap0'), 1.0-EPS/2) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1303 self.identical(fromHex('0x0.fffffffffffffbp0'), 1.0-EPS/2) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1304 self.identical(fromHex('0X0.fffffffffffffcp0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1305 self.identical(fromHex('0x0.fffffffffffffdp0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1306 self.identical(fromHex('0X0.fffffffffffffep0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1307 self.identical(fromHex('0x0.ffffffffffffffp0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1308 self.identical(fromHex('0X1.00000000000000p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1309 self.identical(fromHex('0X1.00000000000001p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1310 self.identical(fromHex('0x1.00000000000002p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1311 self.identical(fromHex('0X1.00000000000003p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1312 self.identical(fromHex('0x1.00000000000004p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1313 self.identical(fromHex('0X1.00000000000005p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1314 self.identical(fromHex('0X1.00000000000006p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1315 self.identical(fromHex('0X1.00000000000007p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1316 self.identical(fromHex('0x1.00000000000007ffffffffffffffffffffp0'), |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1317 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1318 self.identical(fromHex('0x1.00000000000008p0'), 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1319 self.identical(fromHex('0x1.00000000000008000000000000000001p0'), |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1320 1+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1321 self.identical(fromHex('0X1.00000000000009p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1322 self.identical(fromHex('0x1.0000000000000ap0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1323 self.identical(fromHex('0x1.0000000000000bp0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1324 self.identical(fromHex('0X1.0000000000000cp0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1325 self.identical(fromHex('0x1.0000000000000dp0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1326 self.identical(fromHex('0x1.0000000000000ep0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1327 self.identical(fromHex('0X1.0000000000000fp0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1328 self.identical(fromHex('0x1.00000000000010p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1329 self.identical(fromHex('0X1.00000000000011p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1330 self.identical(fromHex('0x1.00000000000012p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1331 self.identical(fromHex('0X1.00000000000013p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1332 self.identical(fromHex('0X1.00000000000014p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1333 self.identical(fromHex('0x1.00000000000015p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1334 self.identical(fromHex('0x1.00000000000016p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1335 self.identical(fromHex('0X1.00000000000017p0'), 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1336 self.identical(fromHex('0x1.00000000000017ffffffffffffffffffffp0'), |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1337 1.0+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1338 self.identical(fromHex('0x1.00000000000018p0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1339 self.identical(fromHex('0X1.00000000000018000000000000000001p0'), |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1340 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1341 self.identical(fromHex('0x1.00000000000019p0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1342 self.identical(fromHex('0X1.0000000000001ap0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1343 self.identical(fromHex('0X1.0000000000001bp0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1344 self.identical(fromHex('0x1.0000000000001cp0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1345 self.identical(fromHex('0x1.0000000000001dp0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1346 self.identical(fromHex('0x1.0000000000001ep0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1347 self.identical(fromHex('0X1.0000000000001fp0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1348 self.identical(fromHex('0x1.00000000000020p0'), 1.0+2*EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1349 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1350 def test_roundtrip(self): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1351 def roundtrip(x): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1352 return fromHex(toHex(x)) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1353 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1354 for x in [NAN, INF, self.MAX, self.MIN, self.MIN-self.TINY, self.TINY, 0.0]: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1355 self.identical(x, roundtrip(x)) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1356 self.identical(-x, roundtrip(-x)) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1357 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1358 # fromHex(toHex(x)) should exactly recover x, for any non-NaN float x. |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1359 import random |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1360 for i in xrange(10000): |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1361 e = random.randrange(-1200, 1200) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1362 m = random.random() |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1363 s = random.choice([1.0, -1.0]) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1364 try: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1365 x = s*ldexp(m, e) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1366 except OverflowError: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1367 pass |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1368 else: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1369 self.identical(x, fromHex(toHex(x))) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1370 |
|
58278
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1371 class StrtodTestCase(unittest.TestCase): |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1372 def check_string(self, s): |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1373 expected = strtod(s) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1374 try: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1375 fs = float(s) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1376 except OverflowError: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1377 got = '-inf' if s[0] == '-' else 'inf' |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1378 else: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1379 got = fs.hex() |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1380 self.assertEqual(expected, got, |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1381 "Incorrectly rounded str->float conversion for " |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1382 "{}: expected {}, got {}".format(s, expected, got)) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1383 |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1384 @unittest.skipUnless(getattr(sys, 'float_repr_style', '') == 'short', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1385 "applies only when using short float repr style") |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1386 def test_bug7632(self): |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1387 # check a few particular values that gave incorrectly rounded |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1388 # results with previous versions of dtoa.c |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1389 test_strings = [ |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1390 '94393431193180696942841837085033647913224148539854e-358', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1391 '12579816049008305546974391768996369464963024663104e-357', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1392 '17489628565202117263145367596028389348922981857013e-357', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1393 '18487398785991994634182916638542680759613590482273e-357', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1394 '32002864200581033134358724675198044527469366773928e-358', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1395 '73608278998966969345824653500136787876436005957953e-358', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1396 '64774478836417299491718435234611299336288082136054e-358', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1397 '13704940134126574534878641876947980878824688451169e-357', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1398 '46697445774047060960624497964425416610480524760471e-358', |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1399 ] |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1400 for s in test_strings: |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1401 self.check_string(s) |
|
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1402 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
44482
diff
changeset
|
1403 |
| 34972 | 1404 def test_main(): |
| 1405 test_support.run_unittest( | |
|
49054
e27cf7ee2968
#3796: A test class was not run in test_float.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48816
diff
changeset
|
1406 GeneralFloatCases, |
| 34972 | 1407 FormatFunctionsTestCase, |
| 1408 UnknownFormatTestCase, | |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
1409 IEEEFormatTestCase, |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
1410 ReprTestCase, |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
1411 RoundTestCase, |
|
44344
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
1412 InfNanTest, |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1413 HexFloatTestCase, |
|
58278
b4f301cea115
Issue #7632: Fix a bug in dtoa.c that could lead to incorrectly-rounded results.
Mark Dickinson <dickinsm@gmail.com>
parents:
58191
diff
changeset
|
1414 StrtodTestCase, |
|
44267
f909872917b9
The new float repr causes too much trouble and pain. I'm disabling the feature until we have sorted out the issues on all machines. 64bit machines seem to have issues and Guido has reported even worse.
Christian Heimes <christian@cheimes.de>
parents:
44262
diff
changeset
|
1415 ) |
| 34972 | 1416 |
| 1417 if __name__ == '__main__': | |
| 1418 test_main() |
