Skip to content

Fix sqrt(0) panic in managed math - #17906

Merged
Vexu merged 1 commit into
ziglang:masterfrom
Rexicon226:fix-sqrt
Nov 7, 2023
Merged

Vexu merged 1 commit into
ziglang:masterfrom
Rexicon226:fix-sqrt

Conversation

@Rexicon226

@Rexicon226 Rexicon226 commented Nov 7, 2023

Copy link
Copy Markdown
Contributor

fixes #17858

when the a value takes 0 bits, it will always be 0, by extension the square root will always be 0.

i also added a negative check that returns an error. because the current error is very misleading:

/home/dr/zig/lib/std/debug.zig:342:14: 0x222c22 in assert (test)
    if (!ok) unreachable; // assertion failure
             ^
/home/dr/zig/lib/std/math/big/int.zig:1524:15: 0x2293ef in div (test)
        assert(!y.eqlZero()); // division by zero

@Rexicon226
Rexicon226 marked this pull request as ready for review November 7, 2023 07:11
@Vexu
Vexu enabled auto-merge (rebase) November 7, 2023 09:11
@Vexu
Vexu merged commit 03abac3 into ziglang:master Nov 7, 2023
@Rexicon226
Rexicon226 deleted the fix-sqrt branch November 7, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

std.math.big.int sqrt panic

2 participants