From 411e9ca4ade243344f358b14151e87e2334e76a0 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Fri, 15 Oct 2021 13:55:40 -0400 Subject: [PATCH] Fix bug where std.math.asinh64 doesn't respect signedness for negative values (#9940) * std: Correct math.asinh64 to return correct signedness for negative values * std: Add tests for negative values for math.asinh32 and math.asinh64 --- lib/std/math/asinh.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/std/math/asinh.zig b/lib/std/math/asinh.zig index 71f7533b8924cb8065f3e657726bf4e4b64d1157..8717ebbb66d0c236602a83d0a4b9d9ab9f8735ed 100644 --- a/lib/std/math/asinh.zig +++ b/lib/std/math/asinh.zig @@ -60,7 +60,7 @@ fn asinh32(x: f32) f32 { fn asinh64(x: f64) f64 { const u = @bitCast(u64, x); const e = (u >> 52) & 0x7FF; - const s = u >> 63; + const s = e >> 63; var rx = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x| @@ -97,6 +97,7 @@ test "math.asinh32" { const epsilon = 0.000001; try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon)); + try expect(math.approxEqAbs(f32, asinh32(-0.2), -0.198690, epsilon)); try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon)); try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon)); try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon)); @@ -109,6 +110,7 @@ test "math.asinh64" { const epsilon = 0.000001; try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon)); + try expect(math.approxEqAbs(f64, asinh64(-0.2), -0.198690, epsilon)); try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon)); try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon)); try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon)); -- 2.54.0