authorgravatar for 112150142+lsculv@users.noreply.github.comLucas Culverhouse <112150142+lsculv@users.noreply.github.com> 2023-09-12 11:39:34-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-09-12 18:39:34+00:00
log5b7eefce4696e68132a0e8d5a0be4d0ae87dc6f7
treef399d5c72bae6b7d71d2ec02e6e165f0e49f189c
parent402468b2109929779fc0fb59eeb5481cfb5ed44d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std.math.cbrt: fixed -0.0 evaluating to 0.0


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

lib/std/math/cbrt.zig+4-4
......@@ -87,9 +87,9 @@ fn cbrt64(x: f64) f64 {
8787 u = @as(u64, @bitCast(x * 0x1.0p54));
8888 hx = @as(u32, @intCast(u >> 32)) & 0x7FFFFFFF;
8989
90 // cbrt(0) is itself
90 // cbrt(+-0) = itself
9191 if (hx == 0) {
92 return 0;
92 return x;
9393 }
9494 hx = hx / 3 + B2;
9595 } else {
......@@ -148,7 +148,7 @@ test "math.cbrt64" {
148148
149149test "math.cbrt.special" {
150150 try expect(cbrt32(0.0) == 0.0);
151 try expect(cbrt32(-0.0) == -0.0);
151 try expect(@as(u32, @bitCast(cbrt32(-0.0))) == @as(u32, 0x80000000));
152152 try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
153153 try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
154154 try expect(math.isNan(cbrt32(math.nan(f32))));
......@@ -156,7 +156,7 @@ test "math.cbrt.special" {
156156
157157test "math.cbrt64.special" {
158158 try expect(cbrt64(0.0) == 0.0);
159 try expect(cbrt64(-0.0) == -0.0);
159 try expect(@as(u64, @bitCast(cbrt64(-0.0))) == @as(u64, 0x8000000000000000));
160160 try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
161161 try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
162162 try expect(math.isNan(cbrt64(math.nan(f64))));