Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_math.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | cd8d3c2d3bce |
| children | f543863f4e43 |
| rev | line source |
|---|---|
| 3950 | 1 # Python test set -- math module |
| 2 # XXXX Should not do tests around zero only | |
| 3 | |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
4 from test.test_support import run_unittest, verbose |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
5 import unittest |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
6 import math |
|
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:
45079
diff
changeset
|
7 import os |
|
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:
45079
diff
changeset
|
8 import sys |
|
47529
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
9 import random |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
10 import struct |
| 3950 | 11 |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
12 eps = 1E-05 |
|
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:
45079
diff
changeset
|
13 NAN = float('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:
45079
diff
changeset
|
14 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:
45079
diff
changeset
|
15 NINF = 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:
45079
diff
changeset
|
16 |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
17 # decorator for skipping tests on non-IEEE 754 platforms |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
18 requires_IEEE_754 = unittest.skipUnless( |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
19 float.__getformat__("double").startswith("IEEE"), |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
20 "test requires IEEE 754 doubles") |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
21 |
|
53350
133c66027f33
Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
22 # detect evidence of double-rounding: fsum is not always correctly |
|
133c66027f33
Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
23 # rounded on machines that suffer from double rounding. |
|
133c66027f33
Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
24 x, y = 1e16, 2.9999 # use temporary values to defeat peephole optimizer |
|
133c66027f33
Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
25 HAVE_DOUBLE_ROUNDING = (x + y == 1e16 + 4) |
|
133c66027f33
Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
26 |
|
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:
45079
diff
changeset
|
27 # locate file with test values |
|
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:
45079
diff
changeset
|
28 if __name__ == '__main__': |
|
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:
45079
diff
changeset
|
29 file = sys.argv[0] |
|
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:
45079
diff
changeset
|
30 else: |
|
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:
45079
diff
changeset
|
31 file = __file__ |
|
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:
45079
diff
changeset
|
32 test_dir = os.path.dirname(file) or os.curdir |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
33 math_testcases = os.path.join(test_dir, 'math_testcases.txt') |
|
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:
45079
diff
changeset
|
34 test_file = os.path.join(test_dir, 'cmath_testcases.txt') |
|
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:
45079
diff
changeset
|
35 |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
36 def to_ulps(x): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
37 """Convert a non-NaN float x to an integer, in such a way that |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
38 adjacent floats are converted to adjacent integers. Then |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
39 abs(ulps(x) - ulps(y)) gives the difference in ulps between two |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
40 floats. |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
41 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
42 The results from this function will only make sense on platforms |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
43 where C doubles are represented in IEEE 754 binary64 format. |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
44 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
45 """ |
|
56556
624f81b5ec24
test_math ulp computation was wrong on big-endian systems
Mark Dickinson <dickinsm@gmail.com>
parents:
56307
diff
changeset
|
46 n = struct.unpack('<q', struct.pack('<d', x))[0] |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
47 if n < 0: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
48 n = ~(n+2**63) |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
49 return n |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
50 |
|
57655
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
51 def ulps_check(expected, got, ulps=20): |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
52 """Given non-NaN floats `expected` and `got`, |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
53 check that they're equal to within the given number of ulps. |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
54 |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
55 Returns None on success and an error message on failure.""" |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
56 |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
57 ulps_error = to_ulps(got) - to_ulps(expected) |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
58 if abs(ulps_error) <= ulps: |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
59 return None |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
60 return "error = {} ulps; permitted error = {} ulps".format(ulps_error, |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
61 ulps) |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
62 |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
63 def acc_check(expected, got, rel_err=2e-15, abs_err = 5e-323): |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
64 """Determine whether non-NaN floats a and b are equal to within a |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
65 (small) rounding error. The default values for rel_err and |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
66 abs_err are chosen to be suitable for platforms where a float is |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
67 represented by an IEEE 754 double. They allow an error of between |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
68 9 and 19 ulps.""" |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
69 |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
70 # need to special case infinities, since inf - inf gives nan |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
71 if math.isinf(expected) and got == expected: |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
72 return None |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
73 |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
74 error = got - expected |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
75 |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
76 permitted_error = max(abs_err, rel_err * abs(expected)) |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
77 if abs(error) < permitted_error: |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
78 return None |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
79 return "error = {}; permitted error = {}".format(error, |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
80 permitted_error) |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
81 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
82 def parse_mtestfile(fname): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
83 """Parse a file with test values |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
84 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
85 -- starts a comment |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
86 blank lines, or lines containing only a comment, are ignored |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
87 other lines are expected to have the form |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
88 id fn arg -> expected [flag]* |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
89 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
90 """ |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
91 with open(fname) as fp: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
92 for line in fp: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
93 # strip comments, and skip blank lines |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
94 if '--' in line: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
95 line = line[:line.index('--')] |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
96 if not line.strip(): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
97 continue |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
98 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
99 lhs, rhs = line.split('->') |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
100 id, fn, arg = lhs.split() |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
101 rhs_pieces = rhs.split() |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
102 exp = rhs_pieces[0] |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
103 flags = rhs_pieces[1:] |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
104 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
105 yield (id, fn, float(arg), float(exp), flags) |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
106 |
|
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:
45079
diff
changeset
|
107 def parse_testfile(fname): |
|
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:
45079
diff
changeset
|
108 """Parse a file with test values |
|
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:
45079
diff
changeset
|
109 |
|
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:
45079
diff
changeset
|
110 Empty lines or lines starting with -- are ignored |
|
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:
45079
diff
changeset
|
111 yields id, fn, arg_real, arg_imag, exp_real, exp_imag |
|
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:
45079
diff
changeset
|
112 """ |
|
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:
45079
diff
changeset
|
113 with open(fname) as fp: |
|
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:
45079
diff
changeset
|
114 for line in fp: |
|
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:
45079
diff
changeset
|
115 # skip comment lines and blank lines |
|
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:
45079
diff
changeset
|
116 if line.startswith('--') or not line.strip(): |
|
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:
45079
diff
changeset
|
117 continue |
|
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:
45079
diff
changeset
|
118 |
|
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:
45079
diff
changeset
|
119 lhs, rhs = line.split('->') |
|
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:
45079
diff
changeset
|
120 id, fn, arg_real, arg_imag = lhs.split() |
|
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:
45079
diff
changeset
|
121 rhs_pieces = rhs.split() |
|
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:
45079
diff
changeset
|
122 exp_real, exp_imag = rhs_pieces[0], rhs_pieces[1] |
|
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:
45079
diff
changeset
|
123 flags = rhs_pieces[2:] |
|
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:
45079
diff
changeset
|
124 |
|
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:
45079
diff
changeset
|
125 yield (id, fn, |
|
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:
45079
diff
changeset
|
126 float(arg_real), float(arg_imag), |
|
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:
45079
diff
changeset
|
127 float(exp_real), float(exp_imag), |
|
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:
45079
diff
changeset
|
128 flags |
|
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:
45079
diff
changeset
|
129 ) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
130 |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
131 class MathTests(unittest.TestCase): |
| 3950 | 132 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
133 def ftest(self, name, value, expected): |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
134 if abs(value-expected) > eps: |
|
42380
0546c115a9cf
Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents:
42370
diff
changeset
|
135 # Use %r instead of %f so the error message |
|
0546c115a9cf
Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents:
42370
diff
changeset
|
136 # displays full precision. Otherwise discrepancies |
|
0546c115a9cf
Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents:
42370
diff
changeset
|
137 # in the last few bits will lead to very confusing |
|
0546c115a9cf
Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents:
42370
diff
changeset
|
138 # error messages |
|
0546c115a9cf
Make test_math error messages more meaningful for small discrepancies in results
Nick Coghlan <ncoghlan@gmail.com>
parents:
42370
diff
changeset
|
139 self.fail('%s returned %r, expected %r' % |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
140 (name, value, expected)) |
| 3950 | 141 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
142 def testConstants(self): |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
143 self.ftest('pi', math.pi, 3.1415926) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
144 self.ftest('e', math.e, 2.7182818) |
| 3950 | 145 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
146 def testAcos(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
147 self.assertRaises(TypeError, math.acos) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
148 self.ftest('acos(-1)', math.acos(-1), math.pi) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
149 self.ftest('acos(0)', math.acos(0), math.pi/2) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
150 self.ftest('acos(1)', math.acos(1), 0) |
|
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:
45079
diff
changeset
|
151 self.assertRaises(ValueError, math.acos, 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:
45079
diff
changeset
|
152 self.assertRaises(ValueError, math.acos, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
153 self.assertTrue(math.isnan(math.acos(NAN))) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
154 |
|
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:
45079
diff
changeset
|
155 def testAcosh(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:
45079
diff
changeset
|
156 self.assertRaises(TypeError, math.acosh) |
|
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:
45079
diff
changeset
|
157 self.ftest('acosh(1)', math.acosh(1), 0) |
|
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:
45079
diff
changeset
|
158 self.ftest('acosh(2)', math.acosh(2), 1.3169578969248168) |
|
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:
45079
diff
changeset
|
159 self.assertRaises(ValueError, math.acosh, 0) |
|
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:
45079
diff
changeset
|
160 self.assertRaises(ValueError, math.acosh, -1) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
161 self.assertEqual(math.acosh(INF), INF) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
162 self.assertRaises(ValueError, math.acosh, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
163 self.assertTrue(math.isnan(math.acosh(NAN))) |
| 3950 | 164 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
165 def testAsin(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
166 self.assertRaises(TypeError, math.asin) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
167 self.ftest('asin(-1)', math.asin(-1), -math.pi/2) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
168 self.ftest('asin(0)', math.asin(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
169 self.ftest('asin(1)', math.asin(1), math.pi/2) |
|
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:
45079
diff
changeset
|
170 self.assertRaises(ValueError, math.asin, 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:
45079
diff
changeset
|
171 self.assertRaises(ValueError, math.asin, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
172 self.assertTrue(math.isnan(math.asin(NAN))) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
173 |
|
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:
45079
diff
changeset
|
174 def testAsinh(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:
45079
diff
changeset
|
175 self.assertRaises(TypeError, math.asinh) |
|
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:
45079
diff
changeset
|
176 self.ftest('asinh(0)', math.asinh(0), 0) |
|
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:
45079
diff
changeset
|
177 self.ftest('asinh(1)', math.asinh(1), 0.88137358701954305) |
|
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:
45079
diff
changeset
|
178 self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
179 self.assertEqual(math.asinh(INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
180 self.assertEqual(math.asinh(NINF), NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
181 self.assertTrue(math.isnan(math.asinh(NAN))) |
| 3950 | 182 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
183 def testAtan(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
184 self.assertRaises(TypeError, math.atan) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
185 self.ftest('atan(-1)', math.atan(-1), -math.pi/4) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
186 self.ftest('atan(0)', math.atan(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
187 self.ftest('atan(1)', math.atan(1), math.pi/4) |
|
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:
45079
diff
changeset
|
188 self.ftest('atan(inf)', math.atan(INF), math.pi/2) |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
189 self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
190 self.assertTrue(math.isnan(math.atan(NAN))) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
191 |
|
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:
45079
diff
changeset
|
192 def testAtanh(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:
45079
diff
changeset
|
193 self.assertRaises(TypeError, math.atan) |
|
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:
45079
diff
changeset
|
194 self.ftest('atanh(0)', math.atanh(0), 0) |
|
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:
45079
diff
changeset
|
195 self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489) |
|
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:
45079
diff
changeset
|
196 self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489) |
|
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:
45079
diff
changeset
|
197 self.assertRaises(ValueError, math.atanh, 1) |
|
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:
45079
diff
changeset
|
198 self.assertRaises(ValueError, math.atanh, -1) |
|
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:
45079
diff
changeset
|
199 self.assertRaises(ValueError, math.atanh, 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:
45079
diff
changeset
|
200 self.assertRaises(ValueError, math.atanh, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
201 self.assertTrue(math.isnan(math.atanh(NAN))) |
| 3950 | 202 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
203 def testAtan2(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
204 self.assertRaises(TypeError, math.atan2) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
205 self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
206 self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
207 self.ftest('atan2(0, 1)', math.atan2(0, 1), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
208 self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
209 self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2) |
| 3950 | 210 |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
211 # math.atan2(0, x) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
212 self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
213 self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
214 self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
215 self.assertEqual(math.atan2(0., 0.), 0.) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
216 self.assertEqual(math.atan2(0., 2.3), 0.) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
217 self.assertEqual(math.atan2(0., INF), 0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
218 self.assertTrue(math.isnan(math.atan2(0., NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
219 # math.atan2(-0, x) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
220 self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
221 self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
222 self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
223 self.assertEqual(math.atan2(-0., 0.), -0.) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
224 self.assertEqual(math.atan2(-0., 2.3), -0.) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
225 self.assertEqual(math.atan2(-0., INF), -0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
226 self.assertTrue(math.isnan(math.atan2(-0., NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
227 # math.atan2(INF, x) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
228 self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
229 self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
230 self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
231 self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
232 self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
233 self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
234 self.assertTrue(math.isnan(math.atan2(INF, NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
235 # math.atan2(NINF, x) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
236 self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
237 self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
238 self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
239 self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
240 self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
241 self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
242 self.assertTrue(math.isnan(math.atan2(NINF, NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
243 # math.atan2(+finite, x) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
244 self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
245 self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
246 self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
247 self.assertEqual(math.atan2(2.3, INF), 0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
248 self.assertTrue(math.isnan(math.atan2(2.3, NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
249 # math.atan2(-finite, x) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
250 self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
251 self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
252 self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
253 self.assertEqual(math.atan2(-2.3, INF), -0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
254 self.assertTrue(math.isnan(math.atan2(-2.3, NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
255 # math.atan2(NAN, x) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
256 self.assertTrue(math.isnan(math.atan2(NAN, NINF))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
257 self.assertTrue(math.isnan(math.atan2(NAN, -2.3))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
258 self.assertTrue(math.isnan(math.atan2(NAN, -0.))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
259 self.assertTrue(math.isnan(math.atan2(NAN, 0.))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
260 self.assertTrue(math.isnan(math.atan2(NAN, 2.3))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
261 self.assertTrue(math.isnan(math.atan2(NAN, INF))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
262 self.assertTrue(math.isnan(math.atan2(NAN, NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
263 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
264 def testCeil(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
265 self.assertRaises(TypeError, math.ceil) |
|
44465
77c37e32fe35
Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44440
diff
changeset
|
266 # These types will be int in py3k. |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
267 self.assertEqual(float, type(math.ceil(1))) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
268 self.assertEqual(float, type(math.ceil(1L))) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
269 self.assertEqual(float, type(math.ceil(1.0))) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
270 self.ftest('ceil(0.5)', math.ceil(0.5), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
271 self.ftest('ceil(1.0)', math.ceil(1.0), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
272 self.ftest('ceil(1.5)', math.ceil(1.5), 2) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
273 self.ftest('ceil(-0.5)', math.ceil(-0.5), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
274 self.ftest('ceil(-1.0)', math.ceil(-1.0), -1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
275 self.ftest('ceil(-1.5)', math.ceil(-1.5), -1) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
276 self.assertEqual(math.ceil(INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
277 self.assertEqual(math.ceil(NINF), NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
278 self.assertTrue(math.isnan(math.ceil(NAN))) |
| 3950 | 279 |
|
44432
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
280 class TestCeil(object): |
|
44488
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44465
diff
changeset
|
281 def __float__(self): |
|
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44465
diff
changeset
|
282 return 41.3 |
|
44432
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
283 class TestNoCeil(object): |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
284 pass |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
285 self.ftest('ceil(TestCeil())', math.ceil(TestCeil()), 42) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
286 self.assertRaises(TypeError, math.ceil, TestNoCeil()) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
287 |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
288 t = TestNoCeil() |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
289 t.__ceil__ = lambda *args: args |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
290 self.assertRaises(TypeError, math.ceil, t) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
291 self.assertRaises(TypeError, math.ceil, t, 0) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
292 |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
293 @requires_IEEE_754 |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
294 def testCopysign(self): |
|
58765
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
295 self.assertEqual(math.copysign(1, 42), 1.0) |
|
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
296 self.assertEqual(math.copysign(0., 42), 0.0) |
|
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
297 self.assertEqual(math.copysign(1., -42), -1.0) |
|
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
298 self.assertEqual(math.copysign(3, 0.), 3.0) |
|
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
299 self.assertEqual(math.copysign(4., -0.), -4.0) |
|
58768
55144cae02ba
Merged revisions 78041 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
57837
diff
changeset
|
300 |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
301 self.assertRaises(TypeError, math.copysign) |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
302 # copysign should let us distinguish signs of zeros |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
303 self.assertEqual(math.copysign(1., 0.), 1.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
304 self.assertEqual(math.copysign(1., -0.), -1.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
305 self.assertEqual(math.copysign(INF, 0.), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
306 self.assertEqual(math.copysign(INF, -0.), NINF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
307 self.assertEqual(math.copysign(NINF, 0.), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
308 self.assertEqual(math.copysign(NINF, -0.), NINF) |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
309 # and of infinities |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
310 self.assertEqual(math.copysign(1., INF), 1.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
311 self.assertEqual(math.copysign(1., NINF), -1.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
312 self.assertEqual(math.copysign(INF, INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
313 self.assertEqual(math.copysign(INF, NINF), NINF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
314 self.assertEqual(math.copysign(NINF, INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
315 self.assertEqual(math.copysign(NINF, NINF), NINF) |
|
58765
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
316 self.assertTrue(math.isnan(math.copysign(NAN, 1.))) |
|
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
317 self.assertTrue(math.isnan(math.copysign(NAN, INF))) |
|
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
318 self.assertTrue(math.isnan(math.copysign(NAN, NINF))) |
|
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
319 self.assertTrue(math.isnan(math.copysign(NAN, NAN))) |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
320 # copysign(INF, NAN) may be INF or it may be NINF, since |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
321 # we don't know whether the sign bit of NAN is set on any |
|
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
322 # given platform. |
|
58765
2ba7677bfa95
testCopysign was defined twice in test_math; combine the definitions
Mark Dickinson <dickinsm@gmail.com>
parents:
57836
diff
changeset
|
323 self.assertTrue(math.isinf(math.copysign(INF, NAN))) |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
324 # similarly, copysign(2., NAN) could be 2. or -2. |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
325 self.assertEqual(abs(math.copysign(2., NAN)), 2.) |
|
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:
45079
diff
changeset
|
326 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
327 def testCos(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
328 self.assertRaises(TypeError, math.cos) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
329 self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
330 self.ftest('cos(0)', math.cos(0), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
331 self.ftest('cos(pi/2)', math.cos(math.pi/2), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
332 self.ftest('cos(pi)', math.cos(math.pi), -1) |
|
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:
45079
diff
changeset
|
333 try: |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
334 self.assertTrue(math.isnan(math.cos(INF))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
335 self.assertTrue(math.isnan(math.cos(NINF))) |
|
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:
45079
diff
changeset
|
336 except ValueError: |
|
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:
45079
diff
changeset
|
337 self.assertRaises(ValueError, math.cos, 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:
45079
diff
changeset
|
338 self.assertRaises(ValueError, math.cos, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
339 self.assertTrue(math.isnan(math.cos(NAN))) |
| 3950 | 340 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
341 def testCosh(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
342 self.assertRaises(TypeError, math.cosh) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
343 self.ftest('cosh(0)', math.cosh(0), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
344 self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
345 self.assertEqual(math.cosh(INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
346 self.assertEqual(math.cosh(NINF), INF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
347 self.assertTrue(math.isnan(math.cosh(NAN))) |
| 3950 | 348 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
349 def testDegrees(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
350 self.assertRaises(TypeError, math.degrees) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
351 self.ftest('degrees(pi)', math.degrees(math.pi), 180.0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
352 self.ftest('degrees(pi/2)', math.degrees(math.pi/2), 90.0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
353 self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0) |
|
23426
1157281f00a0
Adds tests for degrees() and radians() functions added to mathmodule.
Raymond Hettinger <python@rcn.com>
parents:
19750
diff
changeset
|
354 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
355 def testExp(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
356 self.assertRaises(TypeError, math.exp) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
357 self.ftest('exp(-1)', math.exp(-1), 1/math.e) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
358 self.ftest('exp(0)', math.exp(0), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
359 self.ftest('exp(1)', math.exp(1), math.e) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
360 self.assertEqual(math.exp(INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
361 self.assertEqual(math.exp(NINF), 0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
362 self.assertTrue(math.isnan(math.exp(NAN))) |
| 3950 | 363 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
364 def testFabs(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
365 self.assertRaises(TypeError, math.fabs) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
366 self.ftest('fabs(-1)', math.fabs(-1), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
367 self.ftest('fabs(0)', math.fabs(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
368 self.ftest('fabs(1)', math.fabs(1), 1) |
| 3950 | 369 |
|
47529
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
370 def testFactorial(self): |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
371 def fact(n): |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
372 result = 1 |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
373 for i in range(1, int(n)+1): |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
374 result *= i |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
375 return result |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
376 values = range(10) + [50, 100, 500] |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
377 random.shuffle(values) |
|
61541
34a686fbffeb
Merged revisions 81126 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
58768
diff
changeset
|
378 for x in values: |
|
47529
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
379 for cast in (int, long, float): |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
380 self.assertEqual(math.factorial(cast(x)), fact(x), (x, fact(x), math.factorial(x))) |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
381 self.assertRaises(ValueError, math.factorial, -1) |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
382 self.assertRaises(ValueError, math.factorial, math.pi) |
|
6428c4f1ae09
Issue #2138: Add math.factorial().
Raymond Hettinger <python@rcn.com>
parents:
47382
diff
changeset
|
383 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
384 def testFloor(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
385 self.assertRaises(TypeError, math.floor) |
|
44465
77c37e32fe35
Make math.{floor,ceil}({int,long}) return float again for backwards
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44440
diff
changeset
|
386 # These types will be int in py3k. |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
387 self.assertEqual(float, type(math.floor(1))) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
388 self.assertEqual(float, type(math.floor(1L))) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
389 self.assertEqual(float, type(math.floor(1.0))) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
390 self.ftest('floor(0.5)', math.floor(0.5), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
391 self.ftest('floor(1.0)', math.floor(1.0), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
392 self.ftest('floor(1.5)', math.floor(1.5), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
393 self.ftest('floor(-0.5)', math.floor(-0.5), -1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
394 self.ftest('floor(-1.0)', math.floor(-1.0), -1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
395 self.ftest('floor(-1.5)', math.floor(-1.5), -2) |
|
42370
64903ff76ede
Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents:
40284
diff
changeset
|
396 # pow() relies on floor() to check for integers |
|
64903ff76ede
Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents:
40284
diff
changeset
|
397 # This fails on some platforms - so check it here |
|
64903ff76ede
Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents:
40284
diff
changeset
|
398 self.ftest('floor(1.23e167)', math.floor(1.23e167), 1.23e167) |
|
64903ff76ede
Add explicit test for a misbehaving math.floor
Nick Coghlan <ncoghlan@gmail.com>
parents:
40284
diff
changeset
|
399 self.ftest('floor(-1.23e167)', math.floor(-1.23e167), -1.23e167) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
400 self.assertEqual(math.ceil(INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
401 self.assertEqual(math.ceil(NINF), NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
402 self.assertTrue(math.isnan(math.floor(NAN))) |
| 3950 | 403 |
|
44432
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
404 class TestFloor(object): |
|
44488
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44465
diff
changeset
|
405 def __float__(self): |
|
94eeaeeb3ce9
Continue rolling back pep-3141 changes that changed behavior from 2.5. This
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44465
diff
changeset
|
406 return 42.3 |
|
44432
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
407 class TestNoFloor(object): |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
408 pass |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
409 self.ftest('floor(TestFloor())', math.floor(TestFloor()), 42) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
410 self.assertRaises(TypeError, math.floor, TestNoFloor()) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
411 |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
412 t = TestNoFloor() |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
413 t.__floor__ = lambda *args: args |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
414 self.assertRaises(TypeError, math.floor, t) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
415 self.assertRaises(TypeError, math.floor, t, 0) |
|
4f9723d9ca32
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
42380
diff
changeset
|
416 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
417 def testFmod(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
418 self.assertRaises(TypeError, math.fmod) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
419 self.ftest('fmod(10,1)', math.fmod(10,1), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
420 self.ftest('fmod(10,0.5)', math.fmod(10,0.5), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
421 self.ftest('fmod(10,1.5)', math.fmod(10,1.5), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
422 self.ftest('fmod(-10,1)', math.fmod(-10,1), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
423 self.ftest('fmod(-10,0.5)', math.fmod(-10,0.5), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
424 self.ftest('fmod(-10,1.5)', math.fmod(-10,1.5), -1) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
425 self.assertTrue(math.isnan(math.fmod(NAN, 1.))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
426 self.assertTrue(math.isnan(math.fmod(1., NAN))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
427 self.assertTrue(math.isnan(math.fmod(NAN, NAN))) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
428 self.assertRaises(ValueError, math.fmod, 1., 0.) |
|
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:
45079
diff
changeset
|
429 self.assertRaises(ValueError, math.fmod, INF, 1.) |
|
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:
45079
diff
changeset
|
430 self.assertRaises(ValueError, math.fmod, NINF, 1.) |
|
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:
45079
diff
changeset
|
431 self.assertRaises(ValueError, math.fmod, INF, 0.) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
432 self.assertEqual(math.fmod(3.0, INF), 3.0) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
433 self.assertEqual(math.fmod(-3.0, INF), -3.0) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
434 self.assertEqual(math.fmod(3.0, NINF), 3.0) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
435 self.assertEqual(math.fmod(-3.0, NINF), -3.0) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
436 self.assertEqual(math.fmod(0.0, 3.0), 0.0) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
437 self.assertEqual(math.fmod(0.0, NINF), 0.0) |
| 3950 | 438 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
439 def testFrexp(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
440 self.assertRaises(TypeError, math.frexp) |
|
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
441 |
|
57837
bf2eff60eae2
Merged revisions 76945 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
442 def testfrexp(name, result, expected): |
|
bf2eff60eae2
Merged revisions 76945 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
443 (mant, exp), (emant, eexp) = result, expected |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
444 if abs(mant-emant) > eps or exp != eexp: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
445 self.fail('%s returned %r, expected %r'%\ |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
446 (name, (mant, exp), (emant,eexp))) |
| 3950 | 447 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
448 testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1)) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
449 testfrexp('frexp(0)', math.frexp(0), (0, 0)) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
450 testfrexp('frexp(1)', math.frexp(1), (0.5, 1)) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
451 testfrexp('frexp(2)', math.frexp(2), (0.5, 2)) |
| 3950 | 452 |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
453 self.assertEqual(math.frexp(INF)[0], INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
454 self.assertEqual(math.frexp(NINF)[0], NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
455 self.assertTrue(math.isnan(math.frexp(NAN)[0])) |
|
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:
45079
diff
changeset
|
456 |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
457 @requires_IEEE_754 |
|
53351
32226776f866
Remove unnecessary double negative
Mark Dickinson <dickinsm@gmail.com>
parents:
53350
diff
changeset
|
458 @unittest.skipIf(HAVE_DOUBLE_ROUNDING, |
|
53350
133c66027f33
Issue #5593: Use more robust test for double-rounding in test_fsum.
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
459 "fsum is not exact on machines with double rounding") |
|
48110
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
460 def testFsum(self): |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
461 # math.fsum relies on exact rounding for correct operation. |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
462 # There's a known problem with IA32 floating-point that causes |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
463 # inexact rounding in some situations, and will cause the |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
464 # math.fsum tests below to fail; see issue #2937. On non IEEE |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
465 # 754 platforms, and on IEEE 754 platforms that exhibit the |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
466 # problem described in issue #2937, we simply skip the whole |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
467 # test. |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
468 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
469 # Python version of math.fsum, for comparison. Uses a |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
470 # different algorithm based on frexp, ldexp and integer |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
471 # arithmetic. |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
472 from sys import float_info |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
473 mant_dig = float_info.mant_dig |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
474 etiny = float_info.min_exp - mant_dig |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
475 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
476 def msum(iterable): |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
477 """Full precision summation. Compute sum(iterable) without any |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
478 intermediate accumulation of error. Based on the 'lsum' function |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
479 at http://code.activestate.com/recipes/393090/ |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
480 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
481 """ |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
482 tmant, texp = 0, 0 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
483 for x in iterable: |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
484 mant, exp = math.frexp(x) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
485 mant, exp = int(math.ldexp(mant, mant_dig)), exp - mant_dig |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
486 if texp > exp: |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
487 tmant <<= texp-exp |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
488 texp = exp |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
489 else: |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
490 mant <<= exp-texp |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
491 tmant += mant |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
492 # Round tmant * 2**texp to a float. The original recipe |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
493 # used float(str(tmant)) * 2.0**texp for this, but that's |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
494 # a little unsafe because str -> float conversion can't be |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
495 # relied upon to do correct rounding on all platforms. |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
496 tail = max(len(bin(abs(tmant)))-2 - mant_dig, etiny - texp) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
497 if tail > 0: |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
498 h = 1 << (tail-1) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
499 tmant = tmant // (2*h) + bool(tmant & h and tmant & 3*h-1) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
500 texp += tail |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
501 return math.ldexp(tmant, texp) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
502 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
503 test_values = [ |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
504 ([], 0.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
505 ([0.0], 0.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
506 ([1e100, 1.0, -1e100, 1e-100, 1e50, -1.0, -1e50], 1e-100), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
507 ([2.0**53, -0.5, -2.0**-54], 2.0**53-1.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
508 ([2.0**53, 1.0, 2.0**-100], 2.0**53+2.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
509 ([2.0**53+10.0, 1.0, 2.0**-100], 2.0**53+12.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
510 ([2.0**53-4.0, 0.5, 2.0**-54], 2.0**53-3.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
511 ([1./n for n in range(1, 1001)], |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
512 float.fromhex('0x1.df11f45f4e61ap+2')), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
513 ([(-1.)**n/n for n in range(1, 1001)], |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
514 float.fromhex('-0x1.62a2af1bd3624p-1')), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
515 ([1.7**(i+1)-1.7**i for i in range(1000)] + [-1.7**1000], -1.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
516 ([1e16, 1., 1e-16], 10000000000000002.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
517 ([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
518 # exercise code for resizing partials array |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
519 ([2.**n - 2.**(n+50) + 2.**(n+52) for n in range(-1074, 972, 2)] + |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
520 [-2.**1022], |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
521 float.fromhex('0x1.5555555555555p+970')), |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
522 ] |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
523 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
524 for i, (vals, expected) in enumerate(test_values): |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
525 try: |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
526 actual = math.fsum(vals) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
527 except OverflowError: |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
528 self.fail("test %d failed: got OverflowError, expected %r " |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
529 "for math.fsum(%.100r)" % (i, expected, vals)) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
530 except ValueError: |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
531 self.fail("test %d failed: got ValueError, expected %r " |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
532 "for math.fsum(%.100r)" % (i, expected, vals)) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
533 self.assertEqual(actual, expected) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
534 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
535 from random import random, gauss, shuffle |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
536 for j in xrange(1000): |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
537 vals = [7, 1e100, -7, -1e100, -9e-20, 8e-20] * 10 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
538 s = 0 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
539 for i in xrange(200): |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
540 v = gauss(0, random()) ** 7 - s |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
541 s += v |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
542 vals.append(v) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
543 shuffle(vals) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
544 |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
545 s = msum(vals) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
546 self.assertEqual(msum(vals), math.fsum(vals)) |
|
347603f794d1
Rename testSum to testFsum and move it to proper place in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
48101
diff
changeset
|
547 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
548 def testHypot(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
549 self.assertRaises(TypeError, math.hypot) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
550 self.ftest('hypot(0,0)', math.hypot(0,0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
551 self.ftest('hypot(3,4)', math.hypot(3,4), 5) |
|
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:
45079
diff
changeset
|
552 self.assertEqual(math.hypot(NAN, INF), 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:
45079
diff
changeset
|
553 self.assertEqual(math.hypot(INF, NAN), 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:
45079
diff
changeset
|
554 self.assertEqual(math.hypot(NAN, NINF), 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:
45079
diff
changeset
|
555 self.assertEqual(math.hypot(NINF, NAN), INF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
556 self.assertTrue(math.isnan(math.hypot(1.0, NAN))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
557 self.assertTrue(math.isnan(math.hypot(NAN, -2.0))) |
| 3950 | 558 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
559 def testLdexp(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
560 self.assertRaises(TypeError, math.ldexp) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
561 self.ftest('ldexp(0,1)', math.ldexp(0,1), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
562 self.ftest('ldexp(1,1)', math.ldexp(1,1), 2) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
563 self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
564 self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2) |
|
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:
45079
diff
changeset
|
565 self.assertRaises(OverflowError, math.ldexp, 1., 1000000) |
|
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:
45079
diff
changeset
|
566 self.assertRaises(OverflowError, math.ldexp, -1., 1000000) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
567 self.assertEqual(math.ldexp(1., -1000000), 0.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
568 self.assertEqual(math.ldexp(-1., -1000000), -0.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
569 self.assertEqual(math.ldexp(INF, 30), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
570 self.assertEqual(math.ldexp(NINF, -213), NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
571 self.assertTrue(math.isnan(math.ldexp(NAN, 0))) |
| 3950 | 572 |
|
46797
fd0b894bc90c
Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents:
46504
diff
changeset
|
573 # large second argument |
|
fd0b894bc90c
Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents:
46504
diff
changeset
|
574 for n in [10**5, 10L**5, 10**10, 10L**10, 10**20, 10**40]: |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
575 self.assertEqual(math.ldexp(INF, -n), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
576 self.assertEqual(math.ldexp(NINF, -n), NINF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
577 self.assertEqual(math.ldexp(1., -n), 0.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
578 self.assertEqual(math.ldexp(-1., -n), -0.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
579 self.assertEqual(math.ldexp(0., -n), 0.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
580 self.assertEqual(math.ldexp(-0., -n), -0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
581 self.assertTrue(math.isnan(math.ldexp(NAN, -n))) |
|
46797
fd0b894bc90c
Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents:
46504
diff
changeset
|
582 |
|
fd0b894bc90c
Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents:
46504
diff
changeset
|
583 self.assertRaises(OverflowError, math.ldexp, 1., n) |
|
fd0b894bc90c
Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents:
46504
diff
changeset
|
584 self.assertRaises(OverflowError, math.ldexp, -1., n) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
585 self.assertEqual(math.ldexp(0., n), 0.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
586 self.assertEqual(math.ldexp(-0., n), -0.) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
587 self.assertEqual(math.ldexp(INF, n), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
588 self.assertEqual(math.ldexp(NINF, n), NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
589 self.assertTrue(math.isnan(math.ldexp(NAN, n))) |
|
46797
fd0b894bc90c
Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and
Mark Dickinson <dickinsm@gmail.com>
parents:
46504
diff
changeset
|
590 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
591 def testLog(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
592 self.assertRaises(TypeError, math.log) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
593 self.ftest('log(1/e)', math.log(1/math.e), -1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
594 self.ftest('log(1)', math.log(1), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
595 self.ftest('log(e)', math.log(math.e), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
596 self.ftest('log(32,2)', math.log(32,2), 5) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
597 self.ftest('log(10**40, 10)', math.log(10**40, 10), 40) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
598 self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
599 self.assertEqual(math.log(INF), INF) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
600 self.assertRaises(ValueError, math.log, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
601 self.assertTrue(math.isnan(math.log(NAN))) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
602 |
|
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:
45079
diff
changeset
|
603 def testLog1p(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:
45079
diff
changeset
|
604 self.assertRaises(TypeError, math.log1p) |
|
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:
45079
diff
changeset
|
605 self.ftest('log1p(1/e -1)', math.log1p(1/math.e-1), -1) |
|
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:
45079
diff
changeset
|
606 self.ftest('log1p(0)', math.log1p(0), 0) |
|
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:
45079
diff
changeset
|
607 self.ftest('log1p(e-1)', math.log1p(math.e-1), 1) |
|
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:
45079
diff
changeset
|
608 self.ftest('log1p(1)', math.log1p(1), math.log(2)) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
609 self.assertEqual(math.log1p(INF), INF) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
610 self.assertRaises(ValueError, math.log1p, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
611 self.assertTrue(math.isnan(math.log1p(NAN))) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
612 n= 2**90 |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
613 self.assertAlmostEqual(math.log1p(n), 62.383246250395075) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
614 self.assertAlmostEqual(math.log1p(n), math.log1p(float(n))) |
| 3950 | 615 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
616 def testLog10(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
617 self.assertRaises(TypeError, math.log10) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
618 self.ftest('log10(0.1)', math.log10(0.1), -1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
619 self.ftest('log10(1)', math.log10(1), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
620 self.ftest('log10(10)', math.log10(10), 1) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
621 self.assertEqual(math.log(INF), INF) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
622 self.assertRaises(ValueError, math.log10, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
623 self.assertTrue(math.isnan(math.log10(NAN))) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
624 |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
625 def testModf(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
626 self.assertRaises(TypeError, math.modf) |
|
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
627 |
|
57837
bf2eff60eae2
Merged revisions 76945 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
628 def testmodf(name, result, expected): |
|
bf2eff60eae2
Merged revisions 76945 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48110
diff
changeset
|
629 (v1, v2), (e1, e2) = result, expected |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
630 if abs(v1-e1) > eps or abs(v2-e2): |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
631 self.fail('%s returned %r, expected %r'%\ |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
632 (name, (v1,v2), (e1,e2))) |
| 3950 | 633 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
634 testmodf('modf(1.5)', math.modf(1.5), (0.5, 1.0)) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
635 testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0)) |
|
40284
ff678669aa6e
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
40270
diff
changeset
|
636 |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
637 self.assertEqual(math.modf(INF), (0.0, INF)) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
638 self.assertEqual(math.modf(NINF), (-0.0, NINF)) |
|
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:
45079
diff
changeset
|
639 |
|
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:
45079
diff
changeset
|
640 modf_nan = math.modf(NAN) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
641 self.assertTrue(math.isnan(modf_nan[0])) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
642 self.assertTrue(math.isnan(modf_nan[1])) |
|
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:
45079
diff
changeset
|
643 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
644 def testPow(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
645 self.assertRaises(TypeError, math.pow) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
646 self.ftest('pow(0,1)', math.pow(0,1), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
647 self.ftest('pow(1,0)', math.pow(1,0), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
648 self.ftest('pow(2,1)', math.pow(2,1), 2) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
649 self.ftest('pow(2,-1)', math.pow(2,-1), 0.5) |
|
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:
45079
diff
changeset
|
650 self.assertEqual(math.pow(INF, 1), 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:
45079
diff
changeset
|
651 self.assertEqual(math.pow(NINF, 1), NINF) |
|
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:
45079
diff
changeset
|
652 self.assertEqual((math.pow(1, INF)), 1.) |
|
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:
45079
diff
changeset
|
653 self.assertEqual((math.pow(1, NINF)), 1.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
654 self.assertTrue(math.isnan(math.pow(NAN, 1))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
655 self.assertTrue(math.isnan(math.pow(2, NAN))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
656 self.assertTrue(math.isnan(math.pow(0, NAN))) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
657 self.assertEqual(math.pow(1, NAN), 1) |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
658 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
659 # pow(0., x) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
660 self.assertEqual(math.pow(0., INF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
661 self.assertEqual(math.pow(0., 3.), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
662 self.assertEqual(math.pow(0., 2.3), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
663 self.assertEqual(math.pow(0., 2.), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
664 self.assertEqual(math.pow(0., 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
665 self.assertEqual(math.pow(0., -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
666 self.assertRaises(ValueError, math.pow, 0., -2.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
667 self.assertRaises(ValueError, math.pow, 0., -2.3) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
668 self.assertRaises(ValueError, math.pow, 0., -3.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
669 self.assertRaises(ValueError, math.pow, 0., NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
670 self.assertTrue(math.isnan(math.pow(0., NAN))) |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
671 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
672 # pow(INF, x) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
673 self.assertEqual(math.pow(INF, INF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
674 self.assertEqual(math.pow(INF, 3.), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
675 self.assertEqual(math.pow(INF, 2.3), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
676 self.assertEqual(math.pow(INF, 2.), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
677 self.assertEqual(math.pow(INF, 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
678 self.assertEqual(math.pow(INF, -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
679 self.assertEqual(math.pow(INF, -2.), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
680 self.assertEqual(math.pow(INF, -2.3), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
681 self.assertEqual(math.pow(INF, -3.), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
682 self.assertEqual(math.pow(INF, NINF), 0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
683 self.assertTrue(math.isnan(math.pow(INF, NAN))) |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
684 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
685 # pow(-0., x) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
686 self.assertEqual(math.pow(-0., INF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
687 self.assertEqual(math.pow(-0., 3.), -0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
688 self.assertEqual(math.pow(-0., 2.3), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
689 self.assertEqual(math.pow(-0., 2.), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
690 self.assertEqual(math.pow(-0., 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
691 self.assertEqual(math.pow(-0., -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
692 self.assertRaises(ValueError, math.pow, -0., -2.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
693 self.assertRaises(ValueError, math.pow, -0., -2.3) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
694 self.assertRaises(ValueError, math.pow, -0., -3.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
695 self.assertRaises(ValueError, math.pow, -0., NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
696 self.assertTrue(math.isnan(math.pow(-0., NAN))) |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
697 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
698 # pow(NINF, x) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
699 self.assertEqual(math.pow(NINF, INF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
700 self.assertEqual(math.pow(NINF, 3.), NINF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
701 self.assertEqual(math.pow(NINF, 2.3), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
702 self.assertEqual(math.pow(NINF, 2.), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
703 self.assertEqual(math.pow(NINF, 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
704 self.assertEqual(math.pow(NINF, -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
705 self.assertEqual(math.pow(NINF, -2.), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
706 self.assertEqual(math.pow(NINF, -2.3), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
707 self.assertEqual(math.pow(NINF, -3.), -0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
708 self.assertEqual(math.pow(NINF, NINF), 0.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
709 self.assertTrue(math.isnan(math.pow(NINF, NAN))) |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
710 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
711 # pow(-1, x) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
712 self.assertEqual(math.pow(-1., INF), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
713 self.assertEqual(math.pow(-1., 3.), -1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
714 self.assertRaises(ValueError, math.pow, -1., 2.3) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
715 self.assertEqual(math.pow(-1., 2.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
716 self.assertEqual(math.pow(-1., 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
717 self.assertEqual(math.pow(-1., -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
718 self.assertEqual(math.pow(-1., -2.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
719 self.assertRaises(ValueError, math.pow, -1., -2.3) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
720 self.assertEqual(math.pow(-1., -3.), -1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
721 self.assertEqual(math.pow(-1., NINF), 1.) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
722 self.assertTrue(math.isnan(math.pow(-1., NAN))) |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
723 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
724 # pow(1, x) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
725 self.assertEqual(math.pow(1., INF), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
726 self.assertEqual(math.pow(1., 3.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
727 self.assertEqual(math.pow(1., 2.3), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
728 self.assertEqual(math.pow(1., 2.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
729 self.assertEqual(math.pow(1., 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
730 self.assertEqual(math.pow(1., -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
731 self.assertEqual(math.pow(1., -2.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
732 self.assertEqual(math.pow(1., -2.3), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
733 self.assertEqual(math.pow(1., -3.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
734 self.assertEqual(math.pow(1., NINF), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
735 self.assertEqual(math.pow(1., NAN), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
736 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
737 # pow(x, 0) should be 1 for any x |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
738 self.assertEqual(math.pow(2.3, 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
739 self.assertEqual(math.pow(-2.3, 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
740 self.assertEqual(math.pow(NAN, 0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
741 self.assertEqual(math.pow(2.3, -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
742 self.assertEqual(math.pow(-2.3, -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
743 self.assertEqual(math.pow(NAN, -0.), 1.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
744 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
745 # pow(x, y) is invalid if x is negative and y is not integral |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
746 self.assertRaises(ValueError, math.pow, -1., 2.3) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
747 self.assertRaises(ValueError, math.pow, -15., -3.1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
748 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
749 # pow(x, NINF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
750 self.assertEqual(math.pow(1.9, NINF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
751 self.assertEqual(math.pow(1.1, NINF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
752 self.assertEqual(math.pow(0.9, NINF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
753 self.assertEqual(math.pow(0.1, NINF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
754 self.assertEqual(math.pow(-0.1, NINF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
755 self.assertEqual(math.pow(-0.9, NINF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
756 self.assertEqual(math.pow(-1.1, NINF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
757 self.assertEqual(math.pow(-1.9, NINF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
758 |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
759 # pow(x, INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
760 self.assertEqual(math.pow(1.9, INF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
761 self.assertEqual(math.pow(1.1, INF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
762 self.assertEqual(math.pow(0.9, INF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
763 self.assertEqual(math.pow(0.1, INF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
764 self.assertEqual(math.pow(-0.1, INF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
765 self.assertEqual(math.pow(-0.9, INF), 0.) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
766 self.assertEqual(math.pow(-1.1, INF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
767 self.assertEqual(math.pow(-1.9, INF), INF) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
768 |
|
46500
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
769 # pow(x, y) should work for x negative, y an integer |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
770 self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
771 self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
772 self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
773 self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
774 self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
775 self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
776 self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
777 self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
778 self.assertRaises(ValueError, math.pow, -2.0, -0.5) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
779 self.assertRaises(ValueError, math.pow, -2.0, 0.5) |
|
a20def0101de
Yet more explicit special case handling to make
Mark Dickinson <dickinsm@gmail.com>
parents:
46498
diff
changeset
|
780 |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
781 # the following tests have been commented out since they don't |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
782 # really belong here: the implementation of ** for floats is |
|
68588
cd8d3c2d3bce
#11565: Fix several typos. Patch by Piotr Kasprzyk.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
68256
diff
changeset
|
783 # independent of the implementation of math.pow |
|
46486
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
784 #self.assertEqual(1**NAN, 1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
785 #self.assertEqual(1**INF, 1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
786 #self.assertEqual(1**NINF, 1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
787 #self.assertEqual(1**0, 1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
788 #self.assertEqual(1.**NAN, 1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
789 #self.assertEqual(1.**INF, 1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
790 #self.assertEqual(1.**NINF, 1) |
|
82d85a05923b
Additional tests for math.pow, and extra special-case
Mark Dickinson <dickinsm@gmail.com>
parents:
46473
diff
changeset
|
791 #self.assertEqual(1.**0, 1) |
| 3950 | 792 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
793 def testRadians(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
794 self.assertRaises(TypeError, math.radians) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
795 self.ftest('radians(180)', math.radians(180), math.pi) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
796 self.ftest('radians(90)', math.radians(90), math.pi/2) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
797 self.ftest('radians(-45)', math.radians(-45), -math.pi/4) |
| 3950 | 798 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
799 def testSin(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
800 self.assertRaises(TypeError, math.sin) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
801 self.ftest('sin(0)', math.sin(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
802 self.ftest('sin(pi/2)', math.sin(math.pi/2), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
803 self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1) |
|
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:
45079
diff
changeset
|
804 try: |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
805 self.assertTrue(math.isnan(math.sin(INF))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
806 self.assertTrue(math.isnan(math.sin(NINF))) |
|
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:
45079
diff
changeset
|
807 except ValueError: |
|
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:
45079
diff
changeset
|
808 self.assertRaises(ValueError, math.sin, 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:
45079
diff
changeset
|
809 self.assertRaises(ValueError, math.sin, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
810 self.assertTrue(math.isnan(math.sin(NAN))) |
|
23426
1157281f00a0
Adds tests for degrees() and radians() functions added to mathmodule.
Raymond Hettinger <python@rcn.com>
parents:
19750
diff
changeset
|
811 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
812 def testSinh(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
813 self.assertRaises(TypeError, math.sinh) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
814 self.ftest('sinh(0)', math.sinh(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
815 self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
816 self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
817 self.assertEqual(math.sinh(INF), INF) |
|
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
818 self.assertEqual(math.sinh(NINF), NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
819 self.assertTrue(math.isnan(math.sinh(NAN))) |
| 3950 | 820 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
821 def testSqrt(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
822 self.assertRaises(TypeError, math.sqrt) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
823 self.ftest('sqrt(0)', math.sqrt(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
824 self.ftest('sqrt(1)', math.sqrt(1), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
825 self.ftest('sqrt(4)', math.sqrt(4), 2) |
|
66348
614c84670c63
Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents:
62841
diff
changeset
|
826 self.assertEqual(math.sqrt(INF), INF) |
|
46473
5bc7b20dc04a
I finally got the time to update and merge Mark's and my trunk-math branch. The patch is collaborated work of Mark Dickinson and me. It was mostly done a few months ago. The patch fixes a lot of loose ends and edge cases related to operations with NaN, INF, very small values and complex math.
Christian Heimes <christian@cheimes.de>
parents:
45079
diff
changeset
|
827 self.assertRaises(ValueError, math.sqrt, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
828 self.assertTrue(math.isnan(math.sqrt(NAN))) |
| 3950 | 829 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
830 def testTan(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
831 self.assertRaises(TypeError, math.tan) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
832 self.ftest('tan(0)', math.tan(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
833 self.ftest('tan(pi/4)', math.tan(math.pi/4), 1) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
834 self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1) |
|
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:
45079
diff
changeset
|
835 try: |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
836 self.assertTrue(math.isnan(math.tan(INF))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
837 self.assertTrue(math.isnan(math.tan(NINF))) |
|
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:
45079
diff
changeset
|
838 except: |
|
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:
45079
diff
changeset
|
839 self.assertRaises(ValueError, math.tan, 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:
45079
diff
changeset
|
840 self.assertRaises(ValueError, math.tan, NINF) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
841 self.assertTrue(math.isnan(math.tan(NAN))) |
| 3950 | 842 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
843 def testTanh(self): |
|
40270
1715e6a0aee9
Add tests for basic argument errors.
Walter Dörwald <walter@livinglogic.de>
parents:
40219
diff
changeset
|
844 self.assertRaises(TypeError, math.tanh) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
845 self.ftest('tanh(0)', math.tanh(0), 0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
846 self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0) |
|
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:
45079
diff
changeset
|
847 self.ftest('tanh(inf)', math.tanh(INF), 1) |
|
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:
45079
diff
changeset
|
848 self.ftest('tanh(-inf)', math.tanh(NINF), -1) |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
849 self.assertTrue(math.isnan(math.tanh(NAN))) |
|
46504
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
850 # check that tanh(-0.) == -0. on IEEE 754 systems |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
851 if float.__getformat__("double").startswith("IEEE"): |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
852 self.assertEqual(math.tanh(-0.), -0.) |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
853 self.assertEqual(math.copysign(1., math.tanh(-0.)), |
|
60f4456fa338
Add test for tanh(-0.) == -0. on IEEE 754 systems
Mark Dickinson <dickinsm@gmail.com>
parents:
46500
diff
changeset
|
854 math.copysign(1., -0.)) |
| 3950 | 855 |
|
45079
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
856 def test_trunc(self): |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
857 self.assertEqual(math.trunc(1), 1) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
858 self.assertEqual(math.trunc(-1), -1) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
859 self.assertEqual(type(math.trunc(1)), int) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
860 self.assertEqual(type(math.trunc(1.5)), int) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
861 self.assertEqual(math.trunc(1.5), 1) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
862 self.assertEqual(math.trunc(-1.5), -1) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
863 self.assertEqual(math.trunc(1.999999), 1) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
864 self.assertEqual(math.trunc(-1.999999), -1) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
865 self.assertEqual(math.trunc(-0.999999), -0) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
866 self.assertEqual(math.trunc(-100.999), -100) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
867 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
868 class TestTrunc(object): |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
869 def __trunc__(self): |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
870 return 23 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
871 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
872 class TestNoTrunc(object): |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
873 pass |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
874 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
875 self.assertEqual(math.trunc(TestTrunc()), 23) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
876 |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
877 self.assertRaises(TypeError, math.trunc) |
|
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
878 self.assertRaises(TypeError, math.trunc, 1, 2) |
|
62811
ee9ee2f9feb9
be more generous to implementations that have implemented correctly
Benjamin Peterson <benjamin@python.org>
parents:
62316
diff
changeset
|
879 self.assertRaises((AttributeError, TypeError), math.trunc, |
|
ee9ee2f9feb9
be more generous to implementations that have implemented correctly
Benjamin Peterson <benjamin@python.org>
parents:
62316
diff
changeset
|
880 TestNoTrunc()) |
|
45079
492b302aded6
Move __builtins__.trunc() to math.trunc() per
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44488
diff
changeset
|
881 |
|
44437
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
882 def testIsnan(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
883 self.assertTrue(math.isnan(float("nan"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
884 self.assertTrue(math.isnan(float("inf")* 0.)) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
885 self.assertFalse(math.isnan(float("inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
886 self.assertFalse(math.isnan(0.)) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
887 self.assertFalse(math.isnan(1.)) |
|
44437
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
888 |
|
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
889 def testIsinf(self): |
|
55002
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
890 self.assertTrue(math.isinf(float("inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
891 self.assertTrue(math.isinf(float("-inf"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
892 self.assertTrue(math.isinf(1E400)) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
893 self.assertTrue(math.isinf(-1E400)) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
894 self.assertFalse(math.isinf(float("nan"))) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
895 self.assertFalse(math.isinf(0.)) |
|
6768b2350c57
convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents:
53351
diff
changeset
|
896 self.assertFalse(math.isinf(1.)) |
|
44437
968bda81e6c8
Added math.isinf() and math.isnan()
Christian Heimes <christian@cheimes.de>
parents:
44432
diff
changeset
|
897 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
898 # RED_FLAG 16-Oct-2000 Tim |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
899 # While 2.0 is more consistent about exceptions than previous releases, it |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
900 # still fails this part of the test on some platforms. For now, we only |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
901 # *run* test_exceptions() in verbose mode, so that this isn't normally |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
902 # tested. |
|
15170
09c7ac188ce2
Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents:
13912
diff
changeset
|
903 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
904 if verbose: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
905 def test_exceptions(self): |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
906 try: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
907 x = math.exp(-1000000000) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
908 except: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
909 # mathmodule.c is failing to weed out underflows from libm, or |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
910 # we've got an fp format with huge dynamic range |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
911 self.fail("underflowing exp() should not have raised " |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
912 "an exception") |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
913 if x != 0: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
914 self.fail("underflowing exp() should have returned 0") |
|
15170
09c7ac188ce2
Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents:
13912
diff
changeset
|
915 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
916 # If this fails, probably using a strict IEEE-754 conforming libm, and x |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
917 # is +Inf afterwards. But Python wants overflows detected by default. |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
918 try: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
919 x = math.exp(1000000000) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
920 except OverflowError: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
921 pass |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
922 else: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
923 self.fail("overflowing exp() didn't trigger OverflowError") |
|
15170
09c7ac188ce2
Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents:
13912
diff
changeset
|
924 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
925 # If this fails, it could be a puzzle. One odd possibility is that |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
926 # mathmodule.c's macros are getting confused while comparing |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
927 # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
928 # as a result (and so raising OverflowError instead). |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
929 try: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
930 x = math.sqrt(-1.0) |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
931 except ValueError: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
932 pass |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
933 else: |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
934 self.fail("sqrt(-1) didn't raise ValueError") |
|
15170
09c7ac188ce2
Stop raising OverflowError on underflows reported by libm (errno==ERANGE and
Tim Peters <tim.peters@gmail.com>
parents:
13912
diff
changeset
|
935 |
|
56089
f2555ad5fe09
Use skipUnless to skip math module tests on non-IEEE 754 platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
55002
diff
changeset
|
936 @requires_IEEE_754 |
|
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:
45079
diff
changeset
|
937 def test_testfile(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:
45079
diff
changeset
|
938 for id, fn, ar, ai, er, ei, flags in parse_testfile(test_file): |
|
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:
45079
diff
changeset
|
939 # Skip if either the input or result is complex, or if |
|
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:
45079
diff
changeset
|
940 # flags is nonempty |
|
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:
45079
diff
changeset
|
941 if ai != 0. or ei != 0. or flags: |
|
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:
45079
diff
changeset
|
942 continue |
|
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:
45079
diff
changeset
|
943 if fn in ['rect', 'polar']: |
|
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:
45079
diff
changeset
|
944 # no real versions of rect, polar |
|
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:
45079
diff
changeset
|
945 continue |
|
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:
45079
diff
changeset
|
946 func = getattr(math, fn) |
|
46498
31ff59d984bd
Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents:
46486
diff
changeset
|
947 try: |
|
31ff59d984bd
Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents:
46486
diff
changeset
|
948 result = func(ar) |
|
31ff59d984bd
Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents:
46486
diff
changeset
|
949 except ValueError: |
|
31ff59d984bd
Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents:
46486
diff
changeset
|
950 message = ("Unexpected ValueError in " + |
|
31ff59d984bd
Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents:
46486
diff
changeset
|
951 "test %s:%s(%r)\n" % (id, fn, ar)) |
|
31ff59d984bd
Report additional diagnostic information in
Mark Dickinson <dickinsm@gmail.com>
parents:
46486
diff
changeset
|
952 self.fail(message) |
|
47218
5a29552412fa
Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
47217
diff
changeset
|
953 except OverflowError: |
|
5a29552412fa
Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
47217
diff
changeset
|
954 message = ("Unexpected OverflowError in " + |
|
5a29552412fa
Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
47217
diff
changeset
|
955 "test %s:%s(%r)\n" % (id, fn, ar)) |
|
5a29552412fa
Better error reporting in test_math.py
Mark Dickinson <dickinsm@gmail.com>
parents:
47217
diff
changeset
|
956 self.fail(message) |
|
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:
45079
diff
changeset
|
957 self.ftest("%s:%s(%r)" % (id, fn, ar), result, er) |
|
15247
dd0d199674f8
Test for math.* exceptional behavior only in verbose mode, so that the
Tim Peters <tim.peters@gmail.com>
parents:
15171
diff
changeset
|
958 |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
959 @unittest.skipUnless(float.__getformat__("double").startswith("IEEE"), |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
960 "test requires IEEE 754 doubles") |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
961 def test_mtestfile(self): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
962 ALLOWED_ERROR = 20 # permitted error, in ulps |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
963 fail_fmt = "{}:{}({!r}): expected {!r}, got {!r}" |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
964 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
965 failures = [] |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
966 for id, fn, arg, expected, flags in parse_mtestfile(math_testcases): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
967 func = getattr(math, fn) |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
968 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
969 if 'invalid' in flags or 'divide-by-zero' in flags: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
970 expected = 'ValueError' |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
971 elif 'overflow' in flags: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
972 expected = 'OverflowError' |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
973 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
974 try: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
975 got = func(arg) |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
976 except ValueError: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
977 got = 'ValueError' |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
978 except OverflowError: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
979 got = 'OverflowError' |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
980 |
|
57655
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
981 accuracy_failure = None |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
982 if isinstance(got, float) and isinstance(expected, float): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
983 if math.isnan(expected) and math.isnan(got): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
984 continue |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
985 if not math.isnan(expected) and not math.isnan(got): |
|
57756
b206ad8cf5bf
Issue #3366: Add expm1 function to math module. Thanks Eric Smith for
Mark Dickinson <dickinsm@gmail.com>
parents:
57655
diff
changeset
|
986 if fn == 'lgamma': |
|
b206ad8cf5bf
Issue #3366: Add expm1 function to math module. Thanks Eric Smith for
Mark Dickinson <dickinsm@gmail.com>
parents:
57655
diff
changeset
|
987 # we use a weaker accuracy test for lgamma; |
|
b206ad8cf5bf
Issue #3366: Add expm1 function to math module. Thanks Eric Smith for
Mark Dickinson <dickinsm@gmail.com>
parents:
57655
diff
changeset
|
988 # lgamma only achieves an absolute error of |
|
b206ad8cf5bf
Issue #3366: Add expm1 function to math module. Thanks Eric Smith for
Mark Dickinson <dickinsm@gmail.com>
parents:
57655
diff
changeset
|
989 # a few multiples of the machine accuracy, in |
|
b206ad8cf5bf
Issue #3366: Add expm1 function to math module. Thanks Eric Smith for
Mark Dickinson <dickinsm@gmail.com>
parents:
57655
diff
changeset
|
990 # general. |
|
57655
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
991 accuracy_failure = acc_check(expected, got, |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
992 rel_err = 5e-15, |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
993 abs_err = 5e-15) |
|
62316
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
994 elif fn == 'erfc': |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
995 # erfc has less-than-ideal accuracy for large |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
996 # arguments (x ~ 25 or so), mainly due to the |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
997 # error involved in computing exp(-x*x). |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
998 # |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
999 # XXX Would be better to weaken this test only |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
1000 # for large x, instead of for all x. |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
1001 accuracy_failure = ulps_check(expected, got, 2000) |
|
cff0a923140b
Issue #8986: erfc was raising OverflowError on Linux for arguments in
Mark Dickinson <dickinsm@gmail.com>
parents:
61539
diff
changeset
|
1002 |
|
57655
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
1003 else: |
|
57756
b206ad8cf5bf
Issue #3366: Add expm1 function to math module. Thanks Eric Smith for
Mark Dickinson <dickinsm@gmail.com>
parents:
57655
diff
changeset
|
1004 accuracy_failure = ulps_check(expected, got, 20) |
|
57655
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
1005 if accuracy_failure is None: |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1006 continue |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1007 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1008 if isinstance(got, str) and isinstance(expected, str): |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1009 if got == expected: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1010 continue |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1011 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1012 fail_msg = fail_fmt.format(id, fn, arg, expected, got) |
|
57655
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
1013 if accuracy_failure is not None: |
|
cb22eaee86c9
Issue #3366: Add lgamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56556
diff
changeset
|
1014 fail_msg += ' ({})'.format(accuracy_failure) |
|
56268
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1015 failures.append(fail_msg) |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1016 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1017 if failures: |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1018 self.fail('Failures in test_mtestfile:\n ' + |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1019 '\n '.join(failures)) |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1020 |
|
b50dd17dfe26
Issue #3366: Add gamma function to math module.
Mark Dickinson <dickinsm@gmail.com>
parents:
56089
diff
changeset
|
1021 |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
1022 def test_main(): |
|
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:
45079
diff
changeset
|
1023 from doctest import DocFileSuite |
|
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:
45079
diff
changeset
|
1024 suite = unittest.TestSuite() |
|
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:
45079
diff
changeset
|
1025 suite.addTest(unittest.makeSuite(MathTests)) |
|
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:
45079
diff
changeset
|
1026 suite.addTest(DocFileSuite("ieee754.txt")) |
|
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:
45079
diff
changeset
|
1027 run_unittest(suite) |
|
40219
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
1028 |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
1029 if __name__ == '__main__': |
|
69728a7d2312
Convert test_math to unittest.
Georg Brandl <georg@python.org>
parents:
31515
diff
changeset
|
1030 test_main() |
