authorgravatar for m@milesalan.comMiles Alan <m@milesalan.com> 2021-10-15 13:55:40-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-10-15 13:55:40-04:00
log411e9ca4ade243344f358b14151e87e2334e76a0
tree03af0a3d229ad72e4ae1e2483e29a9ee66176f13
parentf3ab092f67d5705ce3c70c0033e463b68523c8bd
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

1 files changed, 3 insertions(+), 1 deletions(-)

lib/std/math/asinh.zig+3-1
...@@ -60,7 +60,7 @@ fn asinh32(x: f32) f32 {...@@ -60,7 +60,7 @@ fn asinh32(x: f32) f32 {
60fn asinh64(x: f64) f64 {60fn asinh64(x: f64) f64 {
61 const u = @bitCast(u64, x);61 const u = @bitCast(u64, x);
62 const e = (u >> 52) & 0x7FF;62 const e = (u >> 52) & 0x7FF;
63 const s = u >> 63;63 const s = e >> 63;
6464
65 var rx = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|65 var rx = @bitCast(f64, u & (maxInt(u64) >> 1)); // |x|
6666
...@@ -97,6 +97,7 @@ test "math.asinh32" {...@@ -97,6 +97,7 @@ test "math.asinh32" {
97 const epsilon = 0.000001;97 const epsilon = 0.000001;
9898
99 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));99 try expect(math.approxEqAbs(f32, asinh32(0.0), 0.0, epsilon));
100 try expect(math.approxEqAbs(f32, asinh32(-0.2), -0.198690, epsilon));
100 try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));101 try expect(math.approxEqAbs(f32, asinh32(0.2), 0.198690, epsilon));
101 try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));102 try expect(math.approxEqAbs(f32, asinh32(0.8923), 0.803133, epsilon));
102 try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));103 try expect(math.approxEqAbs(f32, asinh32(1.5), 1.194763, epsilon));
...@@ -109,6 +110,7 @@ test "math.asinh64" {...@@ -109,6 +110,7 @@ test "math.asinh64" {
109 const epsilon = 0.000001;110 const epsilon = 0.000001;
110111
111 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));112 try expect(math.approxEqAbs(f64, asinh64(0.0), 0.0, epsilon));
113 try expect(math.approxEqAbs(f64, asinh64(-0.2), -0.198690, epsilon));
112 try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));114 try expect(math.approxEqAbs(f64, asinh64(0.2), 0.198690, epsilon));
113 try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));115 try expect(math.approxEqAbs(f64, asinh64(0.8923), 0.803133, epsilon));
114 try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));116 try expect(math.approxEqAbs(f64, asinh64(1.5), 1.194763, epsilon));