| ... | @@ -4,6 +4,7 @@ | ... | @@ -4,6 +4,7 @@ |
| 4 | // - expm1(-inf) = -1 | 4 | // - expm1(-inf) = -1 |
| 5 | // - expm1(nan) = nan | 5 | // - expm1(nan) = nan |
| 6 | | 6 | |
| | 7 | const builtin = @import("builtin"); |
| 7 | const std = @import("../index.zig"); | 8 | const std = @import("../index.zig"); |
| 8 | const math = std.math; | 9 | const math = std.math; |
| 9 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| ... | @@ -18,6 +19,7 @@ pub fn expm1(x: var) -> @typeOf(x) { | ... | @@ -18,6 +19,7 @@ pub fn expm1(x: var) -> @typeOf(x) { |
| 18 | } | 19 | } |
| 19 | | 20 | |
| 20 | fn expm1_32(x_: f32) -> f32 { | 21 | fn expm1_32(x_: f32) -> f32 { |
| | 22 | @setFloatMode(this, builtin.FloatMode.Strict); |
| 21 | const o_threshold: f32 = 8.8721679688e+01; | 23 | const o_threshold: f32 = 8.8721679688e+01; |
| 22 | const ln2_hi: f32 = 6.9313812256e-01; | 24 | const ln2_hi: f32 = 6.9313812256e-01; |
| 23 | const ln2_lo: f32 = 9.0580006145e-06; | 25 | const ln2_lo: f32 = 9.0580006145e-06; |
| ... | @@ -122,7 +124,7 @@ fn expm1_32(x_: f32) -> f32 { | ... | @@ -122,7 +124,7 @@ fn expm1_32(x_: f32) -> f32 { |
| 122 | } | 124 | } |
| 123 | } | 125 | } |
| 124 | | 126 | |
| 125 | const twopk = @bitCast(f32, u32((0x7F + k) << 23)); | 127 | const twopk = @bitCast(f32, u32((0x7F +% k) << 23)); |
| 126 | | 128 | |
| 127 | if (k < 0 or k > 56) { | 129 | if (k < 0 or k > 56) { |
| 128 | var y = x - e + 1.0; | 130 | var y = x - e + 1.0; |
| ... | @@ -135,7 +137,7 @@ fn expm1_32(x_: f32) -> f32 { | ... | @@ -135,7 +137,7 @@ fn expm1_32(x_: f32) -> f32 { |
| 135 | return y - 1.0; | 137 | return y - 1.0; |
| 136 | } | 138 | } |
| 137 | | 139 | |
| 138 | const uf = @bitCast(f32, u32(0x7F - k) << 23); | 140 | const uf = @bitCast(f32, u32(0x7F -% k) << 23); |
| 139 | if (k < 23) { | 141 | if (k < 23) { |
| 140 | return (x - e + (1 - uf)) * twopk; | 142 | return (x - e + (1 - uf)) * twopk; |
| 141 | } else { | 143 | } else { |
| ... | @@ -144,6 +146,7 @@ fn expm1_32(x_: f32) -> f32 { | ... | @@ -144,6 +146,7 @@ fn expm1_32(x_: f32) -> f32 { |
| 144 | } | 146 | } |
| 145 | | 147 | |
| 146 | fn expm1_64(x_: f64) -> f64 { | 148 | fn expm1_64(x_: f64) -> f64 { |
| | 149 | @setFloatMode(this, builtin.FloatMode.Strict); |
| 147 | const o_threshold: f64 = 7.09782712893383973096e+02; | 150 | const o_threshold: f64 = 7.09782712893383973096e+02; |
| 148 | const ln2_hi: f64 = 6.93147180369123816490e-01; | 151 | const ln2_hi: f64 = 6.93147180369123816490e-01; |
| 149 | const ln2_lo: f64 = 1.90821492927058770002e-10; | 152 | const ln2_lo: f64 = 1.90821492927058770002e-10; |
| ... | @@ -251,7 +254,7 @@ fn expm1_64(x_: f64) -> f64 { | ... | @@ -251,7 +254,7 @@ fn expm1_64(x_: f64) -> f64 { |
| 251 | } | 254 | } |
| 252 | } | 255 | } |
| 253 | | 256 | |
| 254 | const twopk = @bitCast(f64, u64(0x3FF + k) << 52); | 257 | const twopk = @bitCast(f64, u64(0x3FF +% k) << 52); |
| 255 | | 258 | |
| 256 | if (k < 0 or k > 56) { | 259 | if (k < 0 or k > 56) { |
| 257 | var y = x - e + 1.0; | 260 | var y = x - e + 1.0; |
| ... | @@ -264,7 +267,7 @@ fn expm1_64(x_: f64) -> f64 { | ... | @@ -264,7 +267,7 @@ fn expm1_64(x_: f64) -> f64 { |
| 264 | return y - 1.0; | 267 | return y - 1.0; |
| 265 | } | 268 | } |
| 266 | | 269 | |
| 267 | const uf = @bitCast(f64, u64(0x3FF - k) << 52); | 270 | const uf = @bitCast(f64, u64(0x3FF -% k) << 52); |
| 268 | if (k < 20) { | 271 | if (k < 20) { |
| 269 | return (x - e + (1 - uf)) * twopk; | 272 | return (x - e + (1 - uf)) * twopk; |
| 270 | } else { | 273 | } else { |