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