Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_float.py @ 49258:25f809123df6 legacy-trunk
Issue #3925: Ignores shutil.rmtree error on cygwin too.
Reviewed by Benjamin Peterson.
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Sun, 21 Sep 2008 20:48:41 +0000 |
| parents | fdc0948c95cf |
| children | 6bcdc131f53c |
| 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 |
|
49054
e27cf7ee2968
#3796: A test class was not run in test_float.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48816
diff
changeset
|
8 import random, fractions |
| 34972 | 9 |
|
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
|
10 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
|
11 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
|
12 |
|
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
|
13 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
|
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
|
15 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
|
16 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
|
17 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 self.assertRaises(ValueError, float, "--3.14") |
|
49054
e27cf7ee2968
#3796: A test class was not run in test_float.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
48816
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 # Implementation limitation in PyFloat_FromString() |
|
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 self.assertRaises(ValueError, float, unicode("1"*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
|
32 |
|
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 @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
|
34 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
|
35 # 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
|
36 # float must not accept the locale specific decimal point but |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
37 # it still has to accept the normal python syntac |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 |
|
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.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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 self.assertEqual(float(" 25.e-1 "), 2.5) |
|
49061
fdc0948c95cf
fix missing module
Benjamin Peterson <benjamin@python.org>
parents:
49054
diff
changeset
|
58 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
|
59 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
60 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
|
61 # 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
|
62 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
|
63 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
|
64 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
|
65 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
78 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
|
79 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
|
80 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 self.assertRaises(TypeError, float, Foo4(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
|
90 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
91 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
|
92 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
|
93 (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
|
94 (-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
|
95 (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
|
96 (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
|
97 ]: |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
98 self.assertEqual(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
|
99 |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
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 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 |
|
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(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
|
121 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
|
122 self.assertRaises(ValueError, float('nan').as_integer_ratio) |
|
83cc09682081
Moved testing of builtin types out of test_builtin and into type specific modules
Benjamin Peterson <benjamin@python.org>
parents:
46473
diff
changeset
|
123 |
| 34972 | 124 class FormatFunctionsTestCase(unittest.TestCase): |
| 125 | |
| 126 def setUp(self): | |
| 127 self.save_formats = {'double':float.__getformat__('double'), | |
| 128 'float':float.__getformat__('float')} | |
| 129 | |
| 130 def tearDown(self): | |
| 131 float.__setformat__('double', self.save_formats['double']) | |
| 132 float.__setformat__('float', self.save_formats['float']) | |
| 133 | |
| 134 def test_getformat(self): | |
| 135 self.assert_(float.__getformat__('double') in | |
| 136 ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) | |
| 137 self.assert_(float.__getformat__('float') in | |
| 138 ['unknown', 'IEEE, big-endian', 'IEEE, little-endian']) | |
| 139 self.assertRaises(ValueError, float.__getformat__, 'chicken') | |
| 140 self.assertRaises(TypeError, float.__getformat__, 1) | |
| 141 | |
| 142 def test_setformat(self): | |
| 143 for t in 'double', 'float': | |
| 144 float.__setformat__(t, 'unknown') | |
| 145 if self.save_formats[t] == 'IEEE, big-endian': | |
| 146 self.assertRaises(ValueError, float.__setformat__, | |
| 147 t, 'IEEE, little-endian') | |
| 148 elif self.save_formats[t] == 'IEEE, little-endian': | |
| 149 self.assertRaises(ValueError, float.__setformat__, | |
| 150 t, 'IEEE, big-endian') | |
| 151 else: | |
| 152 self.assertRaises(ValueError, float.__setformat__, | |
| 153 t, 'IEEE, big-endian') | |
| 154 self.assertRaises(ValueError, float.__setformat__, | |
| 155 t, 'IEEE, little-endian') | |
| 156 self.assertRaises(ValueError, float.__setformat__, | |
| 157 t, 'chicken') | |
| 158 self.assertRaises(ValueError, float.__setformat__, | |
| 159 'chicken', 'unknown') | |
| 160 | |
| 161 BE_DOUBLE_INF = '\x7f\xf0\x00\x00\x00\x00\x00\x00' | |
| 162 LE_DOUBLE_INF = ''.join(reversed(BE_DOUBLE_INF)) | |
| 163 BE_DOUBLE_NAN = '\x7f\xf8\x00\x00\x00\x00\x00\x00' | |
| 164 LE_DOUBLE_NAN = ''.join(reversed(BE_DOUBLE_NAN)) | |
| 165 | |
| 166 BE_FLOAT_INF = '\x7f\x80\x00\x00' | |
| 167 LE_FLOAT_INF = ''.join(reversed(BE_FLOAT_INF)) | |
| 168 BE_FLOAT_NAN = '\x7f\xc0\x00\x00' | |
| 169 LE_FLOAT_NAN = ''.join(reversed(BE_FLOAT_NAN)) | |
| 170 | |
| 171 # on non-IEEE platforms, attempting to unpack a bit pattern | |
| 172 # representing an infinity or a NaN should raise an exception. | |
| 173 | |
| 174 class UnknownFormatTestCase(unittest.TestCase): | |
| 175 def setUp(self): | |
| 176 self.save_formats = {'double':float.__getformat__('double'), | |
| 177 'float':float.__getformat__('float')} | |
| 178 float.__setformat__('double', 'unknown') | |
| 179 float.__setformat__('float', 'unknown') | |
|
35014
275843630522
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
34972
diff
changeset
|
180 |
| 34972 | 181 def tearDown(self): |
| 182 float.__setformat__('double', self.save_formats['double']) | |
| 183 float.__setformat__('float', self.save_formats['float']) | |
| 184 | |
| 185 def test_double_specials_dont_unpack(self): | |
| 186 for fmt, data in [('>d', BE_DOUBLE_INF), | |
| 187 ('>d', BE_DOUBLE_NAN), | |
| 188 ('<d', LE_DOUBLE_INF), | |
| 189 ('<d', LE_DOUBLE_NAN)]: | |
| 190 self.assertRaises(ValueError, struct.unpack, fmt, data) | |
| 191 | |
| 192 def test_float_specials_dont_unpack(self): | |
| 193 for fmt, data in [('>f', BE_FLOAT_INF), | |
| 194 ('>f', BE_FLOAT_NAN), | |
| 195 ('<f', LE_FLOAT_INF), | |
| 196 ('<f', LE_FLOAT_NAN)]: | |
| 197 self.assertRaises(ValueError, struct.unpack, fmt, data) | |
| 198 | |
| 199 | |
| 200 # on an IEEE platform, all we guarantee is that bit patterns | |
| 201 # representing infinities or NaNs do not raise an exception; all else | |
| 202 # 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
|
203 # let's also try to guarantee that -0.0 and 0.0 don't get confused. |
| 34972 | 204 |
| 205 class IEEEFormatTestCase(unittest.TestCase): | |
| 206 if float.__getformat__("double").startswith("IEEE"): | |
| 207 def test_double_specials_do_unpack(self): | |
| 208 for fmt, data in [('>d', BE_DOUBLE_INF), | |
| 209 ('>d', BE_DOUBLE_NAN), | |
| 210 ('<d', LE_DOUBLE_INF), | |
| 211 ('<d', LE_DOUBLE_NAN)]: | |
| 212 struct.unpack(fmt, data) | |
| 213 | |
| 214 if float.__getformat__("float").startswith("IEEE"): | |
| 215 def test_float_specials_do_unpack(self): | |
| 216 for fmt, data in [('>f', BE_FLOAT_INF), | |
| 217 ('>f', BE_FLOAT_NAN), | |
| 218 ('<f', LE_FLOAT_INF), | |
| 219 ('<f', LE_FLOAT_NAN)]: | |
| 220 struct.unpack(fmt, data) | |
| 221 | |
|
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
|
222 if float.__getformat__("double").startswith("IEEE"): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
223 def test_negative_zero(self): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
224 import math |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
225 def pos_pos(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
226 return 0.0, math.atan2(0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
227 def pos_neg(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
228 return 0.0, math.atan2(-0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
229 def neg_pos(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
230 return -0.0, math.atan2(0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
231 def neg_neg(): |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
232 return -0.0, math.atan2(-0.0, -1) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
233 self.assertEquals(pos_pos(), neg_pos()) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
234 self.assertEquals(pos_neg(), neg_neg()) |
|
092f02cf018f
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
Alex Martelli <aleaxit@gmail.com>
parents:
39642
diff
changeset
|
235 |
|
44482
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
236 if float.__getformat__("double").startswith("IEEE"): |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
237 def test_underflow_sign(self): |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
238 import math |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
239 # check that -1e-1000 gives -0.0, not 0.0 |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
240 self.assertEquals(math.atan2(-1e-1000, -1), math.atan2(-0.0, -1)) |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
241 self.assertEquals(math.atan2(float('-1e-1000'), -1), |
|
3fcaf6cc306d
Patch #1725 by Mark Dickinson, fixes incorrect conversion of -1e1000
Guido van Rossum <guido@python.org>
parents:
44344
diff
changeset
|
242 math.atan2(-0.0, -1)) |
| 34972 | 243 |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
244 class ReprTestCase(unittest.TestCase): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
245 def test_repr(self): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
246 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
|
247 'floating_points.txt')) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
248 for line in floats_file: |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
249 line = line.strip() |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
250 if not line or line.startswith('#'): |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
251 continue |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
252 v = eval(line) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
253 self.assertEqual(v, eval(repr(v))) |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
254 floats_file.close() |
|
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
255 |
|
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
|
256 # 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
|
257 # 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
|
258 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
|
259 def test_inf_from_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
|
260 self.assert_(isinf(float("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
|
261 self.assert_(isinf(float("+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
|
262 self.assert_(isinf(float("-inf"))) |
|
47889
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
263 self.assert_(isinf(float("infinity"))) |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
264 self.assert_(isinf(float("+infinity"))) |
|
4bf84035cb5f
Issue 3188: accept float('infinity') as well as float('inf'). This
Mark Dickinson <dickinsm@gmail.com>
parents:
46649
diff
changeset
|
265 self.assert_(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
|
266 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
303 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
|
304 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
|
305 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
306 def test_nan_from_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
|
307 self.assert_(isnan(float("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
|
308 self.assert_(isnan(float("+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
|
309 self.assert_(isnan(float("-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
|
310 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
311 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
|
312 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
|
313 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
|
314 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
334 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
|
335 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
|
336 |
|
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
|
337 def notest_float_nan(self): |
|
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
|
338 self.assert_(NAN.is_nan()) |
|
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
|
339 self.failIf(INF.is_nan()) |
|
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
|
340 self.failIf((0.).is_nan()) |
|
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
|
341 |
|
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
|
342 def notest_float_inf(self): |
|
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
|
343 self.assert_(INF.is_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
|
344 self.failIf(NAN.is_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
|
345 self.failIf((0.).is_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
|
346 |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
347 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
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
355 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
|
356 # 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
|
357 # are NaNs |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
358 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
|
359 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
|
360 return |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
361 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
|
362 return |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
363 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
|
364 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
365 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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
371 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
|
372 invalid_inputs = [ |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
373 '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
|
374 '-Infinit', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
375 '++inf', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
376 '-+Inf', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
377 '--nan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
378 '+-NaN', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
379 'snan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
380 'NaNs', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
381 'nna', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
382 '0xnan', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
383 '', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
384 ' ', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
385 'x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
386 '0xX1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
387 '+ 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
|
388 '- 0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
389 '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
|
390 '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
|
391 '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
|
392 '+0x1 .0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
393 '0x1. 0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
394 '-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
|
395 '-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
|
396 '+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
|
397 '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
|
398 '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
|
399 '+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
|
400 '-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
|
401 '++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
|
402 '--0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
403 '+-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
|
404 '-+0x1.0p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
405 '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
|
406 '+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
|
407 '-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
|
408 '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
|
409 '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
|
410 '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
|
411 '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
|
412 '0x1pa', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
413 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
|
414 u'\uff10x1p0', |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
415 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
|
416 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
|
417 '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
|
418 '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
|
419 ] |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
420 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
|
421 try: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
422 result = fromHex(x) |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
423 except ValueError: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
424 pass |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
425 else: |
|
57a8735647cf
Fix float.fromhex test to give additional information on failure. This
Mark Dickinson <dickinsm@gmail.com>
parents:
47970
diff
changeset
|
426 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
|
427 '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
|
428 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
429 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
436 # 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
446 # 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
452 # 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 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
|
464 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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
495 # 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 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
|
518 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
|
519 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
|
520 # ... |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
521 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
531 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
532 # 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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 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
|
544 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
|
545 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
|
546 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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 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
|
552 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
553 # ...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
|
554 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
|
555 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
|
556 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
|
557 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
558 # zeros |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 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
|
577 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
|
578 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
579 # 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
|
580 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
|
581 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
|
582 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
|
583 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
|
584 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
|
585 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
|
586 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
587 # 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
|
588 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
|
589 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 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
|
618 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
|
619 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
|
620 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
621 # ... 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
|
622 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
|
623 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
|
624 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
|
625 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 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
|
636 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
|
637 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
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 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
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 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
|
655 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
|
656 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
657 # ... 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 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
|
677 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
|
678 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
|
679 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
|
680 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
|
681 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
|
682 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
|
683 1.0) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
684 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
|
685 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
|
686 1+EPS) |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
687 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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 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
|
700 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
|
701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 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
|
709 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
|
710 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
|
711 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
|
712 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
|
713 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
|
714 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
|
715 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
716 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
|
717 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
|
718 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
|
719 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
720 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
|
721 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
|
722 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
|
723 |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
724 # 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
|
725 import random |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
726 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
|
727 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
|
728 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
|
729 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
|
730 try: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
731 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
|
732 except OverflowError: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
733 pass |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
734 else: |
|
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
735 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
|
736 |
|
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
|
737 |
| 34972 | 738 def test_main(): |
| 739 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
|
740 GeneralFloatCases, |
| 34972 | 741 FormatFunctionsTestCase, |
| 742 UnknownFormatTestCase, | |
|
44262
24749a380409
Backport of r59456:59458 from py3k to trunk
Christian Heimes <christian@cheimes.de>
parents:
42704
diff
changeset
|
743 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
|
744 ReprTestCase, |
|
1d69aabf6f7f
Applied patch #1635: Float patch for inf and nan on Windows (and other platforms).
Christian Heimes <christian@cheimes.de>
parents:
44267
diff
changeset
|
745 InfNanTest, |
|
47966
97ba936e8df8
Issue #3008: add instance method float.hex and class method float.fromhex
Mark Dickinson <dickinsm@gmail.com>
parents:
47889
diff
changeset
|
746 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
|
747 ) |
| 34972 | 748 |
| 749 if __name__ == '__main__': | |
| 750 test_main() |
