authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-06 02:58:45-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-06 02:58:45-05:00
logdde7cc52d2f4780587b37604889c4568b8d79c62
tree05e56622db118a83d82233c52140266f47527f37
parent17e68c4a11ee44dbaf32f5d17abc30aa107a0a2d

fix exp1m implementation

in the llvm6 branch with assertions on, it failed the test this fixes it

1 files changed, 7 insertions(+), 4 deletions(-)

std/math/expm1.zig+7-4
......@@ -4,6 +4,7 @@
44// - expm1(-inf) = -1
55// - expm1(nan) = nan
66
7const builtin = @import("builtin");
78const std = @import("../index.zig");
89const math = std.math;
910const assert = std.debug.assert;
......@@ -18,6 +19,7 @@ pub fn expm1(x: var) -> @typeOf(x) {
1819}
1920
2021fn expm1_32(x_: f32) -> f32 {
22 @setFloatMode(this, builtin.FloatMode.Strict);
2123 const o_threshold: f32 = 8.8721679688e+01;
2224 const ln2_hi: f32 = 6.9313812256e-01;
2325 const ln2_lo: f32 = 9.0580006145e-06;
......@@ -122,7 +124,7 @@ fn expm1_32(x_: f32) -> f32 {
122124 }
123125 }
124126
125 const twopk = @bitCast(f32, u32((0x7F + k) << 23));
127 const twopk = @bitCast(f32, u32((0x7F +% k) << 23));
126128
127129 if (k < 0 or k > 56) {
128130 var y = x - e + 1.0;
......@@ -135,7 +137,7 @@ fn expm1_32(x_: f32) -> f32 {
135137 return y - 1.0;
136138 }
137139
138 const uf = @bitCast(f32, u32(0x7F - k) << 23);
140 const uf = @bitCast(f32, u32(0x7F -% k) << 23);
139141 if (k < 23) {
140142 return (x - e + (1 - uf)) * twopk;
141143 } else {
......@@ -144,6 +146,7 @@ fn expm1_32(x_: f32) -> f32 {
144146}
145147
146148fn expm1_64(x_: f64) -> f64 {
149 @setFloatMode(this, builtin.FloatMode.Strict);
147150 const o_threshold: f64 = 7.09782712893383973096e+02;
148151 const ln2_hi: f64 = 6.93147180369123816490e-01;
149152 const ln2_lo: f64 = 1.90821492927058770002e-10;
......@@ -251,7 +254,7 @@ fn expm1_64(x_: f64) -> f64 {
251254 }
252255 }
253256
254 const twopk = @bitCast(f64, u64(0x3FF + k) << 52);
257 const twopk = @bitCast(f64, u64(0x3FF +% k) << 52);
255258
256259 if (k < 0 or k > 56) {
257260 var y = x - e + 1.0;
......@@ -264,7 +267,7 @@ fn expm1_64(x_: f64) -> f64 {
264267 return y - 1.0;
265268 }
266269
267 const uf = @bitCast(f64, u64(0x3FF - k) << 52);
270 const uf = @bitCast(f64, u64(0x3FF -% k) << 52);
268271 if (k < 20) {
269272 return (x - e + (1 - uf)) * twopk;
270273 } else {