Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_float.py @ 65035:87f4b32905df 2.7
Cosmetic fix to use print function.
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Fri, 01 Oct 2010 10:48:47 +0000 |
| parents | 1eb36f169c97 |
| children | 732ffa86c798 |
| 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 |
| 34972 | 11 |
|
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
|
12 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
|
13 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
|
14 |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
15 have_getformat = hasattr(float, "__getformat__") |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
16 requires_getformat = unittest.skipUnless(have_getformat, |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
17 "requires __getformat__") |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
18 requires_setformat = unittest.skipUnless(hasattr(float, "__setformat__"), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
19 "requires __setformat__") |
|
58001
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
20 # decorator for skipping tests on non-IEEE 754 platforms |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
21 requires_IEEE_754 = unittest.skipUnless(have_getformat and |
|
58001
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
22 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
|
23 "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
|
24 |
|
53619
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
25 #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
|
26 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
|
27 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
|
28 |
|
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
|
29 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
|
30 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 self.assertRaises(ValueError, float, "--3.14") |
|
58886
b1c9d6bcf3d4
Check that 'd' isn't allowed as an exponent specifier in inputs to the float function.
Mark Dickinson <dickinsm@gmail.com>
parents:
58817
diff
changeset
|
43 # check that we don't accept alternate exponent markers |
|
b1c9d6bcf3d4
Check that 'd' isn't allowed as an exponent specifier in inputs to the float function.
Mark Dickinson <dickinsm@gmail.com>
parents:
58817
diff
changeset
|
44 self.assertRaises(ValueError, float, "-1.7d29") |
|
b1c9d6bcf3d4
Check that 'd' isn't allowed as an exponent specifier in inputs to the float function.
Mark Dickinson <dickinsm@gmail.com>
parents:
58817
diff
changeset
|
45 self.assertRaises(ValueError, float, "3D-14") |
|
49054
e27cf7ee2968
#3796: A test class was not run in test_float.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48816
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 |
|
56913
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
50 # extra long strings should no longer be a problem |
|
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
51 # (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
|
52 float('.' + '1'*1000) |
|
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
53 float(unicode('.' + '1'*1000)) |
|
f10104051339
Test long inputs to float
Mark Dickinson <dickinsm@gmail.com>
parents:
56766
diff
changeset
|
54 |
|
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
|
55 @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
|
56 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
|
57 # 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
|
58 # 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
|
59 # 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
|
60 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
|
61 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
|
62 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
|
63 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 self.assertEqual(float(" 25.e-1 "), 2.5) |
|
49061
fdc0948c95cf
fix missing module
Benjamin Peterson <benjamin@python.org>
parents:
49054
diff
changeset
|
80 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
|
81 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
82 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
|
83 # 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
|
84 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
|
85 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
|
86 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
|
87 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 |
|
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 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
|
97 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
|
98 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
|
99 |
|
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 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
|
101 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
|
102 |
|
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 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
|
104 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
|
105 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
|
106 |
|
53162
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
107 # 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
|
108 # unicode subclasses). |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
109 class FooStr(str): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
110 def __float__(self): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
111 return float(str(self)) + 1 |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
112 |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
113 class FooUnicode(unicode): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
114 def __float__(self): |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
115 return float(unicode(self)) + 1 |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
116 |
|
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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 self.assertRaises(TypeError, float, Foo4(42)) |
|
53162
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
122 self.assertAlmostEqual(float(FooUnicode('8')), 9.) |
|
6bcdc131f53c
Merged revisions 71627 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49061
diff
changeset
|
123 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
|
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 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
|
126 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
|
127 (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
|
128 (-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
|
129 (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
|
130 (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
|
131 ]: |
|
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(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
|
133 |
|
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 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 |
|
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 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 |
|
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 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
|
155 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
|
156 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
|
157 |
|
58001
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
158 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
|
159 # 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
|
160 # 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
|
161 # 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
|
162 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
|
163 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
164 @requires_IEEE_754 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
165 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
|
166 # 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
|
167 # 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
|
168 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
169 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
|
170 # 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
182 # 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 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
|
191 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
192 # (+-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
|
193 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
|
194 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
|
195 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
196 # (+-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
|
197 # 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
203 # (+-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
|
204 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
|
205 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
|
206 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
207 # (+-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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
213 # (-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
|
214 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
|
215 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
|
216 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
217 # 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
230 # 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 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
|
252 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
|
253 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
254 # 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
262 # 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
268 # 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
274 # 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
280 # 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
|
281 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
|
282 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
|
283 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
|
284 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
|
285 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
286 # (-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
|
287 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
|
288 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
289 # (-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
|
290 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
|
291 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
|
292 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
293 # (-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
|
294 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
|
295 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
296 # (-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
|
297 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
|
298 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
|
299 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
300 # 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
|
301 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
|
302 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
|
303 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
|
304 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
305 # 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
|
306 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
|
307 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
|
308 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
|
309 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
310 # 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
330 # 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
|
331 # 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
337 # 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 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
|
349 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
|
350 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
351 # 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
|
352 # 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
|
353 # 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
|
354 # 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
|
355 #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
|
356 #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
|
357 #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
|
358 #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
|
359 #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
|
360 #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
|
361 #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
|
362 #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
|
363 |
|
ac5fd8909998
Issue #7534: Fix handling of nans, infinities, and negative zero in **
Mark Dickinson <dickinsm@gmail.com>
parents:
57536
diff
changeset
|
364 |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
365 @requires_setformat |
| 34972 | 366 class FormatFunctionsTestCase(unittest.TestCase): |
| 367 | |
| 368 def setUp(self): | |
| 369 self.save_formats = {'double':float.__getformat__('double'), | |
| 370 'float':float.__getformat__('float')} | |
| 371 | |
| 372 def tearDown(self): | |
| 373 float.__setformat__('double', self.save_formats['double']) | |
| 374 float.__setformat__('float', self.save_formats['float']) | |
| 375 | |
| 376 def test_getformat(self): | |
|
58460
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
377 self.assertIn(float.__getformat__('double'), |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
378 ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
379 self.assertIn(float.__getformat__('float'), |
|
17891566a478
use assert[Not]In where appropriate
Ezio Melotti <ezio.melotti@gmail.com>
parents:
58278
diff
changeset
|
380 ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) |
| 34972 | 381 self.assertRaises(ValueError, float.__getformat__, 'chicken') |
| 382 self.assertRaises(TypeError, float.__getformat__, 1) | |
| 383 | |
| 384 def test_setformat(self): | |
| 385 for t in 'double', 'float': | |
| 386 float.__setformat__(t, 'unknown') | |
| 387 if self.save_formats[t] == 'IEEE, big-endian': | |
| 388 self.assertRaises(ValueError, float.__setformat__, | |
| 389 t, 'IEEE, little-endian') | |
| 390 elif self.save_formats[t] == 'IEEE, little-endian': | |
| 391 self.assertRaises(ValueError, float.__setformat__, | |
| 392 t, 'IEEE, big-endian') | |
| 393 else: | |
| 394 self.assertRaises(ValueError, float.__setformat__, | |
| 395 t, 'IEEE, big-endian') | |
| 396 self.assertRaises(ValueError, float.__setformat__, | |
| 397 t, 'IEEE, little-endian') | |
| 398 self.assertRaises(ValueError, float.__setformat__, | |
| 399 t, 'chicken') | |
| 400 self.assertRaises(ValueError, float.__setformat__, | |
| 401 'chicken', 'unknown') | |
| 402 | |
| 403 BE_DOUBLE_INF = '\x7f\xf0\x00\x00\x00\x00\x00\x00' | |
| 404 LE_DOUBLE_INF = ''.join(reversed(BE_DOUBLE_INF)) | |
| 405 BE_DOUBLE_NAN = '\x7f\xf8\x00\x00\x00\x00\x00\x00' | |
| 406 LE_DOUBLE_NAN = ''.join(reversed(BE_DOUBLE_NAN)) | |
| 407 | |
| 408 BE_FLOAT_INF = '\x7f\x80\x00\x00' | |
| 409 LE_FLOAT_INF = ''.join(reversed(BE_FLOAT_INF)) | |
| 410 BE_FLOAT_NAN = '\x7f\xc0\x00\x00' | |
| 411 LE_FLOAT_NAN = ''.join(reversed(BE_FLOAT_NAN)) | |
| 412 | |
| 413 # on non-IEEE platforms, attempting to unpack a bit pattern | |
| 414 # representing an infinity or a NaN should raise an exception. | |
| 415 | |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
416 @requires_setformat |
| 34972 | 417 class UnknownFormatTestCase(unittest.TestCase): |
| 418 def setUp(self): | |
| 419 self.save_formats = {'double':float.__getformat__('double'), | |
| 420 'float':float.__getformat__('float')} | |
| 421 float.__setformat__('double', 'unknown') | |
| 422 float.__setformat__('float', 'unknown') | |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34972
diff
changeset
|
423 |
| 34972 | 424 def tearDown(self): |
| 425 float.__setformat__('double', self.save_formats['double']) | |
| 426 float.__setformat__('float', self.save_formats['float']) | |
| 427 | |
| 428 def test_double_specials_dont_unpack(self): | |
| 429 for fmt, data in [('>d', BE_DOUBLE_INF), | |
| 430 ('>d', BE_DOUBLE_NAN), | |
| 431 ('<d', LE_DOUBLE_INF), | |
| 432 ('<d', LE_DOUBLE_NAN)]: | |
| 433 self.assertRaises(ValueError, struct.unpack, fmt, data) | |
| 434 | |
| 435 def test_float_specials_dont_unpack(self): | |
| 436 for fmt, data in [('>f', BE_FLOAT_INF), | |
| 437 ('>f', BE_FLOAT_NAN), | |
| 438 ('<f', LE_FLOAT_INF), | |
| 439 ('<f', LE_FLOAT_NAN)]: | |
| 440 self.assertRaises(ValueError, struct.unpack, fmt, data) | |
| 441 | |
| 442 | |
| 443 # on an IEEE platform, all we guarantee is that bit patterns | |
| 444 # representing infinities or NaNs do not raise an exception; all else | |
| 445 # 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
|
446 # let's also try to guarantee that -0.0 and 0.0 don't get confused. |
| 34972 | 447 |
| 448 class IEEEFormatTestCase(unittest.TestCase): | |
| 449 | |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
450 @requires_IEEE_754 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
451 def test_double_specials_do_unpack(self): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
452 for fmt, data in [('>d', BE_DOUBLE_INF), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
453 ('>d', BE_DOUBLE_NAN), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
454 ('<d', LE_DOUBLE_INF), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
455 ('<d', LE_DOUBLE_NAN)]: |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
456 struct.unpack(fmt, data) |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
457 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
458 @requires_IEEE_754 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
459 def test_float_specials_do_unpack(self): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
460 for fmt, data in [('>f', BE_FLOAT_INF), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
461 ('>f', BE_FLOAT_NAN), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
462 ('<f', LE_FLOAT_INF), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
463 ('<f', LE_FLOAT_NAN)]: |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
464 struct.unpack(fmt, data) |
| 34972 | 465 |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
466 @requires_IEEE_754 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
467 def test_negative_zero(self): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
468 def pos_pos(): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
469 return 0.0, math.atan2(0.0, -1) |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
470 def pos_neg(): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
471 return 0.0, math.atan2(-0.0, -1) |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
472 def neg_pos(): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
473 return -0.0, math.atan2(0.0, -1) |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
474 def neg_neg(): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
475 return -0.0, math.atan2(-0.0, -1) |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
476 self.assertEquals(pos_pos(), neg_pos()) |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
477 self.assertEquals(pos_neg(), neg_neg()) |
|
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
|
478 |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
479 @requires_IEEE_754 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
480 def test_underflow_sign(self): |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
481 # check that -1e-1000 gives -0.0, not 0.0 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
482 self.assertEquals(math.atan2(-1e-1000, -1), math.atan2(-0.0, -1)) |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
483 self.assertEquals(math.atan2(float('-1e-1000'), -1), |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
484 math.atan2(-0.0, -1)) |
| 34972 | 485 |
|
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
|
486 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
|
487 # 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
|
488 # 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
|
489 |
|
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
|
490 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
|
491 |
|
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
|
492 # 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
|
493 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
|
494 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
|
495 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
|
496 |
|
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
|
497 # 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
|
498 # (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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 |
|
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
|
505 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
|
506 |
|
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
|
507 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
|
508 |
|
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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 |
|
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
|
514 # % 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
|
515 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
|
516 |
|
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
|
517 # 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
|
518 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
|
519 |
|
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
|
520 # 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
|
521 # 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
|
522 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
|
523 [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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 |
|
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
|
533 # 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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
541 @requires_IEEE_754 |
|
53619
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
542 def test_format_testfile(self): |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
543 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
|
544 if line.startswith('--'): |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
545 continue |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
546 line = line.strip() |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
547 if not line: |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
548 continue |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
549 |
|
5d9771d7cc46
Backport some of the float formatting tests from py3k.
Mark Dickinson <dickinsm@gmail.com>
parents:
53611
diff
changeset
|
550 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
|
551 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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 |
|
53611
a3fcccee8957
Issue #5864: format(1234.5, '.4') gives misleading result
Mark Dickinson <dickinsm@gmail.com>
parents:
53162
diff
changeset
|
557 def test_issue5864(self): |
|
a3fcccee8957
Issue #5864: format(1234.5, '.4') gives misleading result
Mark Dickinson <dickinsm@gmail.com>
parents:
53162
diff
changeset
|
558 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
|
559 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
|
560 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
|
561 |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
562 class ReprTestCase(unittest.TestCase): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
563 def test_repr(self): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
564 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
|
565 'floating_points.txt')) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
566 for line in floats_file: |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
567 line = line.strip() |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
568 if not line or line.startswith('#'): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
569 continue |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
570 v = eval(line) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
571 self.assertEqual(v, eval(repr(v))) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
572 floats_file.close() |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
573 |
|
58191
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
574 @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
|
575 "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
|
576 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
|
577 # 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
|
578 # 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
|
579 # 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
|
580 # 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
|
581 # 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
|
582 # 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
|
583 |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
584 test_strings = [ |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
585 # 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
|
586 # 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
|
587 '0.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
588 '1.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
589 '0.01', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
590 '0.02', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
591 '0.03', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
592 '0.04', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
593 '0.05', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
594 '1.23456789', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
595 '10.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
596 '100.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
597 # 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
|
598 '1000000000000000.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
599 '9999999999999990.0', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
600 '1e+16', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
601 '1e+17', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
602 # ... 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
|
603 '0.001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
604 '0.001001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
605 '0.00010000000000001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
606 '0.0001', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
607 '9.999999999999e-05', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
608 '1e-05', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
609 # 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
|
610 # 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
|
611 '8.72293771110361e+25', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
612 '7.47005307342313e+26', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
613 '2.86438000439698e+28', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
614 '8.89142905246179e+28', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
615 '3.08578087079232e+35', |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
616 ] |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
617 |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
618 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
|
619 negs = '-'+s |
|
10b6678f5c04
Backport some float repr tests that were missed in issue 7117.
Mark Dickinson <dickinsm@gmail.com>
parents:
58001
diff
changeset
|
620 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
|
621 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
|
622 |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
623 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
624 @requires_IEEE_754 |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
625 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
|
626 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
|
627 # 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
|
628 # a second argument |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
629 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
|
630 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
631 class MyIndex(object): |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
632 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
|
633 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
|
634 # 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
|
635 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
|
636 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
637 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
|
638 # 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
|
639 # (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
|
640 # 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 |
|
57422
b9b683eedee1
round(0, "ermintrude") succeeded instead of producing a TypeError. Fix this.
Mark Dickinson <dickinsm@gmail.com>
parents:
57324
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 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
|
653 |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 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
|
664 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
|
665 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
666 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
673 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
|
674 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
|
675 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
|
676 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
677 @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
|
678 "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
|
679 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
|
680 # 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
|
681 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
|
682 562949953421312.5) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
683 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
|
684 56294995342131.5) |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
685 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
686 @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
|
687 "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
|
688 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
|
689 # 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
|
690 # 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
|
691 # 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
|
692 # 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 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
|
701 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
702 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
|
703 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
|
704 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
|
705 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
|
706 |
|
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(-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
|
708 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
|
709 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
|
710 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
|
711 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
719 # 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
|
720 # will give integers |
|
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(-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
|
722 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
|
723 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
|
724 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
|
725 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
|
726 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
|
727 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
|
728 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
|
729 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
|
730 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
|
731 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
|
732 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
733 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
|
734 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
|
735 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
|
736 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
|
737 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
|
738 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
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 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
|
745 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
|
746 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
|
747 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
748 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
|
749 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
|
750 |
|
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
751 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 |
|
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(-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
|
758 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
|
759 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
|
760 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
|
761 |
|
62702
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
762 |
|
1eb36f169c97
don't require the presence of __getformat__ or __setformat__; use requires_IEEE_754 globally
Benjamin Peterson <benjamin@python.org>
parents:
62413
diff
changeset
|
763 @requires_IEEE_754 |
|
57536
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
764 def test_format_specials(self): |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
765 # 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
|
766 |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
767 def test(fmt, value, expected): |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
768 # Test with both % and format(). |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
769 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
|
770 if not '#' in fmt: |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
771 # 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
|
772 # support '#' formatting |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
773 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
|
774 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
|
775 |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
776 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
|
777 '%#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
|
778 pfmt = '%+' + fmt[1:] |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
779 sfmt = '% ' + fmt[1:] |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
780 test(fmt, INF, 'inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
781 test(fmt, -INF, '-inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
782 test(fmt, NAN, 'nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
783 test(fmt, -NAN, 'nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
784 # 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
|
785 # always positive. |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
786 test(pfmt, INF, '+inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
787 test(pfmt, -INF, '-inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
788 test(pfmt, NAN, '+nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
789 test(pfmt, -NAN, '+nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
790 # 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
|
791 # Others have a space. |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
792 test(sfmt, INF, ' inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
793 test(sfmt, -INF, '-inf') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
794 test(sfmt, NAN, ' nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
795 test(sfmt, -NAN, ' nan') |
|
0ff47034c691
Issue #4482: Add tests for special float value formatting.
Eric Smith <eric@trueblade.com>
parents:
57503
diff
changeset
|
796 |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
797 |
|
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
|
798 # 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
|
799 # 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
|
800 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
|
801 def test_inf_from_str(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
802 self.assertTrue(isinf(float("inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
803 self.assertTrue(isinf(float("+inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
804 self.assertTrue(isinf(float("-inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
805 self.assertTrue(isinf(float("infinity"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
806 self.assertTrue(isinf(float("+infinity"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
807 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
|
808 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
809 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
|
810 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
|
811 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
|
812 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
|
813 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
|
814 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
|
815 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
816 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
823 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
|
824 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
|
825 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
|
826 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
|
827 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
|
828 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
|
829 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 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
|
839 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
|
840 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
841 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
|
842 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
|
843 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
|
844 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
845 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
|
846 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
|
847 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
848 def test_nan_from_str(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
849 self.assertTrue(isnan(float("nan"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
850 self.assertTrue(isnan(float("+nan"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
851 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
|
852 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
853 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
|
854 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
|
855 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
|
856 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
857 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
|
858 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
|
859 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
|
860 |
|
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 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
|
862 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
|
863 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
|
864 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 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
|
871 |
|
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 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
|
873 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
|
874 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
|
875 |
|
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 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
|
877 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
|
878 |
|
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
|
879 def notest_float_nan(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
880 self.assertTrue(NAN.is_nan()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
881 self.assertFalse(INF.is_nan()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
882 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
|
883 |
|
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
|
884 def notest_float_inf(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
885 self.assertTrue(INF.is_inf()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
886 self.assertFalse(NAN.is_inf()) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
54000
diff
changeset
|
887 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
|
888 |
|
60364
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
889 def test_hash_inf(self): |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
890 # the actual values here should be regarded as an |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
891 # implementation detail, but they need to be |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
892 # identical to those used in the Decimal module. |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
893 self.assertEqual(hash(float('inf')), 314159) |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
894 self.assertEqual(hash(float('-inf')), -271828) |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
895 self.assertEqual(hash(float('nan')), 0) |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
896 |
|
ace711550b59
Use a more robust infinity check in _Py_HashDouble.
Mark Dickinson <dickinsm@gmail.com>
parents:
58886
diff
changeset
|
897 |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
898 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
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 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
|
905 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
906 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
|
907 # 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
|
908 # are NaNs |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
909 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
|
910 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
|
911 return |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
912 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
|
913 return |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
914 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
|
915 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
916 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
|
917 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
|
918 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
|
919 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
|
920 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
|
921 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
922 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
|
923 invalid_inputs = [ |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
924 '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
|
925 '-Infinit', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
926 '++inf', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
927 '-+Inf', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
928 '--nan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
929 '+-NaN', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
930 'snan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
931 'NaNs', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
932 '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
|
933 'an', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
934 'nf', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
935 'nfinity', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
936 'inity', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
937 'iinity', |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
938 '0xnan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
939 '', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
940 ' ', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
941 'x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
942 '0xX1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
943 '+ 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
|
944 '- 0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
945 '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
|
946 '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
|
947 '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
|
948 '+0x1 .0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
949 '0x1. 0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
950 '-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
|
951 '-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
|
952 '+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
|
953 '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
|
954 '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
|
955 '+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
|
956 '-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
|
957 '++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
|
958 '--0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
959 '+-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
|
960 '-+0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
961 '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
|
962 '+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
|
963 '-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
|
964 '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
|
965 '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
|
966 '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
|
967 '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
|
968 '0x1pa', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
969 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
|
970 u'\uff10x1p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
971 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
|
972 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
|
973 '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
|
974 '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
|
975 ] |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
976 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
|
977 try: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
978 result = fromHex(x) |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
979 except ValueError: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
980 pass |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
981 else: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
982 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
|
983 '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
|
984 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
985 |
|
54000
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
986 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
|
987 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
|
988 ('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
|
989 ('-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
|
990 ('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
|
991 ('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
|
992 ('-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
|
993 ('-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
|
994 ] |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
995 whitespace = [ |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
996 '', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
997 ' ', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
998 '\t', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
999 '\n', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1000 '\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
|
1001 '\f', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1002 '\v', |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1003 '\r' |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1004 ] |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 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
|
1010 |
|
119f4232af46
Issue #5981: Fix some float.fromhex bugs related to inf and nan handling.
Mark Dickinson <dickinsm@gmail.com>
parents:
53802
diff
changeset
|
1011 |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1018 # 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
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 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
|
1025 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
|
1026 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
|
1027 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1028 # 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
|
1029 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
|
1030 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
|
1031 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
|
1032 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
|
1033 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1034 # 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
|
1035 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
|
1036 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
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 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
|
1042 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
|
1043 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
|
1044 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
|
1045 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
|
1046 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
|
1047 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
|
1048 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
|
1049 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
|
1050 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
|
1051 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
|
1052 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
|
1053 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
|
1054 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 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
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 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
|
1070 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
|
1071 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
|
1072 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
|
1073 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
|
1074 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
|
1075 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
|
1076 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1077 # 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
|
1078 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
|
1079 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
|
1080 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
|
1081 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
|
1082 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
|
1083 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
|
1084 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
|
1085 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
|
1086 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
|
1087 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
|
1088 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
|
1089 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
|
1090 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
|
1091 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
|
1092 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
|
1093 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
|
1094 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
|
1095 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
|
1096 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
|
1097 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
|
1098 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
|
1099 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
|
1100 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
|
1101 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
|
1102 # ... |
|
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('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
|
1104 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
|
1105 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
|
1106 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
|
1107 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
|
1108 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
|
1109 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
|
1110 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
|
1111 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
|
1112 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1113 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1114 # 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
|
1115 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
|
1116 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
|
1117 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
|
1118 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
|
1119 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
|
1120 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
|
1121 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
|
1122 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
|
1123 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
|
1124 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
|
1125 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
|
1126 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
|
1127 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
|
1128 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
|
1129 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
|
1130 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
|
1131 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
|
1132 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
|
1133 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
|
1134 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1135 # ...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
|
1136 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
|
1137 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
|
1138 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
|
1139 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1140 # zeros |
|
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('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
|
1142 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
|
1143 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
|
1144 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
|
1145 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
|
1146 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
|
1147 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
|
1148 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
|
1149 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
|
1150 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
|
1151 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
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 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
|
1157 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
|
1158 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
|
1159 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
|
1160 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1161 # 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
|
1162 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
|
1163 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
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1169 # 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
|
1170 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
|
1171 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
|
1172 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
|
1173 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
|
1174 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
|
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 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
|
1180 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
|
1181 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
|
1182 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
|
1183 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
|
1184 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
|
1185 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
|
1186 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
|
1187 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
|
1188 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
|
1189 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
|
1190 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
|
1191 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
|
1192 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
|
1193 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
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 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
|
1199 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
|
1200 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
|
1201 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
|
1202 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1203 # ... 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
|
1204 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
|
1205 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
|
1206 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
|
1207 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
|
1208 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
|
1209 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
|
1210 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
|
1211 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
|
1212 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
|
1213 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
|
1214 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
|
1215 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
|
1216 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
|
1217 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
|
1218 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
|
1219 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
|
1220 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
|
1221 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
|
1222 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
|
1223 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
|
1224 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
|
1225 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
|
1226 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
|
1227 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
|
1228 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
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 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
|
1236 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
|
1237 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
|
1238 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1239 # ... 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
|
1240 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
|
1241 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
|
1242 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
|
1243 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
|
1244 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
|
1245 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
|
1246 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
|
1247 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
|
1248 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
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 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
|
1254 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
|
1255 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
|
1256 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
|
1257 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
|
1258 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
|
1259 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
|
1260 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
|
1261 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
|
1262 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
|
1263 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
|
1264 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
|
1265 1.0) |
|
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('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
|
1267 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
|
1268 1+EPS) |
|
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('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
|
1270 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
|
1271 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
|
1272 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
|
1273 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
|
1274 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
|
1275 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
|
1276 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
|
1277 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
|
1278 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
|
1279 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
|
1280 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
|
1281 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
|
1282 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
|
1283 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
|
1284 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
|
1285 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
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 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
|
1291 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
|
1292 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
|
1293 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
|
1294 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
|
1295 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
|
1296 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
|
1297 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1298 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
|
1299 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
|
1300 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
|
1301 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1302 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
|
1303 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
|
1304 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
|
1305 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1306 # 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
|
1307 import random |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1308 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
|
1309 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
|
1310 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
|
1311 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
|
1312 try: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1313 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
|
1314 except OverflowError: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1315 pass |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1316 else: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1317 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
|
1318 |
|
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
|
1319 |
| 34972 | 1320 def test_main(): |
| 1321 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
|
1322 GeneralFloatCases, |
| 34972 | 1323 FormatFunctionsTestCase, |
| 1324 UnknownFormatTestCase, | |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
1325 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
|
1326 ReprTestCase, |
|
57324
92e06cdbeab9
Issue #7117, continued: Change round implementation to use the correctly-rounded
Mark Dickinson <dickinsm@gmail.com>
parents:
56913
diff
changeset
|
1327 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
|
1328 InfNanTest, |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
1329 HexFloatTestCase, |
|
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
|
1330 ) |
| 34972 | 1331 |
| 1332 if __name__ == '__main__': | |
| 1333 test_main() |
