Skip to content

Commit

Permalink
fix exp1m implementation
Browse files Browse the repository at this point in the history
in the llvm6 branch with assertions on, it failed the test
this fixes it
  • Loading branch information
andrewrk committed Jan 6, 2018
1 parent 17e68c4 commit dde7cc5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions std/math/expm1.zig
Expand Up @@ -4,6 +4,7 @@
// - expm1(-inf) = -1
// - expm1(nan) = nan

const builtin = @import("builtin");
const std = @import("../index.zig");
const math = std.math;
const assert = std.debug.assert;
Expand All @@ -18,6 +19,7 @@ pub fn expm1(x: var) -> @typeOf(x) {
}

fn expm1_32(x_: f32) -> f32 {
@setFloatMode(this, builtin.FloatMode.Strict);
const o_threshold: f32 = 8.8721679688e+01;
const ln2_hi: f32 = 6.9313812256e-01;
const ln2_lo: f32 = 9.0580006145e-06;
Expand Down Expand Up @@ -122,7 +124,7 @@ fn expm1_32(x_: f32) -> f32 {
}
}

const twopk = @bitCast(f32, u32((0x7F + k) << 23));
const twopk = @bitCast(f32, u32((0x7F +% k) << 23));

if (k < 0 or k > 56) {
var y = x - e + 1.0;
Expand All @@ -135,7 +137,7 @@ fn expm1_32(x_: f32) -> f32 {
return y - 1.0;
}

const uf = @bitCast(f32, u32(0x7F - k) << 23);
const uf = @bitCast(f32, u32(0x7F -% k) << 23);
if (k < 23) {
return (x - e + (1 - uf)) * twopk;
} else {
Expand All @@ -144,6 +146,7 @@ fn expm1_32(x_: f32) -> f32 {
}

fn expm1_64(x_: f64) -> f64 {
@setFloatMode(this, builtin.FloatMode.Strict);
const o_threshold: f64 = 7.09782712893383973096e+02;
const ln2_hi: f64 = 6.93147180369123816490e-01;
const ln2_lo: f64 = 1.90821492927058770002e-10;
Expand Down Expand Up @@ -251,7 +254,7 @@ fn expm1_64(x_: f64) -> f64 {
}
}

const twopk = @bitCast(f64, u64(0x3FF + k) << 52);
const twopk = @bitCast(f64, u64(0x3FF +% k) << 52);

if (k < 0 or k > 56) {
var y = x - e + 1.0;
Expand All @@ -264,7 +267,7 @@ fn expm1_64(x_: f64) -> f64 {
return y - 1.0;
}

const uf = @bitCast(f64, u64(0x3FF - k) << 52);
const uf = @bitCast(f64, u64(0x3FF -% k) << 52);
if (k < 20) {
return (x - e + (1 - uf)) * twopk;
} else {
Expand Down

0 comments on commit dde7cc5

Please sign in to comment.