|
1 | 1 | import math |
2 | 2 | from testutils import assert_raises |
3 | 3 |
|
| 4 | +NAN = float('nan') |
| 5 | +INF = float('inf') |
| 6 | +NINF = float('-inf') |
| 7 | + |
4 | 8 | # assert(math.exp(2) == math.exp(2.0)) |
5 | 9 | # assert(math.exp(True) == math.exp(1.0)) |
6 | 10 | # |
|
30 | 34 | assert math.ceil(3.3) == 4 |
31 | 35 | assert math.floor(4.4) == 4 |
32 | 36 |
|
| 37 | +assert math.copysign(1, 42) == 1.0 |
| 38 | +assert math.copysign(0., 42) == 0.0 |
| 39 | +assert math.copysign(1., -42) == -1.0 |
| 40 | +assert math.copysign(3, 0.) == 3.0 |
| 41 | +assert math.copysign(4., -0.) == -4.0 |
| 42 | +assert_raises(TypeError, math.copysign) |
| 43 | +# copysign should let us distinguish signs of zeros |
| 44 | +assert math.copysign(1., 0.) == 1. |
| 45 | +assert math.copysign(1., -0.) == -1. |
| 46 | +assert math.copysign(INF, 0.) == INF |
| 47 | +assert math.copysign(INF, -0.) == NINF |
| 48 | +assert math.copysign(NINF, 0.) == INF |
| 49 | +assert math.copysign(NINF, -0.) == NINF |
| 50 | +# and of infinities |
| 51 | +assert math.copysign(1., INF) == 1. |
| 52 | +assert math.copysign(1., NINF) == -1. |
| 53 | +assert math.copysign(INF, INF) == INF |
| 54 | +assert math.copysign(INF, NINF) == NINF |
| 55 | +assert math.copysign(NINF, INF) == INF |
| 56 | +assert math.copysign(NINF, NINF) == NINF |
| 57 | +assert math.isnan(math.copysign(NAN, 1.)) |
| 58 | +assert math.isnan(math.copysign(NAN, INF)) |
| 59 | +assert math.isnan(math.copysign(NAN, NINF)) |
| 60 | +assert math.isnan(math.copysign(NAN, NAN)) |
| 61 | +# copysign(INF, NAN) may be INF or it may be NINF, since |
| 62 | +# we don't know whether the sign bit of NAN is set on any |
| 63 | +# given platform. |
| 64 | +assert math.isinf(math.copysign(INF, NAN)) |
| 65 | +# similarly, copysign(2., NAN) could be 2. or -2. |
| 66 | +assert abs(math.copysign(2., NAN)) == 2. |
| 67 | + |
33 | 68 | class A(object): |
34 | 69 | def __trunc__(self): |
35 | 70 | return 2 |
@@ -91,8 +126,8 @@ def __floor__(self): |
91 | 126 | assert math.ldexp(0.75, 1) == 1.5 |
92 | 127 | assert_raises(TypeError, lambda: math.ldexp(None, None)) |
93 | 128 |
|
94 | | -assert math.frexp(float('inf')) == (float('inf'), 0) |
95 | | -assert str(math.frexp(float('nan'))) == str((float('nan'), 0)) |
| 129 | +assert math.frexp(INF) == (INF, 0) |
| 130 | +assert str(math.frexp(NAN)) == str((NAN, 0)) |
96 | 131 | assert_raises(TypeError, lambda: math.frexp(None)) |
97 | 132 |
|
98 | 133 | assert math.gcd(0, 0) == 0 |
|
0 commit comments