|
10 | 10 | nan = float("nan")
|
11 | 11 |
|
12 | 12 | # single argument functions
|
13 |
| -for name, f, args in ( |
14 |
| - ("fabs", math.fabs, ()), |
15 |
| - ("ceil", math.ceil, ()), |
16 |
| - ("floor", math.floor, ()), |
17 |
| - ("trunc", math.trunc, ()), |
18 |
| - ("sqrt", math.sqrt, (-1, 0)), |
19 |
| - ("exp", math.exp, ()), |
20 |
| - ("log", math.log, ()), |
21 |
| - ("sin", math.sin, ()), |
22 |
| - ("cos", math.cos, ()), |
23 |
| - ("tan", math.tan, ()), |
24 |
| - ("asin", math.asin, (-1.1, 1, 1.1)), |
25 |
| - ("acos", math.acos, (-1.1, 1, 1.1)), |
26 |
| - ("atan", math.atan, ()), |
27 |
| - ("ldexp", lambda x: math.ldexp(x, 0), ()), |
28 |
| - ("radians", math.radians, ()), |
29 |
| - ("degrees", math.degrees, ()), |
| 13 | +for name, f in ( |
| 14 | + ("fabs", math.fabs), |
| 15 | + ("ceil", math.ceil), |
| 16 | + ("floor", math.floor), |
| 17 | + ("trunc", math.trunc), |
| 18 | + ("sqrt", math.sqrt), |
| 19 | + ("exp", math.exp), |
| 20 | + ("log", math.log), |
| 21 | + ("sin", math.sin), |
| 22 | + ("cos", math.cos), |
| 23 | + ("tan", math.tan), |
| 24 | + ("asin", math.asin), |
| 25 | + ("acos", math.acos), |
| 26 | + ("atan", math.atan), |
| 27 | + ("ldexp", lambda x: math.ldexp(x, 0)), |
| 28 | + ("radians", math.radians), |
| 29 | + ("degrees", math.degrees), |
30 | 30 | ):
|
31 |
| - for x in args + (inf, -inf, nan): |
| 31 | + for x in (0, 1, 1.1, -1, -1.1, inf, -inf, nan): |
32 | 32 | try:
|
33 | 33 | ans = "%.4f" % f(x)
|
34 | 34 | except ValueError:
|
|
38 | 38 | print("%s(%.4f) = %s" % (name, x, ans))
|
39 | 39 |
|
40 | 40 | # double argument functions
|
41 |
| -for name, f, args in ( |
42 |
| - ( |
43 |
| - "pow", |
44 |
| - math.pow, |
45 |
| - ( |
46 |
| - (0, 2), |
47 |
| - (-1, 2), |
48 |
| - (0, -1), |
49 |
| - (-1, 2.3), |
50 |
| - (0.5, inf), |
51 |
| - (-0.5, inf), |
52 |
| - (0.5, -inf), |
53 |
| - (-0.5, -inf), |
54 |
| - (1.5, inf), |
55 |
| - (-1.5, inf), |
56 |
| - (1.5, -inf), |
57 |
| - (-1.5, -inf), |
58 |
| - (nan, 0), |
59 |
| - (1, nan), |
60 |
| - ), |
61 |
| - ), |
62 |
| - ("log", math.log, ()), |
63 |
| - ("fmod", math.fmod, ((1.2, inf), (1.2, -inf), (1.2, 0), (inf, 1.2))), |
64 |
| - ("atan2", math.atan2, ((0, 0), (-inf, inf), (-inf, -inf), (inf, -inf))), |
65 |
| - ("copysign", math.copysign, ()), |
| 41 | +for name, f in ( |
| 42 | + ("pow", math.pow), |
| 43 | + ("log", math.log), |
| 44 | + ("fmod", math.fmod), |
| 45 | + ("atan2", math.atan2), |
| 46 | + ("copysign", math.copysign), |
66 | 47 | ):
|
67 |
| - for x in args + ((0, inf), (inf, 0), (inf, inf), (inf, nan), (nan, inf), (nan, nan)): |
| 48 | + for x in ( |
| 49 | + (0, 0), |
| 50 | + (0, 2), |
| 51 | + (0, -1), |
| 52 | + (1, 0), |
| 53 | + (1.2, 0), |
| 54 | + (-1, 0), |
| 55 | + (-1, 2), |
| 56 | + (-1, 2.3), |
| 57 | + (0, inf), |
| 58 | + (0.5, inf), |
| 59 | + (0.5, -inf), |
| 60 | + (0.9, inf), |
| 61 | + (0.9, -inf), |
| 62 | + (1.2, inf), |
| 63 | + (1.2, -inf), |
| 64 | + (-0.5, inf), |
| 65 | + (-0.5, -inf), |
| 66 | + (-0.9, inf), |
| 67 | + (-0.9, -inf), |
| 68 | + (-1.2, inf), |
| 69 | + (-1.2, -inf), |
| 70 | + (inf, 0), |
| 71 | + (inf, 1.2), |
| 72 | + (inf, -1.2), |
| 73 | + (inf, inf), |
| 74 | + (inf, -inf), |
| 75 | + (-inf, inf), |
| 76 | + (-inf, -inf), |
| 77 | + (0, nan), |
| 78 | + (nan, 0), |
| 79 | + (1, nan), |
| 80 | + (nan, 1), |
| 81 | + (inf, nan), |
| 82 | + (nan, inf), |
| 83 | + (nan, nan), |
| 84 | + ): |
68 | 85 | try:
|
69 | 86 | ans = "%.4f" % f(*x)
|
70 | 87 | except ValueError:
|
71 | 88 | ans = "ValueError"
|
| 89 | + except ZeroDivisionError: |
| 90 | + ans = "ZeroDivisionError" |
72 | 91 | print("%s(%.4f, %.4f) = %s" % (name, x[0], x[1], ans))
|
0 commit comments