std.math: Add std.math.egcd to compute the extended GCD#25642
std.math: Add std.math.egcd to compute the extended GCD#25642jedisct1 wants to merge 2 commits intoziglang:masterfrom
Conversation
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.
| } | ||
|
|
||
| test "u4096" { | ||
| if (true) return error.SkipZigTest; // Codegen error on some platforms |
There was a problem hiding this comment.
Any idea about what can possibly happen here, @Rexicon226 ? See https://codeberg.org/ziglang/zig/pulls/9
There was a problem hiding this comment.
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 :).
There was a problem hiding this comment.
I haven't been able to reproduce it locally either. Neither on macOS nor aarch64 linux. This is very puzzling.
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.