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