Skip to content

Commit fffe0c7

Browse files
committed
Don't destructure.
1 parent fe4a594 commit fffe0c7

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

lib/std/crypto/ml_kem.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,9 +636,9 @@ test "invNTTReductions bounds" {
636636

637637
// Invert modulo p.
638638
fn invertMod(a: anytype, p: @TypeOf(a)) @TypeOf(a) {
639-
const gcd, const x, _ = std.math.egcd(a, p);
640-
assert(gcd == 1);
641-
return x;
639+
const r = std.math.egcd(a, p);
640+
assert(r.gcd == 1);
641+
return r.bezout_coeff_1;
642642
}
643643

644644
// Reduce mod q for testing.

lib/std/math/egcd.zig

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ const std = @import("../std.zig");
33

44
/// Result type of `egcd`.
55
pub fn ExtendedGreatestCommonDivisor(S: anytype) type {
6-
if (@typeInfo(S) != .int or @typeInfo(S).int.signedness != .signed) {
7-
@compileError("`S` must be a signed integer.");
8-
}
9-
106
return struct {
117
gcd: S,
128
bezout_coeff_1: S,
@@ -62,51 +58,65 @@ test {
6258
{
6359
const a: i32 = 0;
6460
const b: i32 = 5;
65-
const s, const t = egcd(a, b);
66-
const g = std.math.gcd(@abs(a), @abs(b));
61+
const r = egcd(a, b);
62+
const g = r.gcd;
63+
const s = r.bezout_coeff_1;
64+
const t = r.bezout_coeff_2;
6765
try std.testing.expect(s * a + t * b == g);
6866
}
6967
{
7068
const a: i32 = 5;
7169
const b: i32 = 0;
72-
const s, const t = egcd(a, b);
73-
const g = std.math.gcd(@as(u32, @intCast(a)), @as(u32, @intCast(b)));
70+
const r = egcd(a, b);
71+
const g = r.gcd;
72+
const s = r.bezout_coeff_1;
73+
const t = r.bezout_coeff_2;
7474
try std.testing.expect(s * a + t * b == g);
7575
}
7676

7777
{
7878
const a: i32 = 21;
7979
const b: i32 = 15;
80-
const s, const t = egcd(a, b);
81-
const g = std.math.gcd(@abs(a), @abs(b));
80+
const r = egcd(a, b);
81+
const g = r.gcd;
82+
const s = r.bezout_coeff_1;
83+
const t = r.bezout_coeff_2;
8284
try std.testing.expect(s * a + t * b == g);
8385
}
8486
{
8587
const a: i32 = -21;
8688
const b: i32 = 15;
87-
const s, const t = egcd(a, b);
88-
const g = std.math.gcd(@abs(a), @abs(b));
89+
const r = egcd(a, b);
90+
const g = r.gcd;
91+
const s = r.bezout_coeff_1;
92+
const t = r.bezout_coeff_2;
8993
try std.testing.expect(s * a + t * b == g);
9094
}
9195
{
9296
const a = -21;
9397
const b = 15;
94-
const s, const t = egcd(a, b);
95-
const g = std.math.gcd(@abs(a), @abs(b));
98+
const r = egcd(a, b);
99+
const g = r.gcd;
100+
const s = r.bezout_coeff_1;
101+
const t = r.bezout_coeff_2;
96102
try std.testing.expect(s * a + t * b == g);
97103
}
98104
{
99105
const a = 927372692193078999176;
100106
const b = 573147844013817084101;
101-
const s, const t = egcd(a, b);
102-
const g = std.math.gcd(@abs(a), @abs(b));
107+
const r = egcd(a, b);
108+
const g = r.gcd;
109+
const s = r.bezout_coeff_1;
110+
const t = r.bezout_coeff_2;
103111
try std.testing.expect(s * a + t * b == g);
104112
}
105113
{
106114
const a = 453973694165307953197296969697410619233826;
107115
const b = 280571172992510140037611932413038677189525;
108-
const s, const t = egcd(a, b);
109-
const g = std.math.gcd(@abs(a), @abs(b));
116+
const r = egcd(a, b);
117+
const g = r.gcd;
118+
const s = r.bezout_coeff_1;
119+
const t = r.bezout_coeff_2;
110120
try std.testing.expect(s * a + t * b == g);
111121
}
112122
}

0 commit comments

Comments
 (0)