zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 44f8ce690ddd406fc1a9caa63d9c0741f4afb3a0 (tree)
parent 8d94dc625b34832af0e85c16fe4d64ee19c2e74e
Author: LemonBoy <thatlemon@gmail.com>
Date:   Sun, 11 Apr 2021 21:27:39 +0200

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.

Diffstat:
Mlib/std/special/c.zig | 2+-
Mtest/stage1/behavior/bugs/920.zig | 2+-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig @@ -874,7 +874,7 @@ export fn sqrt(x: f64) f64 { r = sign; while (r != 0) { - t = s1 +% r; + t1 = s1 +% r; t = s0; if (t < ix0 or (t == ix0 and t1 <= ix1)) { s1 = t1 +% r; diff --git a/test/stage1/behavior/bugs/920.zig b/test/stage1/behavior/bugs/920.zig @@ -60,6 +60,6 @@ test "bug 920 fixed" { }; for (NormalDist1.f) |_, i| { - std.testing.expect(NormalDist1.f[i] == NormalDist.f[i]); + std.testing.expectEqual(NormalDist1.f[i], NormalDist.f[i]); } }