Skip to content

Commit b8ddb04

Browse files
committed
std.math: Add std.math.egcd to compute the extended GCD
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.
1 parent bebfdc3 commit b8ddb04

File tree

2 files changed

+425
-0
lines changed

2 files changed

+425
-0
lines changed

lib/std/math.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ pub const atanh = @import("math/atanh.zig").atanh;
237237
pub const sinh = @import("math/sinh.zig").sinh;
238238
pub const cosh = @import("math/cosh.zig").cosh;
239239
pub const tanh = @import("math/tanh.zig").tanh;
240+
pub const egcd = @import("math/egcd.zig").egcd;
240241
pub const gcd = @import("math/gcd.zig").gcd;
241242
pub const lcm = @import("math/lcm.zig").lcm;
242243
pub const gamma = @import("math/gamma.zig").gamma;
@@ -398,6 +399,7 @@ test {
398399
_ = sinh;
399400
_ = cosh;
400401
_ = tanh;
402+
_ = egcd;
401403
_ = gcd;
402404
_ = lcm;
403405
_ = gamma;

0 commit comments

Comments
 (0)