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