authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-11 21:27:39+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-11 21:27:39+02:00
log44f8ce690ddd406fc1a9caa63d9c0741f4afb3a0
treebf5dfad2c0a52184f6e1e9ccea51362cf718c9be
parent8d94dc625b34832af0e85c16fe4d64ee19c2e74e

std: Fix typo in sqrt implementation

The code initializes twice `t` instead of `t1`, leaving the latter uninitialized. The problem manifested itself by corrupting the LSBs of the result in unpredictable ways.

2 files changed, 2 insertions(+), 2 deletions(-)

lib/std/special/c.zig+1-1
...@@ -874,7 +874,7 @@ export fn sqrt(x: f64) f64 {...@@ -874,7 +874,7 @@ export fn sqrt(x: f64) f64 {
874874
875 r = sign;875 r = sign;
876 while (r != 0) {876 while (r != 0) {
877 t = s1 +% r;877 t1 = s1 +% r;
878 t = s0;878 t = s0;
879 if (t < ix0 or (t == ix0 and t1 <= ix1)) {879 if (t < ix0 or (t == ix0 and t1 <= ix1)) {
880 s1 = t1 +% r;880 s1 = t1 +% r;
test/stage1/behavior/bugs/920.zig+1-1
...@@ -60,6 +60,6 @@ test "bug 920 fixed" {...@@ -60,6 +60,6 @@ test "bug 920 fixed" {
60 };60 };
6161
62 for (NormalDist1.f) |_, i| {62 for (NormalDist1.f) |_, i| {
63 std.testing.expect(NormalDist1.f[i] == NormalDist.f[i]);63 std.testing.expectEqual(NormalDist1.f[i], NormalDist.f[i]);
64 }64 }
65}65}