| author | |
| committer | |
| log | 14a324a0fa8d60dbf7d6948a992a09d8a65cbdc4 |
| tree | 2ddb5dd971975ed0726e7946f92426f6d5d7b171 |
| parent | dfa2d11167db31e3b490c7d37633871fef4f2d52 |
7 files changed, 27 insertions(+), 16 deletions(-)
std/math/exp.zig+8-1| ... | ... | @@ -31,6 +31,10 @@ fn exp32(x_: f32) -> f32 { |
| 31 | 31 | const sign = i32(hx >> 31); |
| 32 | 32 | hx &= 0x7FFFFFFF; |
| 33 | 33 | |
| 34 | if (math.isNan(x)) { | |
| 35 | return x; | |
| 36 | } | |
| 37 | ||
| 34 | 38 | // |x| >= -87.33655 or nan |
| 35 | 39 | if (hx >= 0x42AEAC50) { |
| 36 | 40 | // nan |
| ... | ... | @@ -108,6 +112,10 @@ fn exp64(x_: f64) -> f64 { |
| 108 | 112 | const sign = i32(hx >> 31); |
| 109 | 113 | hx &= 0x7FFFFFFF; |
| 110 | 114 | |
| 115 | if (math.isNan(x)) { | |
| 116 | return x; | |
| 117 | } | |
| 118 | ||
| 111 | 119 | // |x| >= 708.39 or nan |
| 112 | 120 | if (hx >= 0x4086232B) { |
| 113 | 121 | // nan |
| ... | ... | @@ -204,7 +212,6 @@ test "math.exp32.special" { |
| 204 | 212 | } |
| 205 | 213 | |
| 206 | 214 | test "math.exp64.special" { |
| 207 | // TODO: Error on release (like pow) | |
| 208 | 215 | assert(math.isPositiveInf(exp64(math.inf(f64)))); |
| 209 | 216 | assert(math.isNan(exp64(math.nan(f64)))); |
| 210 | 217 | } |
std/math/expm1.zig+1-1| ... | ... | @@ -258,7 +258,7 @@ fn expm1_64(x_: f64) -> f64 { |
| 258 | 258 | if (k < 0 or k > 56) { |
| 259 | 259 | var y = x - e + 1.0; |
| 260 | 260 | if (k == 1024) { |
| 261 | y = y * 2.0; // TODO: * 0x1.0p1023; | |
| 261 | y = y * 2.0 * 0x1.0p1022 * 10; | |
| 262 | 262 | } else { |
| 263 | 263 | y = y * twopk; |
| 264 | 264 | } |
std/math/frexp.zig+1-2| ... | ... | @@ -77,8 +77,8 @@ fn frexp64(x: f64) -> frexp64_result { |
| 77 | 77 | } |
| 78 | 78 | return result; |
| 79 | 79 | } else if (e == 0x7FF) { |
| 80 | // frexp(nan) = (nan, 0) | |
| 81 | 80 | result.significand = x; |
| 81 | result.exponent = 0; | |
| 82 | 82 | return result; |
| 83 | 83 | } |
| 84 | 84 | |
| ... | ... | @@ -141,7 +141,6 @@ test "math.frexp32.special" { |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | test "math.frexp64.special" { |
| 144 | // TODO: Error on release mode (like pow) | |
| 145 | 144 | var r: frexp64_result = undefined; |
| 146 | 145 | |
| 147 | 146 | r = frexp64(0.0); |
std/math/pow.zig-1| ... | ... | @@ -179,7 +179,6 @@ fn isOddInteger(x: f64) -> bool { |
| 179 | 179 | test "math.pow" { |
| 180 | 180 | const epsilon = 0.000001; |
| 181 | 181 | |
| 182 | // TODO: Error on release | |
| 183 | 182 | assert(math.approxEq(f32, pow(f32, 0.0, 3.3), 0.0, epsilon)); |
| 184 | 183 | assert(math.approxEq(f32, pow(f32, 0.8923, 3.3), 0.686572, epsilon)); |
| 185 | 184 | assert(math.approxEq(f32, pow(f32, 0.2, 3.3), 0.004936, epsilon)); |
std/math/scalbn.zig+2-3| ... | ... | @@ -48,11 +48,10 @@ fn scalbn64(x: f64, n_: i32) -> f64 { |
| 48 | 48 | var n = n_; |
| 49 | 49 | |
| 50 | 50 | if (n > 1023) { |
| 51 | // TODO: Determine how to do the following. | |
| 52 | // y *= 0x1.0p1023; | |
| 51 | y *= 0x1.0p1022 * 10.0; | |
| 53 | 52 | n -= 1023; |
| 54 | 53 | if (n > 1023) { |
| 55 | // y *= 0x1.0p1023; | |
| 54 | y *= 0x1.0p1022 * 10.0; | |
| 56 | 55 | n -= 1023; |
| 57 | 56 | if (n > 1023) { |
| 58 | 57 | n = 1023; |
std/math/sinh.zig+8-1| ... | ... | @@ -28,6 +28,10 @@ fn sinh32(x: f32) -> f32 { |
| 28 | 28 | const ux = u & 0x7FFFFFFF; |
| 29 | 29 | const ax = @bitCast(f32, ux); |
| 30 | 30 | |
| 31 | if (x == 0.0 or math.isNan(x)) { | |
| 32 | return x; | |
| 33 | } | |
| 34 | ||
| 31 | 35 | var h: f32 = 0.5; |
| 32 | 36 | if (u >> 31 != 0) { |
| 33 | 37 | h = -h; |
| ... | ... | @@ -57,6 +61,10 @@ fn sinh64(x: f64) -> f64 { |
| 57 | 61 | const w = u32(u >> 32); |
| 58 | 62 | const ax = @bitCast(f64, u & (@maxValue(u64) >> 1)); |
| 59 | 63 | |
| 64 | if (x == 0.0 or math.isNan(x)) { | |
| 65 | return x; | |
| 66 | } | |
| 67 | ||
| 60 | 68 | var h: f32 = 0.5; |
| 61 | 69 | if (u >> 63 != 0) { |
| 62 | 70 | h = -h; |
| ... | ... | @@ -112,7 +120,6 @@ test "math.sinh32.special" { |
| 112 | 120 | } |
| 113 | 121 | |
| 114 | 122 | test "math.sinh64.special" { |
| 115 | // TODO: Error on release mode (like pow) | |
| 116 | 123 | assert(sinh64(0.0) == 0.0); |
| 117 | 124 | assert(sinh64(-0.0) == -0.0); |
| 118 | 125 | assert(math.isPositiveInf(sinh64(math.inf(f64)))); |
std/math/tanh.zig+7-7| ... | ... | @@ -30,11 +30,15 @@ fn tanh32(x: f32) -> f32 { |
| 30 | 30 | |
| 31 | 31 | var t: f32 = undefined; |
| 32 | 32 | |
| 33 | if (x == 0.0 or math.isNan(x)) { | |
| 34 | return x; | |
| 35 | } | |
| 36 | ||
| 33 | 37 | // |x| < log(3) / 2 ~= 0.5493 or nan |
| 34 | 38 | if (ux > 0x3F0C9F54) { |
| 35 | 39 | // |x| > 10 |
| 36 | 40 | if (ux > 0x41200000) { |
| 37 | t = 1.0 + 0 / x; | |
| 41 | t = 1.0; | |
| 38 | 42 | } else { |
| 39 | 43 | t = math.expm1(2 * x); |
| 40 | 44 | t = 1 - 2 / (t + 2); |
| ... | ... | @@ -71,10 +75,7 @@ fn tanh64(x: f64) -> f64 { |
| 71 | 75 | var t: f64 = undefined; |
| 72 | 76 | |
| 73 | 77 | // TODO: Shouldn't need these checks. |
| 74 | if (x == 0.0) { | |
| 75 | return x; | |
| 76 | } | |
| 77 | if (math.isNan(x)) { | |
| 78 | if (x == 0.0 or math.isNan(x)) { | |
| 78 | 79 | return x; |
| 79 | 80 | } |
| 80 | 81 | |
| ... | ... | @@ -82,7 +83,7 @@ fn tanh64(x: f64) -> f64 { |
| 82 | 83 | if (w > 0x3FE193EA) { |
| 83 | 84 | // |x| > 20 or nan |
| 84 | 85 | if (w > 0x40340000) { |
| 85 | t = 1.0; // TODO + 0 / x; | |
| 86 | t = 1.0; | |
| 86 | 87 | } else { |
| 87 | 88 | t = math.expm1(2 * x); |
| 88 | 89 | t = 1 - 2 / (t + 2); |
| ... | ... | @@ -137,7 +138,6 @@ test "math.tanh64" { |
| 137 | 138 | } |
| 138 | 139 | |
| 139 | 140 | test "math.tanh32.special" { |
| 140 | // TODO: Error on release (like pow) | |
| 141 | 141 | assert(tanh32(0.0) == 0.0); |
| 142 | 142 | assert(tanh32(-0.0) == -0.0); |
| 143 | 143 | assert(tanh32(math.inf(f32)) == 1.0); |