Skip to content

Conversation

@jedisct1
Copy link
Contributor

This adds an iterative EGCD implementation to std.math.

The implementation is simple and conservative, returns Bézout coefficients consistent with widely‐used implementations, and has been formally verified for any value and type supported by Zig up to u65534/i65534.

Its purpose is to make this API available to projects and other parts of the standard library. Optimizations for specific types or value ranges (e.g., using a binary method with or without approximations) can be added later without any changes to existing applications.

This adds an iterative EGCD implementation to std.math.

The implementation is simple and conservative, returns Bézout
coefficients consistent with widely‐used implementations, and has
been formally verified correct for any value and type supported
by Zig up to u65534/i65534.

Its purpose is to make this API available to projects and other
parts of the standard library. Optimizations for specific types or
value ranges (e.g., using a binary method or approximations) can be
added later without any changes to existing applications.
@jedisct1 jedisct1 marked this pull request as ready for review October 25, 2025 18:58
}

test "u4096" {
if (true) return error.SkipZigTest; // Codegen error on some platforms
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea about what can possibly happen here, @Rexicon226 ? See https://codeberg.org/ziglang/zig/pulls/9

Copy link
Contributor

@Rexicon226 Rexicon226 Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to look into it, but the situation confuses me a bit. I looked through the CI history here and on the codeberg and I see one type of failure was the assert being triggered and the other was a bitcode writer issue? I've tried running the tests locally (on x86-64 host) targeting -target aarch64-linux -mcpu neoverse_n1 (since I see that cpu was failing, just to be safe), and no luck reproducing the assertions. Any particular steps you have for reproducing the issue?

I can queue up a build of LLVM with assertions enabled on my macbook overnight and go from there tomorrow :).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't been able to reproduce it locally either. Neither on macOS nor aarch64 linux. This is very puzzling.

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.

2 participants