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 {...@@ -87,9 +87,9 @@ fn cbrt64(x: f64) f64 {
87 u = @as(u64, @bitCast(x * 0x1.0p54));87 u = @as(u64, @bitCast(x * 0x1.0p54));
88 hx = @as(u32, @intCast(u >> 32)) & 0x7FFFFFFF;88 hx = @as(u32, @intCast(u >> 32)) & 0x7FFFFFFF;
8989
90 // cbrt(0) is itself90 // cbrt(+-0) = itself
91 if (hx == 0) {91 if (hx == 0) {
92 return 0;92 return x;
93 }93 }
94 hx = hx / 3 + B2;94 hx = hx / 3 + B2;
95 } else {95 } else {
...@@ -148,7 +148,7 @@ test "math.cbrt64" {...@@ -148,7 +148,7 @@ test "math.cbrt64" {
148148
149test "math.cbrt.special" {149test "math.cbrt.special" {
150 try expect(cbrt32(0.0) == 0.0);150 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));
152 try expect(math.isPositiveInf(cbrt32(math.inf(f32))));152 try expect(math.isPositiveInf(cbrt32(math.inf(f32))));
153 try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));153 try expect(math.isNegativeInf(cbrt32(-math.inf(f32))));
154 try expect(math.isNan(cbrt32(math.nan(f32))));154 try expect(math.isNan(cbrt32(math.nan(f32))));
...@@ -156,7 +156,7 @@ test "math.cbrt.special" {...@@ -156,7 +156,7 @@ test "math.cbrt.special" {
156156
157test "math.cbrt64.special" {157test "math.cbrt64.special" {
158 try expect(cbrt64(0.0) == 0.0);158 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));
160 try expect(math.isPositiveInf(cbrt64(math.inf(f64))));160 try expect(math.isPositiveInf(cbrt64(math.inf(f64))));
161 try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));161 try expect(math.isNegativeInf(cbrt64(-math.inf(f64))));
162 try expect(math.isNan(cbrt64(math.nan(f64))));162 try expect(math.isNan(cbrt64(math.nan(f64))));