authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-04-16 18:28:25+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-16 18:28:25+02:00
log1a2ceb36c82cae63d30d99ecfadb22bdf2a977fe
treec4cd408e66907abf212955ed891a26ea0206bf16
parent3746b3d93ce895131ab1b2dea5391e5efa9fccf7
parent8ae9ac6df46b9aa10e6098585c0f987d70eae61b
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #23573 from samy-00007/bigint-shift-fix

std.math.big.int: fix a bug in `llshl` and update test syntax

2 files changed, 759 insertions(+), 447 deletions(-)

lib/std/math/big/int.zig+388-76
...@@ -17,8 +17,6 @@ const Endian = std.builtin.Endian;...@@ -17,8 +17,6 @@ const Endian = std.builtin.Endian;
17const Signedness = std.builtin.Signedness;17const Signedness = std.builtin.Signedness;
18const native_endian = builtin.cpu.arch.endian();18const native_endian = builtin.cpu.arch.endian();
1919
20const debug_safety = false;
21
22/// Returns the number of limbs needed to store `scalar`, which must be a20/// Returns the number of limbs needed to store `scalar`, which must be a
23/// primitive integer value.21/// primitive integer value.
24/// Note: A comptime-known upper bound of this value that may be used22/// Note: A comptime-known upper bound of this value that may be used
...@@ -92,8 +90,6 @@ pub fn calcTwosCompLimbCount(bit_count: usize) usize {...@@ -92,8 +90,6 @@ pub fn calcTwosCompLimbCount(bit_count: usize) usize {
9290
93/// a + b * c + *carry, sets carry to the overflow bits91/// a + b * c + *carry, sets carry to the overflow bits
94pub fn addMulLimbWithCarry(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {92pub fn addMulLimbWithCarry(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {
95 @setRuntimeSafety(debug_safety);
96
97 // ov1[0] = a + *carry93 // ov1[0] = a + *carry
98 const ov1 = @addWithOverflow(a, carry.*);94 const ov1 = @addWithOverflow(a, carry.*);
9995
...@@ -213,7 +209,7 @@ pub const Mutable = struct {...@@ -213,7 +209,7 @@ pub const Mutable = struct {
213 for (self.limbs[0..self.len]) |limb| {209 for (self.limbs[0..self.len]) |limb| {
214 std.debug.print("{x} ", .{limb});210 std.debug.print("{x} ", .{limb});
215 }211 }
216 std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.positive });212 std.debug.print("len={} capacity={} positive={}\n", .{ self.len, self.limbs.len, self.positive });
217 }213 }
218214
219 /// Clones an Mutable and returns a new Mutable with the same value. The new Mutable is a deep copy and215 /// Clones an Mutable and returns a new Mutable with the same value. The new Mutable is a deep copy and
...@@ -1107,8 +1103,8 @@ pub const Mutable = struct {...@@ -1107,8 +1103,8 @@ pub const Mutable = struct {
1107 /// Asserts there is enough memory to fit the result. The upper bound Limb count is1103 /// Asserts there is enough memory to fit the result. The upper bound Limb count is
1108 /// `a.limbs.len + (shift / (@sizeOf(Limb) * 8))`.1104 /// `a.limbs.len + (shift / (@sizeOf(Limb) * 8))`.
1109 pub fn shiftLeft(r: *Mutable, a: Const, shift: usize) void {1105 pub fn shiftLeft(r: *Mutable, a: Const, shift: usize) void {
1110 llshl(r.limbs, a.limbs, shift);1106 const new_len = llshl(r.limbs, a.limbs, shift);
1111 r.normalize(a.limbs.len + (shift / limb_bits) + 1);1107 r.normalize(new_len);
1112 r.positive = a.positive;1108 r.positive = a.positive;
1113 }1109 }
11141110
...@@ -1176,8 +1172,8 @@ pub const Mutable = struct {...@@ -1176,8 +1172,8 @@ pub const Mutable = struct {
11761172
1177 // This shift should not be able to overflow, so invoke llshl and normalize manually1173 // This shift should not be able to overflow, so invoke llshl and normalize manually
1178 // to avoid the extra required limb.1174 // to avoid the extra required limb.
1179 llshl(r.limbs, a.limbs, shift);1175 const new_len = llshl(r.limbs, a.limbs, shift);
1180 r.normalize(a.limbs.len + (shift / limb_bits));1176 r.normalize(new_len);
1181 r.positive = a.positive;1177 r.positive = a.positive;
1182 }1178 }
11831179
...@@ -1185,7 +1181,7 @@ pub const Mutable = struct {...@@ -1185,7 +1181,7 @@ pub const Mutable = struct {
1185 /// r and a may alias.1181 /// r and a may alias.
1186 ///1182 ///
1187 /// Asserts there is enough memory to fit the result. The upper bound Limb count is1183 /// Asserts there is enough memory to fit the result. The upper bound Limb count is
1188 /// `a.limbs.len - (shift / (@sizeOf(Limb) * 8))`.1184 /// `a.limbs.len - (shift / (@bitSizeOf(Limb)))`.
1189 pub fn shiftRight(r: *Mutable, a: Const, shift: usize) void {1185 pub fn shiftRight(r: *Mutable, a: Const, shift: usize) void {
1190 const full_limbs_shifted_out = shift / limb_bits;1186 const full_limbs_shifted_out = shift / limb_bits;
1191 const remaining_bits_shifted_out = shift % limb_bits;1187 const remaining_bits_shifted_out = shift % limb_bits;
...@@ -1213,9 +1209,9 @@ pub const Mutable = struct {...@@ -1213,9 +1209,9 @@ pub const Mutable = struct {
1213 break :nonzero a.limbs[full_limbs_shifted_out] << not_covered != 0;1209 break :nonzero a.limbs[full_limbs_shifted_out] << not_covered != 0;
1214 };1210 };
12151211
1216 llshr(r.limbs, a.limbs, shift);1212 const new_len = llshr(r.limbs, a.limbs, shift);
12171213
1218 r.len = a.limbs.len - full_limbs_shifted_out;1214 r.len = new_len;
1219 r.positive = a.positive;1215 r.positive = a.positive;
1220 if (nonzero_negative_shiftout) r.addScalar(r.toConst(), -1);1216 if (nonzero_negative_shiftout) r.addScalar(r.toConst(), -1);
1221 r.normalize(r.len);1217 r.normalize(r.len);
...@@ -1974,7 +1970,7 @@ pub const Const = struct {...@@ -1974,7 +1970,7 @@ pub const Const = struct {
1974 for (self.limbs[0..self.limbs.len]) |limb| {1970 for (self.limbs[0..self.limbs.len]) |limb| {
1975 std.debug.print("{x} ", .{limb});1971 std.debug.print("{x} ", .{limb});
1976 }1972 }
1977 std.debug.print("positive={}\n", .{self.positive});1973 std.debug.print("len={} positive={}\n", .{ self.len, self.positive });
1978 }1974 }
19791975
1980 pub fn abs(self: Const) Const {1976 pub fn abs(self: Const) Const {
...@@ -2676,7 +2672,7 @@ pub const Managed = struct {...@@ -2676,7 +2672,7 @@ pub const Managed = struct {
2676 for (self.limbs[0..self.len()]) |limb| {2672 for (self.limbs[0..self.len()]) |limb| {
2677 std.debug.print("{x} ", .{limb});2673 std.debug.print("{x} ", .{limb});
2678 }2674 }
2679 std.debug.print("capacity={} positive={}\n", .{ self.limbs.len, self.isPositive() });2675 std.debug.print("len={} capacity={} positive={}\n", .{ self.len(), self.limbs.len, self.isPositive() });
2680 }2676 }
26812677
2682 /// Negate the sign.2678 /// Negate the sign.
...@@ -3277,9 +3273,10 @@ const AccOp = enum {...@@ -3277,9 +3273,10 @@ const AccOp = enum {
3277///3273///
3278/// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs.3274/// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs.
3279fn llmulacc(comptime op: AccOp, opt_allocator: ?Allocator, r: []Limb, a: []const Limb, b: []const Limb) void {3275fn llmulacc(comptime op: AccOp, opt_allocator: ?Allocator, r: []Limb, a: []const Limb, b: []const Limb) void {
3280 @setRuntimeSafety(debug_safety);
3281 assert(r.len >= a.len);3276 assert(r.len >= a.len);
3282 assert(r.len >= b.len);3277 assert(r.len >= b.len);
3278 assert(!slicesOverlap(r, a));
3279 assert(!slicesOverlap(r, b));
32833280
3284 // Order greatest first.3281 // Order greatest first.
3285 var x = a;3282 var x = a;
...@@ -3316,9 +3313,10 @@ fn llmulaccKaratsuba(...@@ -3316,9 +3313,10 @@ fn llmulaccKaratsuba(
3316 a: []const Limb,3313 a: []const Limb,
3317 b: []const Limb,3314 b: []const Limb,
3318) error{OutOfMemory}!void {3315) error{OutOfMemory}!void {
3319 @setRuntimeSafety(debug_safety);
3320 assert(r.len >= a.len);3316 assert(r.len >= a.len);
3321 assert(a.len >= b.len);3317 assert(a.len >= b.len);
3318 assert(!slicesOverlap(r, a));
3319 assert(!slicesOverlap(r, b));
33223320
3323 // Classical karatsuba algorithm:3321 // Classical karatsuba algorithm:
3324 // a = a1 * B + a03322 // a = a1 * B + a0
...@@ -3479,7 +3477,6 @@ fn llmulaccKaratsuba(...@@ -3479,7 +3477,6 @@ fn llmulaccKaratsuba(
3479/// r = r (op) a.3477/// r = r (op) a.
3480/// The result is computed modulo `r.len`.3478/// The result is computed modulo `r.len`.
3481fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {3479fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {
3482 @setRuntimeSafety(debug_safety);
3483 if (op == .sub) {3480 if (op == .sub) {
3484 _ = llsubcarry(r, r, a);3481 _ = llsubcarry(r, r, a);
3485 return;3482 return;
...@@ -3508,7 +3505,6 @@ fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {...@@ -3508,7 +3505,6 @@ fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {
35083505
3509/// Returns -1, 0, 1 if |a| < |b|, |a| == |b| or |a| > |b| respectively for limbs.3506/// Returns -1, 0, 1 if |a| < |b|, |a| == |b| or |a| > |b| respectively for limbs.
3510pub fn llcmp(a: []const Limb, b: []const Limb) i8 {3507pub fn llcmp(a: []const Limb, b: []const Limb) i8 {
3511 @setRuntimeSafety(debug_safety);
3512 const a_len = llnormalize(a);3508 const a_len = llnormalize(a);
3513 const b_len = llnormalize(b);3509 const b_len = llnormalize(b);
3514 if (a_len < b_len) {3510 if (a_len < b_len) {
...@@ -3537,7 +3533,6 @@ pub fn llcmp(a: []const Limb, b: []const Limb) i8 {...@@ -3537,7 +3533,6 @@ pub fn llcmp(a: []const Limb, b: []const Limb) i8 {
3537/// r = r (op) y * xi3533/// r = r (op) y * xi
3538/// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs.3534/// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs.
3539fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb) void {3535fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb) void {
3540 @setRuntimeSafety(debug_safety);
3541 assert(r.len >= a.len);3536 assert(r.len >= a.len);
3542 assert(a.len >= b.len);3537 assert(a.len >= b.len);
35433538
...@@ -3551,7 +3546,6 @@ fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb)...@@ -3551,7 +3546,6 @@ fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb)
3551/// The result is computed modulo `r.len`.3546/// The result is computed modulo `r.len`.
3552/// Returns whether the operation overflowed.3547/// Returns whether the operation overflowed.
3553fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {3548fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {
3554 @setRuntimeSafety(debug_safety);
3555 if (xi == 0) {3549 if (xi == 0) {
3556 return false;3550 return false;
3557 }3551 }
...@@ -3598,7 +3592,6 @@ fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {...@@ -3598,7 +3592,6 @@ fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {
35983592
3599/// returns the min length the limb could be.3593/// returns the min length the limb could be.
3600fn llnormalize(a: []const Limb) usize {3594fn llnormalize(a: []const Limb) usize {
3601 @setRuntimeSafety(debug_safety);
3602 var j = a.len;3595 var j = a.len;
3603 while (j > 0) : (j -= 1) {3596 while (j > 0) : (j -= 1) {
3604 if (a[j - 1] != 0) {3597 if (a[j - 1] != 0) {
...@@ -3612,7 +3605,6 @@ fn llnormalize(a: []const Limb) usize {...@@ -3612,7 +3605,6 @@ fn llnormalize(a: []const Limb) usize {
36123605
3613/// Knuth 4.3.1, Algorithm S.3606/// Knuth 4.3.1, Algorithm S.
3614fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {3607fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
3615 @setRuntimeSafety(debug_safety);
3616 assert(a.len != 0 and b.len != 0);3608 assert(a.len != 0 and b.len != 0);
3617 assert(a.len >= b.len);3609 assert(a.len >= b.len);
3618 assert(r.len >= a.len);3610 assert(r.len >= a.len);
...@@ -3638,14 +3630,12 @@ fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {...@@ -3638,14 +3630,12 @@ fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
3638}3630}
36393631
3640fn llsub(r: []Limb, a: []const Limb, b: []const Limb) void {3632fn llsub(r: []Limb, a: []const Limb, b: []const Limb) void {
3641 @setRuntimeSafety(debug_safety);
3642 assert(a.len > b.len or (a.len == b.len and a[a.len - 1] >= b[b.len - 1]));3633 assert(a.len > b.len or (a.len == b.len and a[a.len - 1] >= b[b.len - 1]));
3643 assert(llsubcarry(r, a, b) == 0);3634 assert(llsubcarry(r, a, b) == 0);
3644}3635}
36453636
3646/// Knuth 4.3.1, Algorithm A.3637/// Knuth 4.3.1, Algorithm A.
3647fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {3638fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
3648 @setRuntimeSafety(debug_safety);
3649 assert(a.len != 0 and b.len != 0);3639 assert(a.len != 0 and b.len != 0);
3650 assert(a.len >= b.len);3640 assert(a.len >= b.len);
3651 assert(r.len >= a.len);3641 assert(r.len >= a.len);
...@@ -3671,14 +3661,12 @@ fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {...@@ -3671,14 +3661,12 @@ fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
3671}3661}
36723662
3673fn lladd(r: []Limb, a: []const Limb, b: []const Limb) void {3663fn lladd(r: []Limb, a: []const Limb, b: []const Limb) void {
3674 @setRuntimeSafety(debug_safety);
3675 assert(r.len >= a.len + 1);3664 assert(r.len >= a.len + 1);
3676 r[a.len] = lladdcarry(r, a, b);3665 r[a.len] = lladdcarry(r, a, b);
3677}3666}
36783667
3679/// Knuth 4.3.1, Exercise 16.3668/// Knuth 4.3.1, Exercise 16.
3680fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {3669fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
3681 @setRuntimeSafety(debug_safety);
3682 assert(a.len > 1 or a[0] >= b);3670 assert(a.len > 1 or a[0] >= b);
3683 assert(quo.len >= a.len);3671 assert(quo.len >= a.len);
36843672
...@@ -3704,7 +3692,6 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {...@@ -3704,7 +3692,6 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
3704}3692}
37053693
3706fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void {3694fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void {
3707 @setRuntimeSafety(debug_safety);
3708 assert(a.len > 1 or a[0] >= b);3695 assert(a.len > 1 or a[0] >= b);
3709 assert(quo.len >= a.len);3696 assert(quo.len >= a.len);
37103697
...@@ -3727,69 +3714,114 @@ fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void {...@@ -3727,69 +3714,114 @@ fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void {
3727 }3714 }
3728}3715}
37293716
3730fn llshl(r: []Limb, a: []const Limb, shift: usize) void {3717/// Performs r = a << shift and returns the amount of limbs affected
3731 @setRuntimeSafety(debug_safety);3718///
3732 assert(a.len >= 1);3719/// if a and r overlaps, then r.ptr >= a.ptr is asserted
3720/// r must have the capacity to store a << shift
3721fn llshl(r: []Limb, a: []const Limb, shift: usize) usize {
3722 std.debug.assert(a.len >= 1);
3723 if (slicesOverlap(a, r))
3724 std.debug.assert(@intFromPtr(r.ptr) >= @intFromPtr(a.ptr));
3725
3726 if (shift == 0) {
3727 if (a.ptr != r.ptr)
3728 std.mem.copyBackwards(Limb, r[0..a.len], a);
3729 return a.len;
3730 }
3731 if (shift >= limb_bits) {
3732 const limb_shift = shift / limb_bits;
37333733
3734 const interior_limb_shift = @as(Log2Limb, @truncate(shift));3734 const affected = llshl(r[limb_shift..], a, shift % limb_bits);
3735 @memset(r[0..limb_shift], 0);
3736
3737 return limb_shift + affected;
3738 }
3739
3740 // shift is guaranteed to be < limb_bits
3741 const bit_shift: Log2Limb = @truncate(shift);
3742 const opposite_bit_shift: Log2Limb = @truncate(limb_bits - bit_shift);
37353743
3736 // We only need the extra limb if the shift of the last element overflows.3744 // We only need the extra limb if the shift of the last element overflows.
3737 // This is useful for the implementation of `shiftLeftSat`.3745 // This is useful for the implementation of `shiftLeftSat`.
3738 if (a[a.len - 1] << interior_limb_shift >> interior_limb_shift != a[a.len - 1]) {3746 const overflows = a[a.len - 1] >> opposite_bit_shift != 0;
3739 assert(r.len >= a.len + (shift / limb_bits) + 1);3747 if (overflows) {
3748 std.debug.assert(r.len >= a.len + 1);
3740 } else {3749 } else {
3741 assert(r.len >= a.len + (shift / limb_bits));3750 std.debug.assert(r.len >= a.len);
3751 }
3752
3753 var i: usize = a.len;
3754 if (overflows) {
3755 // r is asserted to be large enough above
3756 r[a.len] = a[a.len - 1] >> opposite_bit_shift;
3757 }
3758 while (i > 1) {
3759 i -= 1;
3760 r[i] = (a[i - 1] >> opposite_bit_shift) | (a[i] << bit_shift);
3742 }3761 }
3762 r[0] = a[0] << bit_shift;
37433763
3744 const limb_shift = shift / limb_bits + 1;3764 return a.len + @intFromBool(overflows);
3765}
37453766
3746 var carry: Limb = 0;3767/// Performs r = a >> shift and returns the amount of limbs affected
3747 var i: usize = 0;3768///
3748 while (i < a.len) : (i += 1) {3769/// if a and r overlaps, then r.ptr <= a.ptr is asserted
3749 const src_i = a.len - i - 1;3770/// r must have the capacity to store a >> shift
3750 const dst_i = src_i + limb_shift;3771///
3772/// See tests below for examples of behaviour
3773fn llshr(r: []Limb, a: []const Limb, shift: usize) usize {
3774 if (slicesOverlap(a, r))
3775 std.debug.assert(@intFromPtr(r.ptr) <= @intFromPtr(a.ptr));
3776
3777 if (a.len == 0) return 0;
37513778
3752 const src_digit = a[src_i];3779 if (shift == 0) {
3753 r[dst_i] = carry | @call(.always_inline, math.shr, .{3780 std.debug.assert(r.len >= a.len);
3754 Limb,3781
3755 src_digit,3782 if (a.ptr != r.ptr)
3756 limb_bits - @as(Limb, @intCast(interior_limb_shift)),3783 std.mem.copyForwards(Limb, r[0..a.len], a);
3757 });3784 return a.len;
3758 carry = (src_digit << interior_limb_shift);3785 }
3786 if (shift >= limb_bits) {
3787 if (shift / limb_bits >= a.len) {
3788 r[0] = 0;
3789 return 1;
3790 }
3791 return llshr(r, a[shift / limb_bits ..], shift % limb_bits);
3759 }3792 }
37603793
3761 r[limb_shift - 1] = carry;3794 // shift is guaranteed to be < limb_bits
3762 @memset(r[0 .. limb_shift - 1], 0);3795 const bit_shift: Log2Limb = @truncate(shift);
3763}3796 const opposite_bit_shift: Log2Limb = @truncate(limb_bits - bit_shift);
37643797
3765fn llshr(r: []Limb, a: []const Limb, shift: usize) void {3798 // special case, where there is a risk to set r to 0
3766 @setRuntimeSafety(debug_safety);3799 if (a.len == 1) {
3767 assert(a.len >= 1);3800 r[0] = a[0] >> bit_shift;
3768 assert(r.len >= a.len - (shift / limb_bits));3801 return 1;
3802 }
3803 if (a.len == 0) {
3804 r[0] = 0;
3805 return 1;
3806 }
37693807
3770 const limb_shift = shift / limb_bits;3808 // if the most significant limb becomes 0 after the shift
3771 const interior_limb_shift = @as(Log2Limb, @truncate(shift));3809 const shrink = a[a.len - 1] >> bit_shift == 0;
3810 std.debug.assert(r.len >= a.len - @intFromBool(!shrink));
37723811
3773 var i: usize = 0;3812 var i: usize = 0;
3774 while (i < a.len - limb_shift) : (i += 1) {3813 while (i < a.len - 1) : (i += 1) {
3775 const dst_i = i;3814 r[i] = (a[i] >> bit_shift) | (a[i + 1] << opposite_bit_shift);
3776 const src_i = dst_i + limb_shift;
3777
3778 const src_digit = a[src_i];
3779 const src_digit_next = if (src_i + 1 < a.len) a[src_i + 1] else 0;
3780 const carry = @call(.always_inline, math.shl, .{
3781 Limb,
3782 src_digit_next,
3783 limb_bits - @as(Limb, @intCast(interior_limb_shift)),
3784 });
3785 r[dst_i] = carry | (src_digit >> interior_limb_shift);
3786 }3815 }
3816
3817 if (!shrink)
3818 r[i] = a[i] >> bit_shift;
3819
3820 return a.len - @intFromBool(shrink);
3787}3821}
37883822
3789// r = ~r3823// r = ~r
3790fn llnot(r: []Limb) void {3824fn llnot(r: []Limb) void {
3791 @setRuntimeSafety(debug_safety);
3792
3793 for (r) |*elem| {3825 for (r) |*elem| {
3794 elem.* = ~elem.*;3826 elem.* = ~elem.*;
3795 }3827 }
...@@ -3802,7 +3834,6 @@ fn llnot(r: []Limb) void {...@@ -3802,7 +3834,6 @@ fn llnot(r: []Limb) void {
3802// When b is positive, r requires at least `a.len` limbs of storage.3834// When b is positive, r requires at least `a.len` limbs of storage.
3803// When b is negative, r requires at least `b.len` limbs of storage.3835// When b is negative, r requires at least `b.len` limbs of storage.
3804fn llsignedor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {3836fn llsignedor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {
3805 @setRuntimeSafety(debug_safety);
3806 assert(r.len >= a.len);3837 assert(r.len >= a.len);
3807 assert(a.len >= b.len);3838 assert(a.len >= b.len);
38083839
...@@ -3933,7 +3964,6 @@ fn llsignedor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_p...@@ -3933,7 +3964,6 @@ fn llsignedor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_p
3933// 2. when b is negative but a is positive, r requires at least `a.len` limbs of storage,3964// 2. when b is negative but a is positive, r requires at least `a.len` limbs of storage,
3934// 3. when both a and b are negative, r requires at least `a.len + 1` limbs of storage.3965// 3. when both a and b are negative, r requires at least `a.len + 1` limbs of storage.
3935fn llsignedand(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {3966fn llsignedand(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {
3936 @setRuntimeSafety(debug_safety);
3937 assert(a.len != 0 and b.len != 0);3967 assert(a.len != 0 and b.len != 0);
3938 assert(a.len >= b.len);3968 assert(a.len >= b.len);
3939 assert(r.len >= if (b_positive) b.len else if (a_positive) a.len else a.len + 1);3969 assert(r.len >= if (b_positive) b.len else if (a_positive) a.len else a.len + 1);
...@@ -4043,7 +4073,6 @@ fn llsignedand(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_...@@ -4043,7 +4073,6 @@ fn llsignedand(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_
4043// If the sign of a and b is equal, then r requires at least `@max(a.len, b.len)` limbs are required.4073// If the sign of a and b is equal, then r requires at least `@max(a.len, b.len)` limbs are required.
4044// Otherwise, r requires at least `@max(a.len, b.len) + 1` limbs.4074// Otherwise, r requires at least `@max(a.len, b.len) + 1` limbs.
4045fn llsignedxor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {4075fn llsignedxor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {
4046 @setRuntimeSafety(debug_safety);
4047 assert(a.len != 0 and b.len != 0);4076 assert(a.len != 0 and b.len != 0);
4048 assert(r.len >= a.len);4077 assert(r.len >= a.len);
4049 assert(a.len >= b.len);4078 assert(a.len >= b.len);
...@@ -4102,10 +4131,9 @@ fn llsignedxor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_...@@ -4102,10 +4131,9 @@ fn llsignedxor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_
41024131
4103/// r MUST NOT alias x.4132/// r MUST NOT alias x.
4104fn llsquareBasecase(r: []Limb, x: []const Limb) void {4133fn llsquareBasecase(r: []Limb, x: []const Limb) void {
4105 @setRuntimeSafety(debug_safety);
4106
4107 const x_norm = x;4134 const x_norm = x;
4108 assert(r.len >= 2 * x_norm.len + 1);4135 assert(r.len >= 2 * x_norm.len + 1);
4136 assert(!slicesOverlap(r, x));
41094137
4110 // Compute the square of a N-limb bigint with only (N^2 + N)/24138 // Compute the square of a N-limb bigint with only (N^2 + N)/2
4111 // multiplications by exploiting the symmetry of the coefficients around the4139 // multiplications by exploiting the symmetry of the coefficients around the
...@@ -4129,7 +4157,7 @@ fn llsquareBasecase(r: []Limb, x: []const Limb) void {...@@ -4129,7 +4157,7 @@ fn llsquareBasecase(r: []Limb, x: []const Limb) void {
4129 }4157 }
41304158
4131 // Each product appears twice, multiply by 24159 // Each product appears twice, multiply by 2
4132 llshl(r, r[0 .. 2 * x_norm.len], 1);4160 _ = llshl(r, r[0 .. 2 * x_norm.len], 1);
41334161
4134 for (x_norm, 0..) |v, i| {4162 for (x_norm, 0..) |v, i| {
4135 // Compute and add the squares4163 // Compute and add the squares
...@@ -4201,6 +4229,290 @@ fn fixedIntFromSignedDoubleLimb(A: SignedDoubleLimb, storage: []Limb) Mutable {...@@ -4201,6 +4229,290 @@ fn fixedIntFromSignedDoubleLimb(A: SignedDoubleLimb, storage: []Limb) Mutable {
4201 };4229 };
4202}4230}
42034231
4232fn slicesOverlap(a: []const Limb, b: []const Limb) bool {
4233 // there is no overlap if a.ptr + a.len <= b.ptr or b.ptr + b.len <= a.ptr
4234 return @intFromPtr(a.ptr + a.len) > @intFromPtr(b.ptr) and @intFromPtr(b.ptr + b.len) > @intFromPtr(a.ptr);
4235}
4236
4204test {4237test {
4205 _ = @import("int_test.zig");4238 _ = @import("int_test.zig");
4206}4239}
4240
4241const testing_allocator = std.testing.allocator;
4242test "llshl shift by whole number of limb" {
4243 const padding = std.math.maxInt(Limb);
4244
4245 var r: [10]Limb = @splat(padding);
4246
4247 const A: Limb = @truncate(0xCCCCCCCCCCCCCCCCCCCCCCC);
4248 const B: Limb = @truncate(0x22222222222222222222222);
4249
4250 const data = [2]Limb{ A, B };
4251 for (0..9) |i| {
4252 @memset(&r, padding);
4253 const len = llshl(&r, &data, i * @bitSizeOf(Limb));
4254
4255 try std.testing.expectEqual(i + 2, len);
4256 try std.testing.expectEqualSlices(Limb, &data, r[i .. i + 2]);
4257 for (r[0..i]) |x|
4258 try std.testing.expectEqual(0, x);
4259 for (r[i + 2 ..]) |x|
4260 try std.testing.expectEqual(padding, x);
4261 }
4262}
4263
4264test llshl {
4265 if (limb_bits != 64) return error.SkipZigTest;
4266
4267 // 1 << 63
4268 const left_one = 0x8000000000000000;
4269 const maxint: Limb = 0xFFFFFFFFFFFFFFFF;
4270
4271 // zig fmt: off
4272 try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}});
4273 try testOneShiftCase(.llshl, .{0, &.{1}, &.{1}});
4274 try testOneShiftCase(.llshl, .{0, &.{125484842448}, &.{125484842448}});
4275 try testOneShiftCase(.llshl, .{0, &.{0xdeadbeef}, &.{0xdeadbeef}});
4276 try testOneShiftCase(.llshl, .{0, &.{maxint}, &.{maxint}});
4277 try testOneShiftCase(.llshl, .{0, &.{left_one}, &.{left_one}});
4278 try testOneShiftCase(.llshl, .{0, &.{0, 1}, &.{0, 1}});
4279 try testOneShiftCase(.llshl, .{0, &.{1, 2}, &.{1, 2}});
4280 try testOneShiftCase(.llshl, .{0, &.{left_one, 1}, &.{left_one, 1}});
4281 try testOneShiftCase(.llshl, .{1, &.{0}, &.{0}});
4282 try testOneShiftCase(.llshl, .{1, &.{2}, &.{1}});
4283 try testOneShiftCase(.llshl, .{1, &.{250969684896}, &.{125484842448}});
4284 try testOneShiftCase(.llshl, .{1, &.{0x1bd5b7dde}, &.{0xdeadbeef}});
4285 try testOneShiftCase(.llshl, .{1, &.{0xfffffffffffffffe, 1}, &.{maxint}});
4286 try testOneShiftCase(.llshl, .{1, &.{0, 1}, &.{left_one}});
4287 try testOneShiftCase(.llshl, .{1, &.{0, 2}, &.{0, 1}});
4288 try testOneShiftCase(.llshl, .{1, &.{2, 4}, &.{1, 2}});
4289 try testOneShiftCase(.llshl, .{1, &.{0, 3}, &.{left_one, 1}});
4290 try testOneShiftCase(.llshl, .{5, &.{32}, &.{1}});
4291 try testOneShiftCase(.llshl, .{5, &.{4015514958336}, &.{125484842448}});
4292 try testOneShiftCase(.llshl, .{5, &.{0x1bd5b7dde0}, &.{0xdeadbeef}});
4293 try testOneShiftCase(.llshl, .{5, &.{0xffffffffffffffe0, 0x1f}, &.{maxint}});
4294 try testOneShiftCase(.llshl, .{5, &.{0, 16}, &.{left_one}});
4295 try testOneShiftCase(.llshl, .{5, &.{0, 32}, &.{0, 1}});
4296 try testOneShiftCase(.llshl, .{5, &.{32, 64}, &.{1, 2}});
4297 try testOneShiftCase(.llshl, .{5, &.{0, 48}, &.{left_one, 1}});
4298 try testOneShiftCase(.llshl, .{64, &.{0, 1}, &.{1}});
4299 try testOneShiftCase(.llshl, .{64, &.{0, 125484842448}, &.{125484842448}});
4300 try testOneShiftCase(.llshl, .{64, &.{0, 0xdeadbeef}, &.{0xdeadbeef}});
4301 try testOneShiftCase(.llshl, .{64, &.{0, maxint}, &.{maxint}});
4302 try testOneShiftCase(.llshl, .{64, &.{0, left_one}, &.{left_one}});
4303 try testOneShiftCase(.llshl, .{64, &.{0, 0, 1}, &.{0, 1}});
4304 try testOneShiftCase(.llshl, .{64, &.{0, 1, 2}, &.{1, 2}});
4305 try testOneShiftCase(.llshl, .{64, &.{0, left_one, 1}, &.{left_one, 1}});
4306 try testOneShiftCase(.llshl, .{35, &.{0x800000000}, &.{1}});
4307 try testOneShiftCase(.llshl, .{35, &.{13534986488655118336, 233}, &.{125484842448}});
4308 try testOneShiftCase(.llshl, .{35, &.{0xf56df77800000000, 6}, &.{0xdeadbeef}});
4309 try testOneShiftCase(.llshl, .{35, &.{0xfffffff800000000, 0x7ffffffff}, &.{maxint}});
4310 try testOneShiftCase(.llshl, .{35, &.{0, 17179869184}, &.{left_one}});
4311 try testOneShiftCase(.llshl, .{35, &.{0, 0x800000000}, &.{0, 1}});
4312 try testOneShiftCase(.llshl, .{35, &.{0x800000000, 0x1000000000}, &.{1, 2}});
4313 try testOneShiftCase(.llshl, .{35, &.{0, 0xc00000000}, &.{left_one, 1}});
4314 try testOneShiftCase(.llshl, .{70, &.{0, 64}, &.{1}});
4315 try testOneShiftCase(.llshl, .{70, &.{0, 8031029916672}, &.{125484842448}});
4316 try testOneShiftCase(.llshl, .{70, &.{0, 0x37ab6fbbc0}, &.{0xdeadbeef}});
4317 try testOneShiftCase(.llshl, .{70, &.{0, 0xffffffffffffffc0, 63}, &.{maxint}});
4318 try testOneShiftCase(.llshl, .{70, &.{0, 0, 32}, &.{left_one}});
4319 try testOneShiftCase(.llshl, .{70, &.{0, 0, 64}, &.{0, 1}});
4320 try testOneShiftCase(.llshl, .{70, &.{0, 64, 128}, &.{1, 2}});
4321 try testOneShiftCase(.llshl, .{70, &.{0, 0, 0x60}, &.{left_one, 1}});
4322 // zig fmt: on
4323}
4324
4325test "llshl shift 0" {
4326 const n = @bitSizeOf(Limb);
4327 if (n <= 20) return error.SkipZigTest;
4328
4329 // zig fmt: off
4330 try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}});
4331 try testOneShiftCase(.llshl, .{1, &.{0}, &.{0}});
4332 try testOneShiftCase(.llshl, .{5, &.{0}, &.{0}});
4333 try testOneShiftCase(.llshl, .{13, &.{0}, &.{0}});
4334 try testOneShiftCase(.llshl, .{20, &.{0}, &.{0}});
4335 try testOneShiftCase(.llshl, .{0, &.{0, 0}, &.{0, 0}});
4336 try testOneShiftCase(.llshl, .{2, &.{0, 0}, &.{0, 0}});
4337 try testOneShiftCase(.llshl, .{7, &.{0, 0}, &.{0, 0}});
4338 try testOneShiftCase(.llshl, .{11, &.{0, 0}, &.{0, 0}});
4339 try testOneShiftCase(.llshl, .{19, &.{0, 0}, &.{0, 0}});
4340
4341 try testOneShiftCase(.llshl, .{0, &.{0}, &.{0}});
4342 try testOneShiftCase(.llshl, .{n, &.{0, 0}, &.{0}});
4343 try testOneShiftCase(.llshl, .{2*n, &.{0, 0, 0}, &.{0}});
4344 try testOneShiftCase(.llshl, .{3*n, &.{0, 0, 0, 0}, &.{0}});
4345 try testOneShiftCase(.llshl, .{4*n, &.{0, 0, 0, 0, 0}, &.{0}});
4346 try testOneShiftCase(.llshl, .{0, &.{0, 0}, &.{0, 0}});
4347 try testOneShiftCase(.llshl, .{n, &.{0, 0, 0}, &.{0, 0}});
4348 try testOneShiftCase(.llshl, .{2*n, &.{0, 0, 0, 0}, &.{0, 0}});
4349 try testOneShiftCase(.llshl, .{3*n, &.{0, 0, 0, 0, 0}, &.{0, 0}});
4350 try testOneShiftCase(.llshl, .{4*n, &.{0, 0, 0, 0, 0, 0}, &.{0, 0}});
4351 // zig fmt: on
4352}
4353
4354test "llshr shift 0" {
4355 const n = @bitSizeOf(Limb);
4356
4357 // zig fmt: off
4358 try testOneShiftCase(.llshr, .{0, &.{0}, &.{0}});
4359 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}});
4360 try testOneShiftCase(.llshr, .{5, &.{0}, &.{0}});
4361 try testOneShiftCase(.llshr, .{13, &.{0}, &.{0}});
4362 try testOneShiftCase(.llshr, .{20, &.{0}, &.{0}});
4363 try testOneShiftCase(.llshr, .{0, &.{0, 0}, &.{0, 0}});
4364 try testOneShiftCase(.llshr, .{2, &.{0}, &.{0, 0}});
4365 try testOneShiftCase(.llshr, .{7, &.{0}, &.{0, 0}});
4366 try testOneShiftCase(.llshr, .{11, &.{0}, &.{0, 0}});
4367 try testOneShiftCase(.llshr, .{19, &.{0}, &.{0, 0}});
4368
4369 try testOneShiftCase(.llshr, .{n, &.{0}, &.{0}});
4370 try testOneShiftCase(.llshr, .{2*n, &.{0}, &.{0}});
4371 try testOneShiftCase(.llshr, .{3*n, &.{0}, &.{0}});
4372 try testOneShiftCase(.llshr, .{4*n, &.{0}, &.{0}});
4373 try testOneShiftCase(.llshr, .{n, &.{0}, &.{0, 0}});
4374 try testOneShiftCase(.llshr, .{2*n, &.{0}, &.{0, 0}});
4375 try testOneShiftCase(.llshr, .{3*n, &.{0}, &.{0, 0}});
4376 try testOneShiftCase(.llshr, .{4*n, &.{0}, &.{0, 0}});
4377
4378 try testOneShiftCase(.llshr, .{1, &.{}, &.{}});
4379 try testOneShiftCase(.llshr, .{2, &.{}, &.{}});
4380 try testOneShiftCase(.llshr, .{64, &.{}, &.{}});
4381 // zig fmt: on
4382}
4383
4384test "llshr to 0" {
4385 const n = @bitSizeOf(Limb);
4386 if (n != 64 and n != 32) return error.SkipZigTest;
4387
4388 // zig fmt: off
4389 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}});
4390 try testOneShiftCase(.llshr, .{1, &.{0}, &.{1}});
4391 try testOneShiftCase(.llshr, .{5, &.{0}, &.{1}});
4392 try testOneShiftCase(.llshr, .{65, &.{0}, &.{0, 1}});
4393 try testOneShiftCase(.llshr, .{193, &.{0}, &.{0, 0, std.math.maxInt(Limb)}});
4394 try testOneShiftCase(.llshr, .{193, &.{0}, &.{std.math.maxInt(Limb), 1, std.math.maxInt(Limb)}});
4395 try testOneShiftCase(.llshr, .{193, &.{0}, &.{0xdeadbeef, 0xabcdefab, 0x1234}});
4396 // zig fmt: on
4397}
4398
4399test "llshr single" {
4400 if (limb_bits != 64) return error.SkipZigTest;
4401
4402 // 1 << 63
4403 const left_one = 0x8000000000000000;
4404 const maxint: Limb = 0xFFFFFFFFFFFFFFFF;
4405
4406 // zig fmt: off
4407 try testOneShiftCase(.llshr, .{0, &.{0}, &.{0}});
4408 try testOneShiftCase(.llshr, .{0, &.{1}, &.{1}});
4409 try testOneShiftCase(.llshr, .{0, &.{125484842448}, &.{125484842448}});
4410 try testOneShiftCase(.llshr, .{0, &.{0xdeadbeef}, &.{0xdeadbeef}});
4411 try testOneShiftCase(.llshr, .{0, &.{maxint}, &.{maxint}});
4412 try testOneShiftCase(.llshr, .{0, &.{left_one}, &.{left_one}});
4413 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0}});
4414 try testOneShiftCase(.llshr, .{1, &.{1}, &.{2}});
4415 try testOneShiftCase(.llshr, .{1, &.{62742421224}, &.{125484842448}});
4416 try testOneShiftCase(.llshr, .{1, &.{62742421223}, &.{125484842447}});
4417 try testOneShiftCase(.llshr, .{1, &.{0x6f56df77}, &.{0xdeadbeef}});
4418 try testOneShiftCase(.llshr, .{1, &.{0x7fffffffffffffff}, &.{maxint}});
4419 try testOneShiftCase(.llshr, .{1, &.{0x4000000000000000}, &.{left_one}});
4420 try testOneShiftCase(.llshr, .{8, &.{1}, &.{256}});
4421 try testOneShiftCase(.llshr, .{8, &.{490175165}, &.{125484842448}});
4422 try testOneShiftCase(.llshr, .{8, &.{0xdeadbe}, &.{0xdeadbeef}});
4423 try testOneShiftCase(.llshr, .{8, &.{0xffffffffffffff}, &.{maxint}});
4424 try testOneShiftCase(.llshr, .{8, &.{0x80000000000000}, &.{left_one}});
4425 // zig fmt: on
4426}
4427
4428test llshr {
4429 if (limb_bits != 64) return error.SkipZigTest;
4430
4431 // 1 << 63
4432 const left_one = 0x8000000000000000;
4433 const maxint: Limb = 0xFFFFFFFFFFFFFFFF;
4434
4435 // zig fmt: off
4436 try testOneShiftCase(.llshr, .{0, &.{0, 0}, &.{0, 0}});
4437 try testOneShiftCase(.llshr, .{0, &.{0, 1}, &.{0, 1}});
4438 try testOneShiftCase(.llshr, .{0, &.{15, 1}, &.{15, 1}});
4439 try testOneShiftCase(.llshr, .{0, &.{987656565, 123456789456}, &.{987656565, 123456789456}});
4440 try testOneShiftCase(.llshr, .{0, &.{0xfeebdaed, 0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}});
4441 try testOneShiftCase(.llshr, .{0, &.{1, maxint}, &.{1, maxint}});
4442 try testOneShiftCase(.llshr, .{0, &.{0, left_one}, &.{0, left_one}});
4443 try testOneShiftCase(.llshr, .{1, &.{0}, &.{0, 0}});
4444 try testOneShiftCase(.llshr, .{1, &.{left_one}, &.{0, 1}});
4445 try testOneShiftCase(.llshr, .{1, &.{0x8000000000000007}, &.{15, 1}});
4446 try testOneShiftCase(.llshr, .{1, &.{493828282, 61728394728}, &.{987656565, 123456789456}});
4447 try testOneShiftCase(.llshr, .{1, &.{0x800000007f75ed76, 0x6f56df77}, &.{0xfeebdaed, 0xdeadbeef}});
4448 try testOneShiftCase(.llshr, .{1, &.{left_one, 0x7fffffffffffffff}, &.{1, maxint}});
4449 try testOneShiftCase(.llshr, .{1, &.{0, 0x4000000000000000}, &.{0, left_one}});
4450 try testOneShiftCase(.llshr, .{64, &.{0}, &.{0, 0}});
4451 try testOneShiftCase(.llshr, .{64, &.{1}, &.{0, 1}});
4452 try testOneShiftCase(.llshr, .{64, &.{1}, &.{15, 1}});
4453 try testOneShiftCase(.llshr, .{64, &.{123456789456}, &.{987656565, 123456789456}});
4454 try testOneShiftCase(.llshr, .{64, &.{0xdeadbeef}, &.{0xfeebdaed, 0xdeadbeef}});
4455 try testOneShiftCase(.llshr, .{64, &.{maxint}, &.{1, maxint}});
4456 try testOneShiftCase(.llshr, .{64, &.{left_one}, &.{0, left_one}});
4457 try testOneShiftCase(.llshr, .{72, &.{0}, &.{0, 0}});
4458 try testOneShiftCase(.llshr, .{72, &.{0}, &.{0, 1}});
4459 try testOneShiftCase(.llshr, .{72, &.{0}, &.{15, 1}});
4460 try testOneShiftCase(.llshr, .{72, &.{482253083}, &.{987656565, 123456789456}});
4461 try testOneShiftCase(.llshr, .{72, &.{0xdeadbe}, &.{0xfeebdaed, 0xdeadbeef}});
4462 try testOneShiftCase(.llshr, .{72, &.{0xffffffffffffff}, &.{1, maxint}});
4463 try testOneShiftCase(.llshr, .{72, &.{0x80000000000000}, &.{0, left_one}});
4464 // zig fmt: on
4465}
4466
4467const Case = struct { usize, []const Limb, []const Limb };
4468
4469fn testOneShiftCase(comptime function: enum { llshr, llshl }, case: Case) !void {
4470 const func = if (function == .llshl) llshl else llshr;
4471 const shift_direction = if (function == .llshl) -1 else 1;
4472
4473 try testOneShiftCaseNoAliasing(func, case);
4474 try testOneShiftCaseAliasing(func, case, shift_direction);
4475}
4476
4477fn testOneShiftCaseNoAliasing(func: fn ([]Limb, []const Limb, usize) usize, case: Case) !void {
4478 const padding = std.math.maxInt(Limb);
4479 var r: [20]Limb = @splat(padding);
4480
4481 const shift = case[0];
4482 const expected = case[1];
4483 const data = case[2];
4484
4485 std.debug.assert(expected.len <= 20);
4486
4487 const len = func(&r, data, shift);
4488
4489 try std.testing.expectEqual(expected.len, len);
4490 try std.testing.expectEqualSlices(Limb, expected, r[0..len]);
4491 try std.testing.expect(mem.allEqual(Limb, r[len..], padding));
4492}
4493
4494fn testOneShiftCaseAliasing(func: fn ([]Limb, []const Limb, usize) usize, case: Case, shift_direction: isize) !void {
4495 const padding = std.math.maxInt(Limb);
4496 var r: [60]Limb = @splat(padding);
4497 const base = 20;
4498
4499 assert(shift_direction == 1 or shift_direction == -1);
4500
4501 for (0..10) |limb_shift| {
4502 const shift = case[0];
4503 const expected = case[1];
4504 const data = case[2];
4505
4506 std.debug.assert(expected.len <= 20);
4507
4508 @memset(&r, padding);
4509 const final_limb_base: usize = @intCast(base + shift_direction * @as(isize, @intCast(limb_shift)));
4510 const written_data = r[final_limb_base..][0..data.len];
4511 @memcpy(written_data, data);
4512
4513 const len = func(r[base..], written_data, shift);
4514
4515 try std.testing.expectEqual(expected.len, len);
4516 try std.testing.expectEqualSlices(Limb, expected, r[base .. base + len]);
4517 }
4518}
lib/std/math/big/int_test.zig+371-371
...@@ -29,7 +29,7 @@ test "comptime_int set" {...@@ -29,7 +29,7 @@ test "comptime_int set" {
29 const result = @as(Limb, s & maxInt(Limb));29 const result = @as(Limb, s & maxInt(Limb));
30 s >>= @typeInfo(Limb).int.bits / 2;30 s >>= @typeInfo(Limb).int.bits / 2;
31 s >>= @typeInfo(Limb).int.bits / 2;31 s >>= @typeInfo(Limb).int.bits / 2;
32 try testing.expect(a.limbs[i] == result);32 try testing.expectEqual(result, a.limbs[i]);
33 }33 }
34}34}
3535
...@@ -37,37 +37,37 @@ test "comptime_int set negative" {...@@ -37,37 +37,37 @@ test "comptime_int set negative" {
37 var a = try Managed.initSet(testing.allocator, -10);37 var a = try Managed.initSet(testing.allocator, -10);
38 defer a.deinit();38 defer a.deinit();
3939
40 try testing.expect(a.limbs[0] == 10);40 try testing.expectEqual(10, a.limbs[0]);
41 try testing.expect(a.isPositive() == false);41 try testing.expectEqual(false, a.isPositive());
42}42}
4343
44test "int set unaligned small" {44test "int set unaligned small" {
45 var a = try Managed.initSet(testing.allocator, @as(u7, 45));45 var a = try Managed.initSet(testing.allocator, @as(u7, 45));
46 defer a.deinit();46 defer a.deinit();
4747
48 try testing.expect(a.limbs[0] == 45);48 try testing.expectEqual(45, a.limbs[0]);
49 try testing.expect(a.isPositive() == true);49 try testing.expectEqual(true, a.isPositive());
50}50}
5151
52test "comptime_int to" {52test "comptime_int to" {
53 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);53 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
54 defer a.deinit();54 defer a.deinit();
5555
56 try testing.expect((try a.toInt(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);56 try testing.expectEqual(0xefffffff00000001eeeeeeefaaaaaaab, try a.toInt(u128));
57}57}
5858
59test "sub-limb to" {59test "sub-limb to" {
60 var a = try Managed.initSet(testing.allocator, 10);60 var a = try Managed.initSet(testing.allocator, 10);
61 defer a.deinit();61 defer a.deinit();
6262
63 try testing.expect((try a.toInt(u8)) == 10);63 try testing.expectEqual(10, try a.toInt(u8));
64}64}
6565
66test "set negative minimum" {66test "set negative minimum" {
67 var a = try Managed.initSet(testing.allocator, @as(i64, minInt(i64)));67 var a = try Managed.initSet(testing.allocator, @as(i64, minInt(i64)));
68 defer a.deinit();68 defer a.deinit();
6969
70 try testing.expect((try a.toInt(i64)) == minInt(i64));70 try testing.expectEqual(minInt(i64), try a.toInt(i64));
71}71}
7272
73test "set double-width maximum then zero" {73test "set double-width maximum then zero" {
...@@ -95,22 +95,22 @@ test "normalize" {...@@ -95,22 +95,22 @@ test "normalize" {
95 a.limbs[2] = 3;95 a.limbs[2] = 3;
96 a.limbs[3] = 0;96 a.limbs[3] = 0;
97 a.normalize(4);97 a.normalize(4);
98 try testing.expect(a.len() == 3);98 try testing.expectEqual(3, a.len());
9999
100 a.limbs[0] = 1;100 a.limbs[0] = 1;
101 a.limbs[1] = 2;101 a.limbs[1] = 2;
102 a.limbs[2] = 3;102 a.limbs[2] = 3;
103 a.normalize(3);103 a.normalize(3);
104 try testing.expect(a.len() == 3);104 try testing.expectEqual(3, a.len());
105105
106 a.limbs[0] = 0;106 a.limbs[0] = 0;
107 a.limbs[1] = 0;107 a.limbs[1] = 0;
108 a.normalize(2);108 a.normalize(2);
109 try testing.expect(a.len() == 1);109 try testing.expectEqual(1, a.len());
110110
111 a.limbs[0] = 0;111 a.limbs[0] = 0;
112 a.normalize(1);112 a.normalize(1);
113 try testing.expect(a.len() == 1);113 try testing.expectEqual(1, a.len());
114}114}
115115
116test "normalize multi" {116test "normalize multi" {
...@@ -123,24 +123,24 @@ test "normalize multi" {...@@ -123,24 +123,24 @@ test "normalize multi" {
123 a.limbs[2] = 0;123 a.limbs[2] = 0;
124 a.limbs[3] = 0;124 a.limbs[3] = 0;
125 a.normalize(4);125 a.normalize(4);
126 try testing.expect(a.len() == 2);126 try testing.expectEqual(2, a.len());
127127
128 a.limbs[0] = 1;128 a.limbs[0] = 1;
129 a.limbs[1] = 2;129 a.limbs[1] = 2;
130 a.limbs[2] = 3;130 a.limbs[2] = 3;
131 a.normalize(3);131 a.normalize(3);
132 try testing.expect(a.len() == 3);132 try testing.expectEqual(3, a.len());
133133
134 a.limbs[0] = 0;134 a.limbs[0] = 0;
135 a.limbs[1] = 0;135 a.limbs[1] = 0;
136 a.limbs[2] = 0;136 a.limbs[2] = 0;
137 a.limbs[3] = 0;137 a.limbs[3] = 0;
138 a.normalize(4);138 a.normalize(4);
139 try testing.expect(a.len() == 1);139 try testing.expectEqual(1, a.len());
140140
141 a.limbs[0] = 0;141 a.limbs[0] = 0;
142 a.normalize(1);142 a.normalize(1);
143 try testing.expect(a.len() == 1);143 try testing.expectEqual(1, a.len());
144}144}
145145
146test "parity" {146test "parity" {
...@@ -161,26 +161,26 @@ test "bitcount + sizeInBaseUpperBound" {...@@ -161,26 +161,26 @@ test "bitcount + sizeInBaseUpperBound" {
161 defer a.deinit();161 defer a.deinit();
162162
163 try a.set(0b100);163 try a.set(0b100);
164 try testing.expect(a.bitCountAbs() == 3);164 try testing.expectEqual(3, a.bitCountAbs());
165 try testing.expect(a.sizeInBaseUpperBound(2) >= 3);165 try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
166 try testing.expect(a.sizeInBaseUpperBound(10) >= 1);166 try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
167167
168 a.negate();168 a.negate();
169 try testing.expect(a.bitCountAbs() == 3);169 try testing.expectEqual(3, a.bitCountAbs());
170 try testing.expect(a.sizeInBaseUpperBound(2) >= 4);170 try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
171 try testing.expect(a.sizeInBaseUpperBound(10) >= 2);171 try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
172172
173 try a.set(0xffffffff);173 try a.set(0xffffffff);
174 try testing.expect(a.bitCountAbs() == 32);174 try testing.expectEqual(32, a.bitCountAbs());
175 try testing.expect(a.sizeInBaseUpperBound(2) >= 32);175 try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
176 try testing.expect(a.sizeInBaseUpperBound(10) >= 10);176 try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
177177
178 try a.shiftLeft(&a, 5000);178 try a.shiftLeft(&a, 5000);
179 try testing.expect(a.bitCountAbs() == 5032);179 try testing.expectEqual(5032, a.bitCountAbs());
180 try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);180 try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
181 a.setSign(false);181 a.setSign(false);
182182
183 try testing.expect(a.bitCountAbs() == 5032);183 try testing.expectEqual(5032, a.bitCountAbs());
184 try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);184 try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
185}185}
186186
...@@ -189,30 +189,30 @@ test "bitcount/to" {...@@ -189,30 +189,30 @@ test "bitcount/to" {
189 defer a.deinit();189 defer a.deinit();
190190
191 try a.set(0);191 try a.set(0);
192 try testing.expect(a.bitCountTwosComp() == 0);192 try testing.expectEqual(0, a.bitCountTwosComp());
193193
194 try testing.expect((try a.toInt(u0)) == 0);194 try testing.expectEqual(0, try a.toInt(u0));
195 try testing.expect((try a.toInt(i0)) == 0);195 try testing.expectEqual(0, try a.toInt(i0));
196196
197 try a.set(-1);197 try a.set(-1);
198 try testing.expect(a.bitCountTwosComp() == 1);198 try testing.expectEqual(1, a.bitCountTwosComp());
199 try testing.expect((try a.toInt(i1)) == -1);199 try testing.expectEqual(-1, try a.toInt(i1));
200200
201 try a.set(-8);201 try a.set(-8);
202 try testing.expect(a.bitCountTwosComp() == 4);202 try testing.expectEqual(4, a.bitCountTwosComp());
203 try testing.expect((try a.toInt(i4)) == -8);203 try testing.expectEqual(-8, try a.toInt(i4));
204204
205 try a.set(127);205 try a.set(127);
206 try testing.expect(a.bitCountTwosComp() == 7);206 try testing.expectEqual(7, a.bitCountTwosComp());
207 try testing.expect((try a.toInt(u7)) == 127);207 try testing.expectEqual(127, try a.toInt(u7));
208208
209 try a.set(-128);209 try a.set(-128);
210 try testing.expect(a.bitCountTwosComp() == 8);210 try testing.expectEqual(8, a.bitCountTwosComp());
211 try testing.expect((try a.toInt(i8)) == -128);211 try testing.expectEqual(-128, try a.toInt(i8));
212212
213 try a.set(-129);213 try a.set(-129);
214 try testing.expect(a.bitCountTwosComp() == 9);214 try testing.expectEqual(9, a.bitCountTwosComp());
215 try testing.expect((try a.toInt(i9)) == -129);215 try testing.expectEqual(-129, try a.toInt(i9));
216}216}
217217
218test "fits" {218test "fits" {
...@@ -248,7 +248,7 @@ test "string set" {...@@ -248,7 +248,7 @@ test "string set" {
248 defer a.deinit();248 defer a.deinit();
249249
250 try a.setString(10, "120317241209124781241290847124");250 try a.setString(10, "120317241209124781241290847124");
251 try testing.expect((try a.toInt(u128)) == 120317241209124781241290847124);251 try testing.expectEqual(120317241209124781241290847124, try a.toInt(u128));
252}252}
253253
254test "string negative" {254test "string negative" {
...@@ -256,7 +256,7 @@ test "string negative" {...@@ -256,7 +256,7 @@ test "string negative" {
256 defer a.deinit();256 defer a.deinit();
257257
258 try a.setString(10, "-1023");258 try a.setString(10, "-1023");
259 try testing.expect((try a.toInt(i32)) == -1023);259 try testing.expectEqual(-1023, try a.toInt(i32));
260}260}
261261
262test "string set number with underscores" {262test "string set number with underscores" {
...@@ -264,7 +264,7 @@ test "string set number with underscores" {...@@ -264,7 +264,7 @@ test "string set number with underscores" {
264 defer a.deinit();264 defer a.deinit();
265265
266 try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");266 try a.setString(10, "__1_2_0_3_1_7_2_4_1_2_0_____9_1__2__4_7_8_1_2_4_1_2_9_0_8_4_7_1_2_4___");
267 try testing.expect((try a.toInt(u128)) == 120317241209124781241290847124);267 try testing.expectEqual(120317241209124781241290847124, try a.toInt(u128));
268}268}
269269
270test "string set case insensitive number" {270test "string set case insensitive number" {
...@@ -272,7 +272,7 @@ test "string set case insensitive number" {...@@ -272,7 +272,7 @@ test "string set case insensitive number" {
272 defer a.deinit();272 defer a.deinit();
273273
274 try a.setString(16, "aB_cD_eF");274 try a.setString(16, "aB_cD_eF");
275 try testing.expect((try a.toInt(u32)) == 0xabcdef);275 try testing.expectEqual(0xabcdef, try a.toInt(u32));
276}276}
277277
278test "string set base 36" {278test "string set base 36" {
...@@ -280,7 +280,7 @@ test "string set base 36" {...@@ -280,7 +280,7 @@ test "string set base 36" {
280 defer a.deinit();280 defer a.deinit();
281281
282 try a.setString(36, "fifvthrv1mzt79ez9");282 try a.setString(36, "fifvthrv1mzt79ez9");
283 try testing.expect((try a.to(u128)) == 123456789123456789123456789);283 try testing.expectEqual(123456789123456789123456789, try a.to(u128));
284}284}
285285
286test "string set bad char error" {286test "string set bad char error" {
...@@ -314,11 +314,11 @@ fn testTwosComplementLimit(comptime T: type) !void {...@@ -314,11 +314,11 @@ fn testTwosComplementLimit(comptime T: type) !void {
314314
315 try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);315 try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);
316 const max: T = maxInt(T);316 const max: T = maxInt(T);
317 try testing.expect(max == try a.toInt(T));317 try testing.expectEqual(max, try a.toInt(T));
318318
319 try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);319 try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);
320 const min: T = minInt(T);320 const min: T = minInt(T);
321 try testing.expect(min == try a.toInt(T));321 try testing.expectEqual(min, try a.toInt(T));
322}322}
323323
324test "string to" {324test "string to" {
...@@ -400,12 +400,12 @@ test "clone" {...@@ -400,12 +400,12 @@ test "clone" {
400 var b = try a.clone();400 var b = try a.clone();
401 defer b.deinit();401 defer b.deinit();
402402
403 try testing.expect((try a.toInt(u32)) == 1234);403 try testing.expectEqual(1234, try a.toInt(u32));
404 try testing.expect((try b.toInt(u32)) == 1234);404 try testing.expectEqual(1234, try b.toInt(u32));
405405
406 try a.set(77);406 try a.set(77);
407 try testing.expect((try a.toInt(u32)) == 77);407 try testing.expectEqual(77, try a.toInt(u32));
408 try testing.expect((try b.toInt(u32)) == 1234);408 try testing.expectEqual(1234, try b.toInt(u32));
409}409}
410410
411test "swap" {411test "swap" {
...@@ -414,20 +414,20 @@ test "swap" {...@@ -414,20 +414,20 @@ test "swap" {
414 var b = try Managed.initSet(testing.allocator, 5678);414 var b = try Managed.initSet(testing.allocator, 5678);
415 defer b.deinit();415 defer b.deinit();
416416
417 try testing.expect((try a.toInt(u32)) == 1234);417 try testing.expectEqual(1234, try a.toInt(u32));
418 try testing.expect((try b.toInt(u32)) == 5678);418 try testing.expectEqual(5678, try b.toInt(u32));
419419
420 a.swap(&b);420 a.swap(&b);
421421
422 try testing.expect((try a.toInt(u32)) == 5678);422 try testing.expectEqual(5678, try a.toInt(u32));
423 try testing.expect((try b.toInt(u32)) == 1234);423 try testing.expectEqual(1234, try b.toInt(u32));
424}424}
425425
426test "to negative" {426test "to negative" {
427 var a = try Managed.initSet(testing.allocator, -10);427 var a = try Managed.initSet(testing.allocator, -10);
428 defer a.deinit();428 defer a.deinit();
429429
430 try testing.expect((try a.toInt(i32)) == -10);430 try testing.expectEqual(-10, try a.toInt(i32));
431}431}
432432
433test "compare" {433test "compare" {
...@@ -436,8 +436,8 @@ test "compare" {...@@ -436,8 +436,8 @@ test "compare" {
436 var b = try Managed.initSet(testing.allocator, 10);436 var b = try Managed.initSet(testing.allocator, 10);
437 defer b.deinit();437 defer b.deinit();
438438
439 try testing.expect(a.orderAbs(b) == .gt);439 try testing.expectEqual(.gt, a.orderAbs(b));
440 try testing.expect(a.order(b) == .lt);440 try testing.expectEqual(.lt, a.order(b));
441}441}
442442
443test "compare similar" {443test "compare similar" {
...@@ -446,8 +446,8 @@ test "compare similar" {...@@ -446,8 +446,8 @@ test "compare similar" {
446 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);446 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
447 defer b.deinit();447 defer b.deinit();
448448
449 try testing.expect(a.orderAbs(b) == .lt);449 try testing.expectEqual(.lt, a.orderAbs(b));
450 try testing.expect(b.orderAbs(a) == .gt);450 try testing.expectEqual(.gt, b.orderAbs(a));
451}451}
452452
453test "compare different limb size" {453test "compare different limb size" {
...@@ -456,8 +456,8 @@ test "compare different limb size" {...@@ -456,8 +456,8 @@ test "compare different limb size" {
456 var b = try Managed.initSet(testing.allocator, 1);456 var b = try Managed.initSet(testing.allocator, 1);
457 defer b.deinit();457 defer b.deinit();
458458
459 try testing.expect(a.orderAbs(b) == .gt);459 try testing.expectEqual(.gt, a.orderAbs(b));
460 try testing.expect(b.orderAbs(a) == .lt);460 try testing.expectEqual(.lt, b.orderAbs(a));
461}461}
462462
463test "compare multi-limb" {463test "compare multi-limb" {
...@@ -466,8 +466,8 @@ test "compare multi-limb" {...@@ -466,8 +466,8 @@ test "compare multi-limb" {
466 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);466 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
467 defer b.deinit();467 defer b.deinit();
468468
469 try testing.expect(a.orderAbs(b) == .gt);469 try testing.expectEqual(.gt, a.orderAbs(b));
470 try testing.expect(a.order(b) == .lt);470 try testing.expectEqual(.lt, a.order(b));
471}471}
472472
473test "equality" {473test "equality" {
...@@ -485,10 +485,10 @@ test "abs" {...@@ -485,10 +485,10 @@ test "abs" {
485 defer a.deinit();485 defer a.deinit();
486486
487 a.abs();487 a.abs();
488 try testing.expect((try a.toInt(u32)) == 5);488 try testing.expectEqual(5, try a.toInt(u32));
489489
490 a.abs();490 a.abs();
491 try testing.expect((try a.toInt(u32)) == 5);491 try testing.expectEqual(5, try a.toInt(u32));
492}492}
493493
494test "negate" {494test "negate" {
...@@ -496,10 +496,10 @@ test "negate" {...@@ -496,10 +496,10 @@ test "negate" {
496 defer a.deinit();496 defer a.deinit();
497497
498 a.negate();498 a.negate();
499 try testing.expect((try a.toInt(i32)) == -5);499 try testing.expectEqual(-5, try a.toInt(i32));
500500
501 a.negate();501 a.negate();
502 try testing.expect((try a.toInt(i32)) == 5);502 try testing.expectEqual(5, try a.toInt(i32));
503}503}
504504
505test "add single-single" {505test "add single-single" {
...@@ -512,7 +512,7 @@ test "add single-single" {...@@ -512,7 +512,7 @@ test "add single-single" {
512 defer c.deinit();512 defer c.deinit();
513 try c.add(&a, &b);513 try c.add(&a, &b);
514514
515 try testing.expect((try c.toInt(u32)) == 55);515 try testing.expectEqual(55, try c.toInt(u32));
516}516}
517517
518test "add multi-single" {518test "add multi-single" {
...@@ -525,10 +525,10 @@ test "add multi-single" {...@@ -525,10 +525,10 @@ test "add multi-single" {
525 defer c.deinit();525 defer c.deinit();
526526
527 try c.add(&a, &b);527 try c.add(&a, &b);
528 try testing.expect((try c.toInt(DoubleLimb)) == maxInt(Limb) + 2);528 try testing.expectEqual(maxInt(Limb) + 2, try c.toInt(DoubleLimb));
529529
530 try c.add(&b, &a);530 try c.add(&b, &a);
531 try testing.expect((try c.toInt(DoubleLimb)) == maxInt(Limb) + 2);531 try testing.expectEqual(maxInt(Limb) + 2, try c.toInt(DoubleLimb));
532}532}
533533
534test "add multi-multi" {534test "add multi-multi" {
...@@ -546,7 +546,7 @@ test "add multi-multi" {...@@ -546,7 +546,7 @@ test "add multi-multi" {
546 defer c.deinit();546 defer c.deinit();
547 try c.add(&a, &b);547 try c.add(&a, &b);
548548
549 try testing.expect((try c.toInt(u128)) == op1 + op2);549 try testing.expectEqual(op1 + op2, try c.toInt(u128));
550}550}
551551
552test "add zero-zero" {552test "add zero-zero" {
...@@ -559,7 +559,7 @@ test "add zero-zero" {...@@ -559,7 +559,7 @@ test "add zero-zero" {
559 defer c.deinit();559 defer c.deinit();
560 try c.add(&a, &b);560 try c.add(&a, &b);
561561
562 try testing.expect((try c.toInt(u32)) == 0);562 try testing.expectEqual(0, try c.toInt(u32));
563}563}
564564
565test "add alias multi-limb nonzero-zero" {565test "add alias multi-limb nonzero-zero" {
...@@ -571,7 +571,7 @@ test "add alias multi-limb nonzero-zero" {...@@ -571,7 +571,7 @@ test "add alias multi-limb nonzero-zero" {
571571
572 try a.add(&a, &b);572 try a.add(&a, &b);
573573
574 try testing.expect((try a.toInt(u128)) == op1);574 try testing.expectEqual(op1, try a.toInt(u128));
575}575}
576576
577test "add sign" {577test "add sign" {
...@@ -588,16 +588,16 @@ test "add sign" {...@@ -588,16 +588,16 @@ test "add sign" {
588 defer neg_two.deinit();588 defer neg_two.deinit();
589589
590 try a.add(&one, &two);590 try a.add(&one, &two);
591 try testing.expect((try a.toInt(i32)) == 3);591 try testing.expectEqual(3, try a.toInt(i32));
592592
593 try a.add(&neg_one, &two);593 try a.add(&neg_one, &two);
594 try testing.expect((try a.toInt(i32)) == 1);594 try testing.expectEqual(1, try a.toInt(i32));
595595
596 try a.add(&one, &neg_two);596 try a.add(&one, &neg_two);
597 try testing.expect((try a.toInt(i32)) == -1);597 try testing.expectEqual(-1, try a.toInt(i32));
598598
599 try a.add(&neg_one, &neg_two);599 try a.add(&neg_one, &neg_two);
600 try testing.expect((try a.toInt(i32)) == -3);600 try testing.expectEqual(-3, try a.toInt(i32));
601}601}
602602
603test "add comptime scalar" {603test "add comptime scalar" {
...@@ -608,7 +608,7 @@ test "add comptime scalar" {...@@ -608,7 +608,7 @@ test "add comptime scalar" {
608 defer b.deinit();608 defer b.deinit();
609 try b.addScalar(&a, 5);609 try b.addScalar(&a, 5);
610610
611 try testing.expect((try b.toInt(u32)) == 55);611 try testing.expectEqual(55, try b.toInt(u32));
612}612}
613613
614test "add scalar" {614test "add scalar" {
...@@ -619,7 +619,7 @@ test "add scalar" {...@@ -619,7 +619,7 @@ test "add scalar" {
619 defer b.deinit();619 defer b.deinit();
620 try b.addScalar(&a, @as(u32, 31));620 try b.addScalar(&a, @as(u32, 31));
621621
622 try testing.expect((try b.toInt(u32)) == 154);622 try testing.expectEqual(154, try b.toInt(u32));
623}623}
624624
625test "addWrap single-single, unsigned" {625test "addWrap single-single, unsigned" {
...@@ -632,7 +632,7 @@ test "addWrap single-single, unsigned" {...@@ -632,7 +632,7 @@ test "addWrap single-single, unsigned" {
632 const wrapped = try a.addWrap(&a, &b, .unsigned, 17);632 const wrapped = try a.addWrap(&a, &b, .unsigned, 17);
633633
634 try testing.expect(wrapped);634 try testing.expect(wrapped);
635 try testing.expect((try a.toInt(u17)) == 9);635 try testing.expectEqual(9, try a.toInt(u17));
636}636}
637637
638test "subWrap single-single, unsigned" {638test "subWrap single-single, unsigned" {
...@@ -645,7 +645,7 @@ test "subWrap single-single, unsigned" {...@@ -645,7 +645,7 @@ test "subWrap single-single, unsigned" {
645 const wrapped = try a.subWrap(&a, &b, .unsigned, 17);645 const wrapped = try a.subWrap(&a, &b, .unsigned, 17);
646646
647 try testing.expect(wrapped);647 try testing.expect(wrapped);
648 try testing.expect((try a.toInt(u17)) == 1);648 try testing.expectEqual(1, try a.toInt(u17));
649}649}
650650
651test "addWrap multi-multi, unsigned, limb aligned" {651test "addWrap multi-multi, unsigned, limb aligned" {
...@@ -658,7 +658,7 @@ test "addWrap multi-multi, unsigned, limb aligned" {...@@ -658,7 +658,7 @@ test "addWrap multi-multi, unsigned, limb aligned" {
658 const wrapped = try a.addWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));658 const wrapped = try a.addWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));
659659
660 try testing.expect(wrapped);660 try testing.expect(wrapped);
661 try testing.expect((try a.toInt(DoubleLimb)) == maxInt(DoubleLimb) - 1);661 try testing.expectEqual(maxInt(DoubleLimb) - 1, try a.toInt(DoubleLimb));
662}662}
663663
664test "subWrap single-multi, unsigned, limb aligned" {664test "subWrap single-multi, unsigned, limb aligned" {
...@@ -671,7 +671,7 @@ test "subWrap single-multi, unsigned, limb aligned" {...@@ -671,7 +671,7 @@ test "subWrap single-multi, unsigned, limb aligned" {
671 const wrapped = try a.subWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));671 const wrapped = try a.subWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));
672672
673 try testing.expect(wrapped);673 try testing.expect(wrapped);
674 try testing.expect((try a.toInt(DoubleLimb)) == maxInt(DoubleLimb) - 88);674 try testing.expectEqual(maxInt(DoubleLimb) - 88, try a.toInt(DoubleLimb));
675}675}
676676
677test "addWrap single-single, signed" {677test "addWrap single-single, signed" {
...@@ -684,7 +684,7 @@ test "addWrap single-single, signed" {...@@ -684,7 +684,7 @@ test "addWrap single-single, signed" {
684 const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(i21));684 const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(i21));
685685
686 try testing.expect(wrapped);686 try testing.expect(wrapped);
687 try testing.expect((try a.toInt(i21)) == minInt(i21));687 try testing.expectEqual(minInt(i21), try a.toInt(i21));
688}688}
689689
690test "subWrap single-single, signed" {690test "subWrap single-single, signed" {
...@@ -697,7 +697,7 @@ test "subWrap single-single, signed" {...@@ -697,7 +697,7 @@ test "subWrap single-single, signed" {
697 const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(i21));697 const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(i21));
698698
699 try testing.expect(wrapped);699 try testing.expect(wrapped);
700 try testing.expect((try a.toInt(i21)) == maxInt(i21));700 try testing.expectEqual(maxInt(i21), try a.toInt(i21));
701}701}
702702
703test "addWrap multi-multi, signed, limb aligned" {703test "addWrap multi-multi, signed, limb aligned" {
...@@ -710,7 +710,7 @@ test "addWrap multi-multi, signed, limb aligned" {...@@ -710,7 +710,7 @@ test "addWrap multi-multi, signed, limb aligned" {
710 const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));710 const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));
711711
712 try testing.expect(wrapped);712 try testing.expect(wrapped);
713 try testing.expect((try a.toInt(SignedDoubleLimb)) == -2);713 try testing.expectEqual(-2, try a.toInt(SignedDoubleLimb));
714}714}
715715
716test "subWrap single-multi, signed, limb aligned" {716test "subWrap single-multi, signed, limb aligned" {
...@@ -723,7 +723,7 @@ test "subWrap single-multi, signed, limb aligned" {...@@ -723,7 +723,7 @@ test "subWrap single-multi, signed, limb aligned" {
723 const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));723 const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));
724724
725 try testing.expect(wrapped);725 try testing.expect(wrapped);
726 try testing.expect((try a.toInt(SignedDoubleLimb)) == maxInt(SignedDoubleLimb));726 try testing.expectEqual(maxInt(SignedDoubleLimb), try a.toInt(SignedDoubleLimb));
727}727}
728728
729test "addWrap returns normalized result" {729test "addWrap returns normalized result" {
...@@ -763,7 +763,7 @@ test "addSat single-single, unsigned" {...@@ -763,7 +763,7 @@ test "addSat single-single, unsigned" {
763763
764 try a.addSat(&a, &b, .unsigned, 17);764 try a.addSat(&a, &b, .unsigned, 17);
765765
766 try testing.expect((try a.toInt(u17)) == maxInt(u17));766 try testing.expectEqual(maxInt(u17), try a.toInt(u17));
767}767}
768768
769test "subSat single-single, unsigned" {769test "subSat single-single, unsigned" {
...@@ -775,7 +775,7 @@ test "subSat single-single, unsigned" {...@@ -775,7 +775,7 @@ test "subSat single-single, unsigned" {
775775
776 try a.subSat(&a, &b, .unsigned, 17);776 try a.subSat(&a, &b, .unsigned, 17);
777777
778 try testing.expect((try a.toInt(u17)) == 0);778 try testing.expectEqual(0, try a.toInt(u17));
779}779}
780780
781test "addSat multi-multi, unsigned, limb aligned" {781test "addSat multi-multi, unsigned, limb aligned" {
...@@ -787,7 +787,7 @@ test "addSat multi-multi, unsigned, limb aligned" {...@@ -787,7 +787,7 @@ test "addSat multi-multi, unsigned, limb aligned" {
787787
788 try a.addSat(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));788 try a.addSat(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));
789789
790 try testing.expect((try a.toInt(DoubleLimb)) == maxInt(DoubleLimb));790 try testing.expectEqual(maxInt(DoubleLimb), try a.toInt(DoubleLimb));
791}791}
792792
793test "subSat single-multi, unsigned, limb aligned" {793test "subSat single-multi, unsigned, limb aligned" {
...@@ -799,7 +799,7 @@ test "subSat single-multi, unsigned, limb aligned" {...@@ -799,7 +799,7 @@ test "subSat single-multi, unsigned, limb aligned" {
799799
800 try a.subSat(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));800 try a.subSat(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));
801801
802 try testing.expect((try a.toInt(DoubleLimb)) == 0);802 try testing.expectEqual(0, try a.toInt(DoubleLimb));
803}803}
804804
805test "addSat single-single, signed" {805test "addSat single-single, signed" {
...@@ -811,7 +811,7 @@ test "addSat single-single, signed" {...@@ -811,7 +811,7 @@ test "addSat single-single, signed" {
811811
812 try a.addSat(&a, &b, .signed, @bitSizeOf(i14));812 try a.addSat(&a, &b, .signed, @bitSizeOf(i14));
813813
814 try testing.expect((try a.toInt(i14)) == maxInt(i14));814 try testing.expectEqual(maxInt(i14), try a.toInt(i14));
815}815}
816816
817test "subSat single-single, signed" {817test "subSat single-single, signed" {
...@@ -823,7 +823,7 @@ test "subSat single-single, signed" {...@@ -823,7 +823,7 @@ test "subSat single-single, signed" {
823823
824 try a.subSat(&a, &b, .signed, @bitSizeOf(i21));824 try a.subSat(&a, &b, .signed, @bitSizeOf(i21));
825825
826 try testing.expect((try a.toInt(i21)) == minInt(i21));826 try testing.expectEqual(minInt(i21), try a.toInt(i21));
827}827}
828828
829test "addSat multi-multi, signed, limb aligned" {829test "addSat multi-multi, signed, limb aligned" {
...@@ -835,7 +835,7 @@ test "addSat multi-multi, signed, limb aligned" {...@@ -835,7 +835,7 @@ test "addSat multi-multi, signed, limb aligned" {
835835
836 try a.addSat(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));836 try a.addSat(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));
837837
838 try testing.expect((try a.toInt(SignedDoubleLimb)) == maxInt(SignedDoubleLimb));838 try testing.expectEqual(maxInt(SignedDoubleLimb), try a.toInt(SignedDoubleLimb));
839}839}
840840
841test "subSat single-multi, signed, limb aligned" {841test "subSat single-multi, signed, limb aligned" {
...@@ -847,7 +847,7 @@ test "subSat single-multi, signed, limb aligned" {...@@ -847,7 +847,7 @@ test "subSat single-multi, signed, limb aligned" {
847847
848 try a.subSat(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));848 try a.subSat(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));
849849
850 try testing.expect((try a.toInt(SignedDoubleLimb)) == minInt(SignedDoubleLimb));850 try testing.expectEqual(minInt(SignedDoubleLimb), try a.toInt(SignedDoubleLimb));
851}851}
852852
853test "sub single-single" {853test "sub single-single" {
...@@ -860,7 +860,7 @@ test "sub single-single" {...@@ -860,7 +860,7 @@ test "sub single-single" {
860 defer c.deinit();860 defer c.deinit();
861 try c.sub(&a, &b);861 try c.sub(&a, &b);
862862
863 try testing.expect((try c.toInt(u32)) == 45);863 try testing.expectEqual(45, try c.toInt(u32));
864}864}
865865
866test "sub multi-single" {866test "sub multi-single" {
...@@ -873,7 +873,7 @@ test "sub multi-single" {...@@ -873,7 +873,7 @@ test "sub multi-single" {
873 defer c.deinit();873 defer c.deinit();
874 try c.sub(&a, &b);874 try c.sub(&a, &b);
875875
876 try testing.expect((try c.toInt(Limb)) == maxInt(Limb));876 try testing.expectEqual(maxInt(Limb), try c.toInt(Limb));
877}877}
878878
879test "sub multi-multi" {879test "sub multi-multi" {
...@@ -890,7 +890,7 @@ test "sub multi-multi" {...@@ -890,7 +890,7 @@ test "sub multi-multi" {
890 defer c.deinit();890 defer c.deinit();
891 try c.sub(&a, &b);891 try c.sub(&a, &b);
892892
893 try testing.expect((try c.toInt(u128)) == op1 - op2);893 try testing.expectEqual(op1 - op2, try c.toInt(u128));
894}894}
895895
896test "sub equal" {896test "sub equal" {
...@@ -903,7 +903,7 @@ test "sub equal" {...@@ -903,7 +903,7 @@ test "sub equal" {
903 defer c.deinit();903 defer c.deinit();
904 try c.sub(&a, &b);904 try c.sub(&a, &b);
905905
906 try testing.expect((try c.toInt(u32)) == 0);906 try testing.expectEqual(0, try c.toInt(u32));
907}907}
908908
909test "sub sign" {909test "sub sign" {
...@@ -920,19 +920,19 @@ test "sub sign" {...@@ -920,19 +920,19 @@ test "sub sign" {
920 defer neg_two.deinit();920 defer neg_two.deinit();
921921
922 try a.sub(&one, &two);922 try a.sub(&one, &two);
923 try testing.expect((try a.toInt(i32)) == -1);923 try testing.expectEqual(-1, try a.toInt(i32));
924924
925 try a.sub(&neg_one, &two);925 try a.sub(&neg_one, &two);
926 try testing.expect((try a.toInt(i32)) == -3);926 try testing.expectEqual(-3, try a.toInt(i32));
927927
928 try a.sub(&one, &neg_two);928 try a.sub(&one, &neg_two);
929 try testing.expect((try a.toInt(i32)) == 3);929 try testing.expectEqual(3, try a.toInt(i32));
930930
931 try a.sub(&neg_one, &neg_two);931 try a.sub(&neg_one, &neg_two);
932 try testing.expect((try a.toInt(i32)) == 1);932 try testing.expectEqual(1, try a.toInt(i32));
933933
934 try a.sub(&neg_two, &neg_one);934 try a.sub(&neg_two, &neg_one);
935 try testing.expect((try a.toInt(i32)) == -1);935 try testing.expectEqual(-1, try a.toInt(i32));
936}936}
937937
938test "mul single-single" {938test "mul single-single" {
...@@ -945,7 +945,7 @@ test "mul single-single" {...@@ -945,7 +945,7 @@ test "mul single-single" {
945 defer c.deinit();945 defer c.deinit();
946 try c.mul(&a, &b);946 try c.mul(&a, &b);
947947
948 try testing.expect((try c.toInt(u64)) == 250);948 try testing.expectEqual(250, try c.toInt(u64));
949}949}
950950
951test "mul multi-single" {951test "mul multi-single" {
...@@ -958,7 +958,7 @@ test "mul multi-single" {...@@ -958,7 +958,7 @@ test "mul multi-single" {
958 defer c.deinit();958 defer c.deinit();
959 try c.mul(&a, &b);959 try c.mul(&a, &b);
960960
961 try testing.expect((try c.toInt(DoubleLimb)) == 2 * maxInt(Limb));961 try testing.expectEqual(2 * maxInt(Limb), try c.toInt(DoubleLimb));
962}962}
963963
964test "mul multi-multi" {964test "mul multi-multi" {
...@@ -977,7 +977,7 @@ test "mul multi-multi" {...@@ -977,7 +977,7 @@ test "mul multi-multi" {
977 defer c.deinit();977 defer c.deinit();
978 try c.mul(&a, &b);978 try c.mul(&a, &b);
979979
980 try testing.expect((try c.toInt(u256)) == op1 * op2);980 try testing.expectEqual(op1 * op2, try c.toInt(u256));
981}981}
982982
983test "mul alias r with a" {983test "mul alias r with a" {
...@@ -988,7 +988,7 @@ test "mul alias r with a" {...@@ -988,7 +988,7 @@ test "mul alias r with a" {
988988
989 try a.mul(&a, &b);989 try a.mul(&a, &b);
990990
991 try testing.expect((try a.toInt(DoubleLimb)) == 2 * maxInt(Limb));991 try testing.expectEqual(2 * maxInt(Limb), try a.toInt(DoubleLimb));
992}992}
993993
994test "mul alias r with b" {994test "mul alias r with b" {
...@@ -999,7 +999,7 @@ test "mul alias r with b" {...@@ -999,7 +999,7 @@ test "mul alias r with b" {
999999
1000 try a.mul(&b, &a);1000 try a.mul(&b, &a);
10011001
1002 try testing.expect((try a.toInt(DoubleLimb)) == 2 * maxInt(Limb));1002 try testing.expectEqual(2 * maxInt(Limb), try a.toInt(DoubleLimb));
1003}1003}
10041004
1005test "mul alias r with a and b" {1005test "mul alias r with a and b" {
...@@ -1008,7 +1008,7 @@ test "mul alias r with a and b" {...@@ -1008,7 +1008,7 @@ test "mul alias r with a and b" {
10081008
1009 try a.mul(&a, &a);1009 try a.mul(&a, &a);
10101010
1011 try testing.expect((try a.toInt(DoubleLimb)) == maxInt(Limb) * maxInt(Limb));1011 try testing.expectEqual(maxInt(Limb) * maxInt(Limb), try a.toInt(DoubleLimb));
1012}1012}
10131013
1014test "mul a*0" {1014test "mul a*0" {
...@@ -1021,7 +1021,7 @@ test "mul a*0" {...@@ -1021,7 +1021,7 @@ test "mul a*0" {
1021 defer c.deinit();1021 defer c.deinit();
1022 try c.mul(&a, &b);1022 try c.mul(&a, &b);
10231023
1024 try testing.expect((try c.toInt(u32)) == 0);1024 try testing.expectEqual(0, try c.toInt(u32));
1025}1025}
10261026
1027test "mul 0*0" {1027test "mul 0*0" {
...@@ -1034,7 +1034,7 @@ test "mul 0*0" {...@@ -1034,7 +1034,7 @@ test "mul 0*0" {
1034 defer c.deinit();1034 defer c.deinit();
1035 try c.mul(&a, &b);1035 try c.mul(&a, &b);
10361036
1037 try testing.expect((try c.toInt(u32)) == 0);1037 try testing.expectEqual(0, try c.toInt(u32));
1038}1038}
10391039
1040test "mul large" {1040test "mul large" {
...@@ -1068,7 +1068,7 @@ test "mulWrap single-single unsigned" {...@@ -1068,7 +1068,7 @@ test "mulWrap single-single unsigned" {
1068 defer c.deinit();1068 defer c.deinit();
1069 try c.mulWrap(&a, &b, .unsigned, 17);1069 try c.mulWrap(&a, &b, .unsigned, 17);
10701070
1071 try testing.expect((try c.toInt(u17)) == 59836);1071 try testing.expectEqual(59836, try c.toInt(u17));
1072}1072}
10731073
1074test "mulWrap single-single signed" {1074test "mulWrap single-single signed" {
...@@ -1081,7 +1081,7 @@ test "mulWrap single-single signed" {...@@ -1081,7 +1081,7 @@ test "mulWrap single-single signed" {
1081 defer c.deinit();1081 defer c.deinit();
1082 try c.mulWrap(&a, &b, .signed, 17);1082 try c.mulWrap(&a, &b, .signed, 17);
10831083
1084 try testing.expect((try c.toInt(i17)) == -59836);1084 try testing.expectEqual(-59836, try c.toInt(i17));
1085}1085}
10861086
1087test "mulWrap multi-multi unsigned" {1087test "mulWrap multi-multi unsigned" {
...@@ -1100,7 +1100,7 @@ test "mulWrap multi-multi unsigned" {...@@ -1100,7 +1100,7 @@ test "mulWrap multi-multi unsigned" {
1100 defer c.deinit();1100 defer c.deinit();
1101 try c.mulWrap(&a, &b, .unsigned, 65);1101 try c.mulWrap(&a, &b, .unsigned, 65);
11021102
1103 try testing.expect((try c.toInt(u256)) == (op1 * op2) & ((1 << 65) - 1));1103 try testing.expectEqual((op1 * op2) & ((1 << 65) - 1), try c.toInt(u256));
1104}1104}
11051105
1106test "mulWrap multi-multi signed" {1106test "mulWrap multi-multi signed" {
...@@ -1118,7 +1118,7 @@ test "mulWrap multi-multi signed" {...@@ -1118,7 +1118,7 @@ test "mulWrap multi-multi signed" {
1118 defer c.deinit();1118 defer c.deinit();
1119 try c.mulWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));1119 try c.mulWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));
11201120
1121 try testing.expect((try c.toInt(SignedDoubleLimb)) == minInt(SignedDoubleLimb) + 2);1121 try testing.expectEqual(minInt(SignedDoubleLimb) + 2, try c.toInt(SignedDoubleLimb));
1122}1122}
11231123
1124test "mulWrap large" {1124test "mulWrap large" {
...@@ -1157,8 +1157,8 @@ test "div single-half no rem" {...@@ -1157,8 +1157,8 @@ test "div single-half no rem" {
1157 defer r.deinit();1157 defer r.deinit();
1158 try Managed.divTrunc(&q, &r, &a, &b);1158 try Managed.divTrunc(&q, &r, &a, &b);
11591159
1160 try testing.expect((try q.toInt(u32)) == 10);1160 try testing.expectEqual(10, try q.toInt(u32));
1161 try testing.expect((try r.toInt(u32)) == 0);1161 try testing.expectEqual(0, try r.toInt(u32));
1162}1162}
11631163
1164test "div single-half with rem" {1164test "div single-half with rem" {
...@@ -1173,8 +1173,8 @@ test "div single-half with rem" {...@@ -1173,8 +1173,8 @@ test "div single-half with rem" {
1173 defer r.deinit();1173 defer r.deinit();
1174 try Managed.divTrunc(&q, &r, &a, &b);1174 try Managed.divTrunc(&q, &r, &a, &b);
11751175
1176 try testing.expect((try q.toInt(u32)) == 9);1176 try testing.expectEqual(9, try q.toInt(u32));
1177 try testing.expect((try r.toInt(u32)) == 4);1177 try testing.expectEqual(4, try r.toInt(u32));
1178}1178}
11791179
1180test "div single-single no rem" {1180test "div single-single no rem" {
...@@ -1190,8 +1190,8 @@ test "div single-single no rem" {...@@ -1190,8 +1190,8 @@ test "div single-single no rem" {
1190 defer r.deinit();1190 defer r.deinit();
1191 try Managed.divTrunc(&q, &r, &a, &b);1191 try Managed.divTrunc(&q, &r, &a, &b);
11921192
1193 try testing.expect((try q.toInt(u32)) == 131072);1193 try testing.expectEqual(131072, try q.toInt(u32));
1194 try testing.expect((try r.toInt(u32)) == 0);1194 try testing.expectEqual(0, try r.toInt(u32));
1195}1195}
11961196
1197test "div single-single with rem" {1197test "div single-single with rem" {
...@@ -1206,8 +1206,8 @@ test "div single-single with rem" {...@@ -1206,8 +1206,8 @@ test "div single-single with rem" {
1206 defer r.deinit();1206 defer r.deinit();
1207 try Managed.divTrunc(&q, &r, &a, &b);1207 try Managed.divTrunc(&q, &r, &a, &b);
12081208
1209 try testing.expect((try q.toInt(u64)) == 131072);1209 try testing.expectEqual(131072, try q.toInt(u64));
1210 try testing.expect((try r.toInt(u64)) == 8589934592);1210 try testing.expectEqual(8589934592, try r.toInt(u64));
1211}1211}
12121212
1213test "div multi-single no rem" {1213test "div multi-single no rem" {
...@@ -1226,8 +1226,8 @@ test "div multi-single no rem" {...@@ -1226,8 +1226,8 @@ test "div multi-single no rem" {
1226 defer r.deinit();1226 defer r.deinit();
1227 try Managed.divTrunc(&q, &r, &a, &b);1227 try Managed.divTrunc(&q, &r, &a, &b);
12281228
1229 try testing.expect((try q.toInt(u64)) == op1 / op2);1229 try testing.expectEqual(op1 / op2, try q.toInt(u64));
1230 try testing.expect((try r.toInt(u64)) == 0);1230 try testing.expectEqual(0, try r.toInt(u64));
1231}1231}
12321232
1233test "div multi-single with rem" {1233test "div multi-single with rem" {
...@@ -1246,8 +1246,8 @@ test "div multi-single with rem" {...@@ -1246,8 +1246,8 @@ test "div multi-single with rem" {
1246 defer r.deinit();1246 defer r.deinit();
1247 try Managed.divTrunc(&q, &r, &a, &b);1247 try Managed.divTrunc(&q, &r, &a, &b);
12481248
1249 try testing.expect((try q.toInt(u64)) == op1 / op2);1249 try testing.expectEqual(op1 / op2, try q.toInt(u64));
1250 try testing.expect((try r.toInt(u64)) == 3);1250 try testing.expectEqual(3, try r.toInt(u64));
1251}1251}
12521252
1253test "div multi>2-single" {1253test "div multi>2-single" {
...@@ -1266,8 +1266,8 @@ test "div multi>2-single" {...@@ -1266,8 +1266,8 @@ test "div multi>2-single" {
1266 defer r.deinit();1266 defer r.deinit();
1267 try Managed.divTrunc(&q, &r, &a, &b);1267 try Managed.divTrunc(&q, &r, &a, &b);
12681268
1269 try testing.expect((try q.toInt(u128)) == op1 / op2);1269 try testing.expectEqual(op1 / op2, try q.toInt(u128));
1270 try testing.expect((try r.toInt(u32)) == 0x3e4e);1270 try testing.expectEqual(0x3e4e, try r.toInt(u32));
1271}1271}
12721272
1273test "div single-single q < r" {1273test "div single-single q < r" {
...@@ -1282,8 +1282,8 @@ test "div single-single q < r" {...@@ -1282,8 +1282,8 @@ test "div single-single q < r" {
1282 defer r.deinit();1282 defer r.deinit();
1283 try Managed.divTrunc(&q, &r, &a, &b);1283 try Managed.divTrunc(&q, &r, &a, &b);
12841284
1285 try testing.expect((try q.toInt(u64)) == 0);1285 try testing.expectEqual(0, try q.toInt(u64));
1286 try testing.expect((try r.toInt(u64)) == 0x0078f432);1286 try testing.expectEqual(0x0078f432, try r.toInt(u64));
1287}1287}
12881288
1289test "div single-single q == r" {1289test "div single-single q == r" {
...@@ -1298,8 +1298,8 @@ test "div single-single q == r" {...@@ -1298,8 +1298,8 @@ test "div single-single q == r" {
1298 defer r.deinit();1298 defer r.deinit();
1299 try Managed.divTrunc(&q, &r, &a, &b);1299 try Managed.divTrunc(&q, &r, &a, &b);
13001300
1301 try testing.expect((try q.toInt(u64)) == 1);1301 try testing.expectEqual(1, try q.toInt(u64));
1302 try testing.expect((try r.toInt(u64)) == 0);1302 try testing.expectEqual(0, try r.toInt(u64));
1303}1303}
13041304
1305test "div q=0 alias" {1305test "div q=0 alias" {
...@@ -1310,8 +1310,8 @@ test "div q=0 alias" {...@@ -1310,8 +1310,8 @@ test "div q=0 alias" {
13101310
1311 try Managed.divTrunc(&a, &b, &a, &b);1311 try Managed.divTrunc(&a, &b, &a, &b);
13121312
1313 try testing.expect((try a.toInt(u64)) == 0);1313 try testing.expectEqual(0, try a.toInt(u64));
1314 try testing.expect((try b.toInt(u64)) == 3);1314 try testing.expectEqual(3, try b.toInt(u64));
1315}1315}
13161316
1317test "div multi-multi q < r" {1317test "div multi-multi q < r" {
...@@ -1330,8 +1330,8 @@ test "div multi-multi q < r" {...@@ -1330,8 +1330,8 @@ test "div multi-multi q < r" {
1330 defer r.deinit();1330 defer r.deinit();
1331 try Managed.divTrunc(&q, &r, &a, &b);1331 try Managed.divTrunc(&q, &r, &a, &b);
13321332
1333 try testing.expect((try q.toInt(u128)) == 0);1333 try testing.expectEqual(0, try q.toInt(u128));
1334 try testing.expect((try r.toInt(u128)) == op1);1334 try testing.expectEqual(op1, try r.toInt(u128));
1335}1335}
13361336
1337test "div trunc single-single +/+" {1337test "div trunc single-single +/+" {
...@@ -1354,8 +1354,8 @@ test "div trunc single-single +/+" {...@@ -1354,8 +1354,8 @@ test "div trunc single-single +/+" {
1354 const eq = @divTrunc(u, v);1354 const eq = @divTrunc(u, v);
1355 const er = @mod(u, v);1355 const er = @mod(u, v);
13561356
1357 try testing.expect((try q.toInt(i32)) == eq);1357 try testing.expectEqual(eq, try q.toInt(i32));
1358 try testing.expect((try r.toInt(i32)) == er);1358 try testing.expectEqual(er, try r.toInt(i32));
1359}1359}
13601360
1361test "div trunc single-single -/+" {1361test "div trunc single-single -/+" {
...@@ -1378,8 +1378,8 @@ test "div trunc single-single -/+" {...@@ -1378,8 +1378,8 @@ test "div trunc single-single -/+" {
1378 const eq = -1;1378 const eq = -1;
1379 const er = -2;1379 const er = -2;
13801380
1381 try testing.expect((try q.toInt(i32)) == eq);1381 try testing.expectEqual(eq, try q.toInt(i32));
1382 try testing.expect((try r.toInt(i32)) == er);1382 try testing.expectEqual(er, try r.toInt(i32));
1383}1383}
13841384
1385test "div trunc single-single +/-" {1385test "div trunc single-single +/-" {
...@@ -1402,8 +1402,8 @@ test "div trunc single-single +/-" {...@@ -1402,8 +1402,8 @@ test "div trunc single-single +/-" {
1402 const eq = -1;1402 const eq = -1;
1403 const er = 2;1403 const er = 2;
14041404
1405 try testing.expect((try q.toInt(i32)) == eq);1405 try testing.expectEqual(eq, try q.toInt(i32));
1406 try testing.expect((try r.toInt(i32)) == er);1406 try testing.expectEqual(er, try r.toInt(i32));
1407}1407}
14081408
1409test "div trunc single-single -/-" {1409test "div trunc single-single -/-" {
...@@ -1426,8 +1426,8 @@ test "div trunc single-single -/-" {...@@ -1426,8 +1426,8 @@ test "div trunc single-single -/-" {
1426 const eq = 1;1426 const eq = 1;
1427 const er = -2;1427 const er = -2;
14281428
1429 try testing.expect((try q.toInt(i32)) == eq);1429 try testing.expectEqual(eq, try q.toInt(i32));
1430 try testing.expect((try r.toInt(i32)) == er);1430 try testing.expectEqual(er, try r.toInt(i32));
1431}1431}
14321432
1433test "divTrunc #15535" {1433test "divTrunc #15535" {
...@@ -1440,7 +1440,7 @@ test "divTrunc #15535" {...@@ -1440,7 +1440,7 @@ test "divTrunc #15535" {
1440 var q = try Managed.init(testing.allocator);1440 var q = try Managed.init(testing.allocator);
1441 defer q.deinit();1441 defer q.deinit();
1442 try q.divTrunc(&r, &x, &x);1442 try q.divTrunc(&r, &x, &x);
1443 try testing.expect(r.order(one) == std.math.Order.lt);1443 try testing.expectEqual(std.math.Order.lt, r.order(one));
1444}1444}
14451445
1446test "divFloor #10932" {1446test "divFloor #10932" {
...@@ -1463,8 +1463,8 @@ test "divFloor #10932" {...@@ -1463,8 +1463,8 @@ test "divFloor #10932" {
14631463
1464 const ress = try res.toString(testing.allocator, 16, .lower);1464 const ress = try res.toString(testing.allocator, 16, .lower);
1465 defer testing.allocator.free(ress);1465 defer testing.allocator.free(ress);
1466 try testing.expect(std.mem.eql(u8, ress, "194bd136316c046d070b763396297bf8869a605030216b52597015902a172b2a752f62af1568dcd431602f03725bfa62b0be71ae86616210972c0126e173503011ca48c5747ff066d159c95e46b69cbb14c8fc0bd2bf0919f921be96463200000000000000000000000000000000000000000000000000000000000000000000000000000000"));1466 try testing.expectEqualStrings("194bd136316c046d070b763396297bf8869a605030216b52597015902a172b2a752f62af1568dcd431602f03725bfa62b0be71ae86616210972c0126e173503011ca48c5747ff066d159c95e46b69cbb14c8fc0bd2bf0919f921be96463200000000000000000000000000000000000000000000000000000000000000000000000000000000", ress);
1467 try testing.expect((try mod.toInt(i32)) == 0);1467 try testing.expectEqual(0, try mod.toInt(i32));
1468}1468}
14691469
1470test "divFloor #11166" {1470test "divFloor #11166" {
...@@ -1487,11 +1487,11 @@ test "divFloor #11166" {...@@ -1487,11 +1487,11 @@ test "divFloor #11166" {
14871487
1488 const ress = try res.toString(testing.allocator, 10, .lower);1488 const ress = try res.toString(testing.allocator, 10, .lower);
1489 defer testing.allocator.free(ress);1489 defer testing.allocator.free(ress);
1490 try testing.expect(std.mem.eql(u8, ress, "1000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));1490 try testing.expectEqualStrings("1000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", ress);
14911491
1492 const mods = try mod.toString(testing.allocator, 10, .lower);1492 const mods = try mod.toString(testing.allocator, 10, .lower);
1493 defer testing.allocator.free(mods);1493 defer testing.allocator.free(mods);
1494 try testing.expect(std.mem.eql(u8, mods, "870000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));1494 try testing.expectEqualStrings("870000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", mods);
1495}1495}
14961496
1497test "gcd #10932" {1497test "gcd #10932" {
...@@ -1511,7 +1511,7 @@ test "gcd #10932" {...@@ -1511,7 +1511,7 @@ test "gcd #10932" {
15111511
1512 const ress = try res.toString(testing.allocator, 16, .lower);1512 const ress = try res.toString(testing.allocator, 16, .lower);
1513 defer testing.allocator.free(ress);1513 defer testing.allocator.free(ress);
1514 try testing.expect(std.mem.eql(u8, ress, "1a974a5c9734476ff5a3604bcc678a756beacfc21b4427d1f2c1f56f5d4e411a162c56136e20000000000000000000000000000000"));1514 try testing.expectEqualStrings("1a974a5c9734476ff5a3604bcc678a756beacfc21b4427d1f2c1f56f5d4e411a162c56136e20000000000000000000000000000000", ress);
1515}1515}
15161516
1517test "bitAnd #10932" {1517test "bitAnd #10932" {
...@@ -1529,7 +1529,7 @@ test "bitAnd #10932" {...@@ -1529,7 +1529,7 @@ test "bitAnd #10932" {
15291529
1530 try res.bitAnd(&a, &b);1530 try res.bitAnd(&a, &b);
15311531
1532 try testing.expect((try res.toInt(i32)) == 0);1532 try testing.expectEqual(0, try res.toInt(i32));
1533}1533}
15341534
1535test "bit And #19235" {1535test "bit And #19235" {
...@@ -1542,7 +1542,7 @@ test "bit And #19235" {...@@ -1542,7 +1542,7 @@ test "bit And #19235" {
15421542
1543 try r.bitAnd(&a, &b);1543 try r.bitAnd(&a, &b);
15441544
1545 try testing.expect((try r.toInt(i128)) == 0x10000000000000000);1545 try testing.expectEqual(0x10000000000000000, try r.toInt(i128));
1546}1546}
15471547
1548test "div floor single-single +/+" {1548test "div floor single-single +/+" {
...@@ -1565,8 +1565,8 @@ test "div floor single-single +/+" {...@@ -1565,8 +1565,8 @@ test "div floor single-single +/+" {
1565 const eq = 1;1565 const eq = 1;
1566 const er = 2;1566 const er = 2;
15671567
1568 try testing.expect((try q.toInt(i32)) == eq);1568 try testing.expectEqual(eq, try q.toInt(i32));
1569 try testing.expect((try r.toInt(i32)) == er);1569 try testing.expectEqual(er, try r.toInt(i32));
1570}1570}
15711571
1572test "div floor single-single -/+" {1572test "div floor single-single -/+" {
...@@ -1589,8 +1589,8 @@ test "div floor single-single -/+" {...@@ -1589,8 +1589,8 @@ test "div floor single-single -/+" {
1589 const eq = -2;1589 const eq = -2;
1590 const er = 1;1590 const er = 1;
15911591
1592 try testing.expect((try q.toInt(i32)) == eq);1592 try testing.expectEqual(eq, try q.toInt(i32));
1593 try testing.expect((try r.toInt(i32)) == er);1593 try testing.expectEqual(er, try r.toInt(i32));
1594}1594}
15951595
1596test "div floor single-single +/-" {1596test "div floor single-single +/-" {
...@@ -1613,8 +1613,8 @@ test "div floor single-single +/-" {...@@ -1613,8 +1613,8 @@ test "div floor single-single +/-" {
1613 const eq = -2;1613 const eq = -2;
1614 const er = -1;1614 const er = -1;
16151615
1616 try testing.expect((try q.toInt(i32)) == eq);1616 try testing.expectEqual(eq, try q.toInt(i32));
1617 try testing.expect((try r.toInt(i32)) == er);1617 try testing.expectEqual(er, try r.toInt(i32));
1618}1618}
16191619
1620test "div floor single-single -/-" {1620test "div floor single-single -/-" {
...@@ -1637,8 +1637,8 @@ test "div floor single-single -/-" {...@@ -1637,8 +1637,8 @@ test "div floor single-single -/-" {
1637 const eq = 1;1637 const eq = 1;
1638 const er = -2;1638 const er = -2;
16391639
1640 try testing.expect((try q.toInt(i32)) == eq);1640 try testing.expectEqual(eq, try q.toInt(i32));
1641 try testing.expect((try r.toInt(i32)) == er);1641 try testing.expectEqual(er, try r.toInt(i32));
1642}1642}
16431643
1644test "div floor no remainder negative quotient" {1644test "div floor no remainder negative quotient" {
...@@ -1656,8 +1656,8 @@ test "div floor no remainder negative quotient" {...@@ -1656,8 +1656,8 @@ test "div floor no remainder negative quotient" {
1656 defer r.deinit();1656 defer r.deinit();
1657 try Managed.divFloor(&q, &r, &a, &b);1657 try Managed.divFloor(&q, &r, &a, &b);
16581658
1659 try testing.expect((try q.toInt(i32)) == -0x80000000);1659 try testing.expectEqual(-0x80000000, try q.toInt(i32));
1660 try testing.expect((try r.toInt(i32)) == 0);1660 try testing.expectEqual(0, try r.toInt(i32));
1661}1661}
16621662
1663test "div floor negative close to zero" {1663test "div floor negative close to zero" {
...@@ -1675,8 +1675,8 @@ test "div floor negative close to zero" {...@@ -1675,8 +1675,8 @@ test "div floor negative close to zero" {
1675 defer r.deinit();1675 defer r.deinit();
1676 try Managed.divFloor(&q, &r, &a, &b);1676 try Managed.divFloor(&q, &r, &a, &b);
16771677
1678 try testing.expect((try q.toInt(i32)) == -1);1678 try testing.expectEqual(-1, try q.toInt(i32));
1679 try testing.expect((try r.toInt(i32)) == 10);1679 try testing.expectEqual(10, try r.toInt(i32));
1680}1680}
16811681
1682test "div floor positive close to zero" {1682test "div floor positive close to zero" {
...@@ -1694,8 +1694,8 @@ test "div floor positive close to zero" {...@@ -1694,8 +1694,8 @@ test "div floor positive close to zero" {
1694 defer r.deinit();1694 defer r.deinit();
1695 try Managed.divFloor(&q, &r, &a, &b);1695 try Managed.divFloor(&q, &r, &a, &b);
16961696
1697 try testing.expect((try q.toInt(i32)) == 0);1697 try testing.expectEqual(0, try q.toInt(i32));
1698 try testing.expect((try r.toInt(i32)) == 10);1698 try testing.expectEqual(10, try r.toInt(i32));
1699}1699}
17001700
1701test "div multi-multi with rem" {1701test "div multi-multi with rem" {
...@@ -1712,8 +1712,8 @@ test "div multi-multi with rem" {...@@ -1712,8 +1712,8 @@ test "div multi-multi with rem" {
1712 defer r.deinit();1712 defer r.deinit();
1713 try Managed.divTrunc(&q, &r, &a, &b);1713 try Managed.divTrunc(&q, &r, &a, &b);
17141714
1715 try testing.expect((try q.toInt(u128)) == 0xe38f38e39161aaabd03f0f1b);1715 try testing.expectEqual(0xe38f38e39161aaabd03f0f1b, try q.toInt(u128));
1716 try testing.expect((try r.toInt(u128)) == 0x28de0acacd806823638);1716 try testing.expectEqual(0x28de0acacd806823638, try r.toInt(u128));
1717}1717}
17181718
1719test "div multi-multi no rem" {1719test "div multi-multi no rem" {
...@@ -1730,8 +1730,8 @@ test "div multi-multi no rem" {...@@ -1730,8 +1730,8 @@ test "div multi-multi no rem" {
1730 defer r.deinit();1730 defer r.deinit();
1731 try Managed.divTrunc(&q, &r, &a, &b);1731 try Managed.divTrunc(&q, &r, &a, &b);
17321732
1733 try testing.expect((try q.toInt(u128)) == 0xe38f38e39161aaabd03f0f1b);1733 try testing.expectEqual(0xe38f38e39161aaabd03f0f1b, try q.toInt(u128));
1734 try testing.expect((try r.toInt(u128)) == 0);1734 try testing.expectEqual(0, try r.toInt(u128));
1735}1735}
17361736
1737test "div multi-multi (2 branch)" {1737test "div multi-multi (2 branch)" {
...@@ -1748,8 +1748,8 @@ test "div multi-multi (2 branch)" {...@@ -1748,8 +1748,8 @@ test "div multi-multi (2 branch)" {
1748 defer r.deinit();1748 defer r.deinit();
1749 try Managed.divTrunc(&q, &r, &a, &b);1749 try Managed.divTrunc(&q, &r, &a, &b);
17501750
1751 try testing.expect((try q.toInt(u128)) == 0x10000000000000000);1751 try testing.expectEqual(0x10000000000000000, try q.toInt(u128));
1752 try testing.expect((try r.toInt(u128)) == 0x44444443444444431111111111111111);1752 try testing.expectEqual(0x44444443444444431111111111111111, try r.toInt(u128));
1753}1753}
17541754
1755test "div multi-multi (3.1/3.3 branch)" {1755test "div multi-multi (3.1/3.3 branch)" {
...@@ -1766,8 +1766,8 @@ test "div multi-multi (3.1/3.3 branch)" {...@@ -1766,8 +1766,8 @@ test "div multi-multi (3.1/3.3 branch)" {
1766 defer r.deinit();1766 defer r.deinit();
1767 try Managed.divTrunc(&q, &r, &a, &b);1767 try Managed.divTrunc(&q, &r, &a, &b);
17681768
1769 try testing.expect((try q.toInt(u128)) == 0xfffffffffffffffffff);1769 try testing.expectEqual(0xfffffffffffffffffff, try q.toInt(u128));
1770 try testing.expect((try r.toInt(u256)) == 0x1111111111111111111110b12222222222222222282);1770 try testing.expectEqual(0x1111111111111111111110b12222222222222222282, try r.toInt(u256));
1771}1771}
17721772
1773test "div multi-single zero-limb trailing" {1773test "div multi-single zero-limb trailing" {
...@@ -1804,11 +1804,11 @@ test "div multi-multi zero-limb trailing (with rem)" {...@@ -1804,11 +1804,11 @@ test "div multi-multi zero-limb trailing (with rem)" {
1804 defer r.deinit();1804 defer r.deinit();
1805 try Managed.divTrunc(&q, &r, &a, &b);1805 try Managed.divTrunc(&q, &r, &a, &b);
18061806
1807 try testing.expect((try q.toInt(u128)) == 0x10000000000000000);1807 try testing.expectEqual(0x10000000000000000, try q.toInt(u128));
18081808
1809 const rs = try r.toString(testing.allocator, 16, .lower);1809 const rs = try r.toString(testing.allocator, 16, .lower);
1810 defer testing.allocator.free(rs);1810 defer testing.allocator.free(rs);
1811 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));1811 try testing.expectEqualStrings("4444444344444443111111111111111100000000000000000000000000000000", rs);
1812}1812}
18131813
1814test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {1814test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count > divisor zero-limb count" {
...@@ -1825,11 +1825,11 @@ test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count...@@ -1825,11 +1825,11 @@ test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count
1825 defer r.deinit();1825 defer r.deinit();
1826 try Managed.divTrunc(&q, &r, &a, &b);1826 try Managed.divTrunc(&q, &r, &a, &b);
18271827
1828 try testing.expect((try q.toInt(u128)) == 0x1);1828 try testing.expectEqual(0x1, try q.toInt(u128));
18291829
1830 const rs = try r.toString(testing.allocator, 16, .lower);1830 const rs = try r.toString(testing.allocator, 16, .lower);
1831 defer testing.allocator.free(rs);1831 defer testing.allocator.free(rs);
1832 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));1832 try testing.expectEqualStrings("444444434444444311111111111111110000000000000000", rs);
1833}1833}
18341834
1835test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {1835test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count < divisor zero-limb count" {
...@@ -1848,11 +1848,11 @@ test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count...@@ -1848,11 +1848,11 @@ test "div multi-multi zero-limb trailing (with rem) and dividend zero-limb count
18481848
1849 const qs = try q.toString(testing.allocator, 16, .lower);1849 const qs = try q.toString(testing.allocator, 16, .lower);
1850 defer testing.allocator.free(qs);1850 defer testing.allocator.free(qs);
1851 try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));1851 try testing.expectEqualStrings("10000000000000000820820803105186f", qs);
18521852
1853 const rs = try r.toString(testing.allocator, 16, .lower);1853 const rs = try r.toString(testing.allocator, 16, .lower);
1854 defer testing.allocator.free(rs);1854 defer testing.allocator.free(rs);
1855 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));1855 try testing.expectEqualStrings("4e11f2baa5896a321d463b543d0104e30000000000000000", rs);
1856}1856}
18571857
1858test "div multi-multi fuzz case #1" {1858test "div multi-multi fuzz case #1" {
...@@ -1872,11 +1872,11 @@ test "div multi-multi fuzz case #1" {...@@ -1872,11 +1872,11 @@ test "div multi-multi fuzz case #1" {
18721872
1873 const qs = try q.toString(testing.allocator, 16, .lower);1873 const qs = try q.toString(testing.allocator, 16, .lower);
1874 defer testing.allocator.free(qs);1874 defer testing.allocator.free(qs);
1875 try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));1875 try testing.expectEqualStrings("3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1", qs);
18761876
1877 const rs = try r.toString(testing.allocator, 16, .lower);1877 const rs = try r.toString(testing.allocator, 16, .lower);
1878 defer testing.allocator.free(rs);1878 defer testing.allocator.free(rs);
1879 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));1879 try testing.expectEqualStrings("310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1", rs);
1880}1880}
18811881
1882test "div multi-multi fuzz case #2" {1882test "div multi-multi fuzz case #2" {
...@@ -1896,11 +1896,11 @@ test "div multi-multi fuzz case #2" {...@@ -1896,11 +1896,11 @@ test "div multi-multi fuzz case #2" {
18961896
1897 const qs = try q.toString(testing.allocator, 16, .lower);1897 const qs = try q.toString(testing.allocator, 16, .lower);
1898 defer testing.allocator.free(qs);1898 defer testing.allocator.free(qs);
1899 try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));1899 try testing.expectEqualStrings("40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4", qs);
19001900
1901 const rs = try r.toString(testing.allocator, 16, .lower);1901 const rs = try r.toString(testing.allocator, 16, .lower);
1902 defer testing.allocator.free(rs);1902 defer testing.allocator.free(rs);
1903 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));1903 try testing.expectEqualStrings("a900000000000000000000000000000000000000000000000000", rs);
1904}1904}
19051905
1906test "truncate single unsigned" {1906test "truncate single unsigned" {
...@@ -1909,7 +1909,7 @@ test "truncate single unsigned" {...@@ -1909,7 +1909,7 @@ test "truncate single unsigned" {
19091909
1910 try a.truncate(&a, .unsigned, 17);1910 try a.truncate(&a, .unsigned, 17);
19111911
1912 try testing.expect((try a.toInt(u17)) == maxInt(u17));1912 try testing.expectEqual(maxInt(u17), try a.toInt(u17));
1913}1913}
19141914
1915test "truncate single signed" {1915test "truncate single signed" {
...@@ -1918,7 +1918,7 @@ test "truncate single signed" {...@@ -1918,7 +1918,7 @@ test "truncate single signed" {
19181918
1919 try a.truncate(&a, .signed, 17);1919 try a.truncate(&a, .signed, 17);
19201920
1921 try testing.expect((try a.toInt(i17)) == minInt(i17));1921 try testing.expectEqual(minInt(i17), try a.toInt(i17));
1922}1922}
19231923
1924test "truncate multi to single unsigned" {1924test "truncate multi to single unsigned" {
...@@ -1927,7 +1927,7 @@ test "truncate multi to single unsigned" {...@@ -1927,7 +1927,7 @@ test "truncate multi to single unsigned" {
19271927
1928 try a.truncate(&a, .unsigned, 27);1928 try a.truncate(&a, .unsigned, 27);
19291929
1930 try testing.expect((try a.toInt(u27)) == 0x2BC_DEF0);1930 try testing.expectEqual(0x2BC_DEF0, try a.toInt(u27));
1931}1931}
19321932
1933test "truncate multi to single signed" {1933test "truncate multi to single signed" {
...@@ -1936,7 +1936,7 @@ test "truncate multi to single signed" {...@@ -1936,7 +1936,7 @@ test "truncate multi to single signed" {
19361936
1937 try a.truncate(&a, .signed, @bitSizeOf(i11));1937 try a.truncate(&a, .signed, @bitSizeOf(i11));
19381938
1939 try testing.expect((try a.toInt(i11)) == minInt(i11));1939 try testing.expectEqual(minInt(i11), try a.toInt(i11));
1940}1940}
19411941
1942test "truncate multi to multi unsigned" {1942test "truncate multi to multi unsigned" {
...@@ -1948,7 +1948,7 @@ test "truncate multi to multi unsigned" {...@@ -1948,7 +1948,7 @@ test "truncate multi to multi unsigned" {
19481948
1949 try a.truncate(&a, .unsigned, bits - 1);1949 try a.truncate(&a, .unsigned, bits - 1);
19501950
1951 try testing.expect((try a.toInt(Int)) == maxInt(Int));1951 try testing.expectEqual(maxInt(Int), try a.toInt(Int));
1952}1952}
19531953
1954test "truncate multi to multi signed" {1954test "truncate multi to multi signed" {
...@@ -1957,7 +1957,7 @@ test "truncate multi to multi signed" {...@@ -1957,7 +1957,7 @@ test "truncate multi to multi signed" {
19571957
1958 try a.truncate(&a, .signed, @bitSizeOf(Limb) + 1);1958 try a.truncate(&a, .signed, @bitSizeOf(Limb) + 1);
19591959
1960 try testing.expect((try a.toInt(std.meta.Int(.signed, @bitSizeOf(Limb) + 1))) == -1 << @bitSizeOf(Limb));1960 try testing.expectEqual(-1 << @bitSizeOf(Limb), try a.toInt(std.meta.Int(.signed, @bitSizeOf(Limb) + 1)));
1961}1961}
19621962
1963test "truncate negative multi to single" {1963test "truncate negative multi to single" {
...@@ -1966,7 +1966,7 @@ test "truncate negative multi to single" {...@@ -1966,7 +1966,7 @@ test "truncate negative multi to single" {
19661966
1967 try a.truncate(&a, .signed, @bitSizeOf(i17));1967 try a.truncate(&a, .signed, @bitSizeOf(i17));
19681968
1969 try testing.expect((try a.toInt(i17)) == 0);1969 try testing.expectEqual(0, try a.toInt(i17));
1970}1970}
19711971
1972test "truncate multi unsigned many" {1972test "truncate multi unsigned many" {
...@@ -1978,7 +1978,7 @@ test "truncate multi unsigned many" {...@@ -1978,7 +1978,7 @@ test "truncate multi unsigned many" {
1978 defer b.deinit();1978 defer b.deinit();
1979 try b.truncate(&a, .signed, @bitSizeOf(i1));1979 try b.truncate(&a, .signed, @bitSizeOf(i1));
19801980
1981 try testing.expect((try b.toInt(i1)) == 0);1981 try testing.expectEqual(0, try b.toInt(i1));
1982}1982}
19831983
1984test "truncate to mutable with fewer limbs" {1984test "truncate to mutable with fewer limbs" {
...@@ -2067,7 +2067,7 @@ test "saturate single signed positive" {...@@ -2067,7 +2067,7 @@ test "saturate single signed positive" {
20672067
2068 try a.saturate(&a, .signed, 17);2068 try a.saturate(&a, .signed, 17);
20692069
2070 try testing.expect((try a.toInt(i17)) == maxInt(i17));2070 try testing.expectEqual(maxInt(i17), try a.toInt(i17));
2071}2071}
20722072
2073test "saturate single signed negative" {2073test "saturate single signed negative" {
...@@ -2076,7 +2076,7 @@ test "saturate single signed negative" {...@@ -2076,7 +2076,7 @@ test "saturate single signed negative" {
20762076
2077 try a.saturate(&a, .signed, 17);2077 try a.saturate(&a, .signed, 17);
20782078
2079 try testing.expect((try a.toInt(i17)) == minInt(i17));2079 try testing.expectEqual(minInt(i17), try a.toInt(i17));
2080}2080}
20812081
2082test "saturate single signed" {2082test "saturate single signed" {
...@@ -2085,7 +2085,7 @@ test "saturate single signed" {...@@ -2085,7 +2085,7 @@ test "saturate single signed" {
20852085
2086 try a.saturate(&a, .signed, 17);2086 try a.saturate(&a, .signed, 17);
20872087
2088 try testing.expect((try a.toInt(i17)) == maxInt(i17) - 1);2088 try testing.expectEqual(maxInt(i17) - 1, try a.toInt(i17));
2089}2089}
20902090
2091test "saturate multi signed" {2091test "saturate multi signed" {
...@@ -2094,7 +2094,7 @@ test "saturate multi signed" {...@@ -2094,7 +2094,7 @@ test "saturate multi signed" {
20942094
2095 try a.saturate(&a, .signed, @bitSizeOf(SignedDoubleLimb));2095 try a.saturate(&a, .signed, @bitSizeOf(SignedDoubleLimb));
20962096
2097 try testing.expect((try a.toInt(SignedDoubleLimb)) == maxInt(SignedDoubleLimb));2097 try testing.expectEqual(maxInt(SignedDoubleLimb), try a.toInt(SignedDoubleLimb));
2098}2098}
20992099
2100test "saturate single unsigned" {2100test "saturate single unsigned" {
...@@ -2103,7 +2103,7 @@ test "saturate single unsigned" {...@@ -2103,7 +2103,7 @@ test "saturate single unsigned" {
21032103
2104 try a.saturate(&a, .unsigned, 23);2104 try a.saturate(&a, .unsigned, 23);
21052105
2106 try testing.expect((try a.toInt(u23)) == maxInt(u23));2106 try testing.expectEqual(maxInt(u23), try a.toInt(u23));
2107}2107}
21082108
2109test "saturate multi unsigned zero" {2109test "saturate multi unsigned zero" {
...@@ -2121,7 +2121,7 @@ test "saturate multi unsigned" {...@@ -2121,7 +2121,7 @@ test "saturate multi unsigned" {
21212121
2122 try a.saturate(&a, .unsigned, @bitSizeOf(DoubleLimb));2122 try a.saturate(&a, .unsigned, @bitSizeOf(DoubleLimb));
21232123
2124 try testing.expect((try a.toInt(DoubleLimb)) == maxInt(DoubleLimb));2124 try testing.expectEqual(maxInt(DoubleLimb), try a.toInt(DoubleLimb));
2125}2125}
21262126
2127test "shift-right single" {2127test "shift-right single" {
...@@ -2129,7 +2129,7 @@ test "shift-right single" {...@@ -2129,7 +2129,7 @@ test "shift-right single" {
2129 defer a.deinit();2129 defer a.deinit();
2130 try a.shiftRight(&a, 16);2130 try a.shiftRight(&a, 16);
21312131
2132 try testing.expect((try a.toInt(u32)) == 0xffff);2132 try testing.expectEqual(0xffff, try a.toInt(u32));
2133}2133}
21342134
2135test "shift-right multi" {2135test "shift-right multi" {
...@@ -2137,7 +2137,7 @@ test "shift-right multi" {...@@ -2137,7 +2137,7 @@ test "shift-right multi" {
2137 defer a.deinit();2137 defer a.deinit();
2138 try a.shiftRight(&a, 67);2138 try a.shiftRight(&a, 67);
21392139
2140 try testing.expect((try a.toInt(u64)) == 0x1fffe0001dddc222);2140 try testing.expectEqual(0x1fffe0001dddc222, try a.toInt(u64));
21412141
2142 try a.set(0xffff0000eeee1111dddd2222cccc3333);2142 try a.set(0xffff0000eeee1111dddd2222cccc3333);
2143 try a.shiftRight(&a, 63);2143 try a.shiftRight(&a, 63);
...@@ -2154,8 +2154,8 @@ test "shift-right multi" {...@@ -2154,8 +2154,8 @@ test "shift-right multi" {
2154 );2154 );
2155 defer testing.allocator.free(string);2155 defer testing.allocator.free(string);
2156 try std.testing.expectEqualStrings(2156 try std.testing.expectEqualStrings(
2157 string,
2158 "ffff0000eeee1111dddd2222cccc3333",2157 "ffff0000eeee1111dddd2222cccc3333",
2158 string,
2159 );2159 );
2160}2160}
21612161
...@@ -2164,7 +2164,7 @@ test "shift-left single" {...@@ -2164,7 +2164,7 @@ test "shift-left single" {
2164 defer a.deinit();2164 defer a.deinit();
2165 try a.shiftLeft(&a, 16);2165 try a.shiftLeft(&a, 16);
21662166
2167 try testing.expect((try a.toInt(u64)) == 0xffff0000);2167 try testing.expectEqual(0xffff0000, try a.toInt(u64));
2168}2168}
21692169
2170test "shift-left multi" {2170test "shift-left multi" {
...@@ -2172,7 +2172,7 @@ test "shift-left multi" {...@@ -2172,7 +2172,7 @@ test "shift-left multi" {
2172 defer a.deinit();2172 defer a.deinit();
2173 try a.shiftLeft(&a, 67);2173 try a.shiftLeft(&a, 67);
21742174
2175 try testing.expect((try a.toInt(u128)) == 0xffff0000eeee11100000000000000000);2175 try testing.expectEqual(0xffff0000eeee11100000000000000000, try a.toInt(u128));
2176}2176}
21772177
2178test "shift-right negative" {2178test "shift-right negative" {
...@@ -2182,43 +2182,43 @@ test "shift-right negative" {...@@ -2182,43 +2182,43 @@ test "shift-right negative" {
2182 var arg = try Managed.initSet(testing.allocator, -20);2182 var arg = try Managed.initSet(testing.allocator, -20);
2183 defer arg.deinit();2183 defer arg.deinit();
2184 try a.shiftRight(&arg, 2);2184 try a.shiftRight(&arg, 2);
2185 try testing.expect((try a.toInt(i32)) == -5); // -20 >> 2 == -52185 try testing.expectEqual(-5, try a.toInt(i32)); // -20 >> 2 == -5
21862186
2187 var arg2 = try Managed.initSet(testing.allocator, -5);2187 var arg2 = try Managed.initSet(testing.allocator, -5);
2188 defer arg2.deinit();2188 defer arg2.deinit();
2189 try a.shiftRight(&arg2, 10);2189 try a.shiftRight(&arg2, 10);
2190 try testing.expect((try a.toInt(i32)) == -1); // -5 >> 10 == -12190 try testing.expectEqual(-1, try a.toInt(i32)); // -5 >> 10 == -1
21912191
2192 var arg3 = try Managed.initSet(testing.allocator, -10);2192 var arg3 = try Managed.initSet(testing.allocator, -10);
2193 defer arg3.deinit();2193 defer arg3.deinit();
2194 try a.shiftRight(&arg3, 1232);2194 try a.shiftRight(&arg3, 1232);
2195 try testing.expect((try a.toInt(i32)) == -1); // -10 >> 1232 == -12195 try testing.expectEqual(-1, try a.toInt(i32)); // -10 >> 1232 == -1
21962196
2197 var arg4 = try Managed.initSet(testing.allocator, -5);2197 var arg4 = try Managed.initSet(testing.allocator, -5);
2198 defer arg4.deinit();2198 defer arg4.deinit();
2199 try a.shiftRight(&arg4, 2);2199 try a.shiftRight(&arg4, 2);
2200 try testing.expect(try a.toInt(i32) == -2); // -5 >> 2 == -22200 try testing.expectEqual(-2, try a.toInt(i32)); // -5 >> 2 == -2
22012201
2202 var arg5 = try Managed.initSet(testing.allocator, -0xffff0000eeee1111dddd2222cccc3333);2202 var arg5 = try Managed.initSet(testing.allocator, -0xffff0000eeee1111dddd2222cccc3333);
2203 defer arg5.deinit();2203 defer arg5.deinit();
2204 try a.shiftRight(&arg5, 67);2204 try a.shiftRight(&arg5, 67);
2205 try testing.expect(try a.toInt(i64) == -0x1fffe0001dddc223);2205 try testing.expectEqual(-0x1fffe0001dddc223, try a.toInt(i64));
22062206
2207 var arg6 = try Managed.initSet(testing.allocator, -0x1ffffffffffffffff);2207 var arg6 = try Managed.initSet(testing.allocator, -0x1ffffffffffffffff);
2208 defer arg6.deinit();2208 defer arg6.deinit();
2209 try a.shiftRight(&arg6, 1);2209 try a.shiftRight(&arg6, 1);
2210 try a.shiftRight(&a, 1);2210 try a.shiftRight(&a, 1);
2211 a.setSign(true);2211 a.setSign(true);
2212 try testing.expect(try a.toInt(u64) == 0x8000000000000000);2212 try testing.expectEqual(0x8000000000000000, try a.toInt(u64));
22132213
2214 var arg7 = try Managed.initSet(testing.allocator, -32767);2214 var arg7 = try Managed.initSet(testing.allocator, -32767);
2215 defer arg7.deinit();2215 defer arg7.deinit();
2216 a.setSign(false);2216 a.setSign(false);
2217 try a.shiftRight(&arg7, 4);2217 try a.shiftRight(&arg7, 4);
2218 try testing.expect(try a.toInt(i16) == -2048);2218 try testing.expectEqual(-2048, try a.toInt(i16));
2219 a.setSign(true);2219 a.setSign(true);
2220 try a.shiftRight(&arg7, 4);2220 try a.shiftRight(&arg7, 4);
2221 try testing.expect(try a.toInt(i16) == -2048);2221 try testing.expectEqual(-2048, try a.toInt(i16));
22222222
2223 var arg8_limbs: [1]Limb = undefined;2223 var arg8_limbs: [1]Limb = undefined;
2224 var arg8: Mutable = .{2224 var arg8: Mutable = .{
...@@ -2235,7 +2235,7 @@ test "sat shift-left simple unsigned" {...@@ -2235,7 +2235,7 @@ test "sat shift-left simple unsigned" {
2235 defer a.deinit();2235 defer a.deinit();
2236 try a.shiftLeftSat(&a, 16, .unsigned, 21);2236 try a.shiftLeftSat(&a, 16, .unsigned, 21);
22372237
2238 try testing.expect((try a.toInt(u64)) == 0x1fffff);2238 try testing.expectEqual(0x1fffff, try a.toInt(u64));
2239}2239}
22402240
2241test "sat shift-left simple unsigned no sat" {2241test "sat shift-left simple unsigned no sat" {
...@@ -2243,7 +2243,7 @@ test "sat shift-left simple unsigned no sat" {...@@ -2243,7 +2243,7 @@ test "sat shift-left simple unsigned no sat" {
2243 defer a.deinit();2243 defer a.deinit();
2244 try a.shiftLeftSat(&a, 16, .unsigned, 21);2244 try a.shiftLeftSat(&a, 16, .unsigned, 21);
22452245
2246 try testing.expect((try a.toInt(u64)) == 0x10000);2246 try testing.expectEqual(0x10000, try a.toInt(u64));
2247}2247}
22482248
2249test "sat shift-left multi unsigned" {2249test "sat shift-left multi unsigned" {
...@@ -2251,7 +2251,7 @@ test "sat shift-left multi unsigned" {...@@ -2251,7 +2251,7 @@ test "sat shift-left multi unsigned" {
2251 defer a.deinit();2251 defer a.deinit();
2252 try a.shiftLeftSat(&a, @bitSizeOf(DoubleLimb) - 3, .unsigned, @bitSizeOf(DoubleLimb) - 1);2252 try a.shiftLeftSat(&a, @bitSizeOf(DoubleLimb) - 3, .unsigned, @bitSizeOf(DoubleLimb) - 1);
22532253
2254 try testing.expect((try a.toInt(DoubleLimb)) == maxInt(DoubleLimb) >> 1);2254 try testing.expectEqual(maxInt(DoubleLimb) >> 1, try a.toInt(DoubleLimb));
2255}2255}
22562256
2257test "sat shift-left unsigned shift > bitcount" {2257test "sat shift-left unsigned shift > bitcount" {
...@@ -2259,7 +2259,7 @@ test "sat shift-left unsigned shift > bitcount" {...@@ -2259,7 +2259,7 @@ test "sat shift-left unsigned shift > bitcount" {
2259 defer a.deinit();2259 defer a.deinit();
2260 try a.shiftLeftSat(&a, 10, .unsigned, 10);2260 try a.shiftLeftSat(&a, 10, .unsigned, 10);
22612261
2262 try testing.expect((try a.toInt(u10)) == maxInt(u10));2262 try testing.expectEqual(maxInt(u10), try a.toInt(u10));
2263}2263}
22642264
2265test "sat shift-left unsigned zero" {2265test "sat shift-left unsigned zero" {
...@@ -2267,7 +2267,7 @@ test "sat shift-left unsigned zero" {...@@ -2267,7 +2267,7 @@ test "sat shift-left unsigned zero" {
2267 defer a.deinit();2267 defer a.deinit();
2268 try a.shiftLeftSat(&a, 1, .unsigned, 0);2268 try a.shiftLeftSat(&a, 1, .unsigned, 0);
22692269
2270 try testing.expect((try a.toInt(u64)) == 0);2270 try testing.expectEqual(0, try a.toInt(u64));
2271}2271}
22722272
2273test "sat shift-left unsigned negative" {2273test "sat shift-left unsigned negative" {
...@@ -2275,7 +2275,7 @@ test "sat shift-left unsigned negative" {...@@ -2275,7 +2275,7 @@ test "sat shift-left unsigned negative" {
2275 defer a.deinit();2275 defer a.deinit();
2276 try a.shiftLeftSat(&a, 0, .unsigned, 0);2276 try a.shiftLeftSat(&a, 0, .unsigned, 0);
22772277
2278 try testing.expect((try a.toInt(u64)) == 0);2278 try testing.expectEqual(0, try a.toInt(u64));
2279}2279}
22802280
2281test "sat shift-left signed simple negative" {2281test "sat shift-left signed simple negative" {
...@@ -2283,7 +2283,7 @@ test "sat shift-left signed simple negative" {...@@ -2283,7 +2283,7 @@ test "sat shift-left signed simple negative" {
2283 defer a.deinit();2283 defer a.deinit();
2284 try a.shiftLeftSat(&a, 3, .signed, 10);2284 try a.shiftLeftSat(&a, 3, .signed, 10);
22852285
2286 try testing.expect((try a.toInt(i10)) == minInt(i10));2286 try testing.expectEqual(minInt(i10), try a.toInt(i10));
2287}2287}
22882288
2289test "sat shift-left signed simple positive" {2289test "sat shift-left signed simple positive" {
...@@ -2291,7 +2291,7 @@ test "sat shift-left signed simple positive" {...@@ -2291,7 +2291,7 @@ test "sat shift-left signed simple positive" {
2291 defer a.deinit();2291 defer a.deinit();
2292 try a.shiftLeftSat(&a, 3, .signed, 10);2292 try a.shiftLeftSat(&a, 3, .signed, 10);
22932293
2294 try testing.expect((try a.toInt(i10)) == maxInt(i10));2294 try testing.expectEqual(maxInt(i10), try a.toInt(i10));
2295}2295}
22962296
2297test "sat shift-left signed multi positive" {2297test "sat shift-left signed multi positive" {
...@@ -2306,7 +2306,7 @@ test "sat shift-left signed multi positive" {...@@ -2306,7 +2306,7 @@ test "sat shift-left signed multi positive" {
2306 defer a.deinit();2306 defer a.deinit();
2307 try a.shiftLeftSat(&a, shift, .signed, @bitSizeOf(SignedDoubleLimb));2307 try a.shiftLeftSat(&a, shift, .signed, @bitSizeOf(SignedDoubleLimb));
23082308
2309 try testing.expect((try a.toInt(SignedDoubleLimb)) == x <<| shift);2309 try testing.expectEqual(x <<| shift, try a.toInt(SignedDoubleLimb));
2310}2310}
23112311
2312test "sat shift-left signed multi negative" {2312test "sat shift-left signed multi negative" {
...@@ -2321,7 +2321,7 @@ test "sat shift-left signed multi negative" {...@@ -2321,7 +2321,7 @@ test "sat shift-left signed multi negative" {
2321 defer a.deinit();2321 defer a.deinit();
2322 try a.shiftLeftSat(&a, shift, .signed, @bitSizeOf(SignedDoubleLimb));2322 try a.shiftLeftSat(&a, shift, .signed, @bitSizeOf(SignedDoubleLimb));
23232323
2324 try testing.expect((try a.toInt(SignedDoubleLimb)) == x <<| shift);2324 try testing.expectEqual(x <<| shift, try a.toInt(SignedDoubleLimb));
2325}2325}
23262326
2327test "bitNotWrap unsigned simple" {2327test "bitNotWrap unsigned simple" {
...@@ -2333,7 +2333,7 @@ test "bitNotWrap unsigned simple" {...@@ -2333,7 +2333,7 @@ test "bitNotWrap unsigned simple" {
23332333
2334 try a.bitNotWrap(&a, .unsigned, 10);2334 try a.bitNotWrap(&a, .unsigned, 10);
23352335
2336 try testing.expect((try a.toInt(u10)) == ~x);2336 try testing.expectEqual(~x, try a.toInt(u10));
2337}2337}
23382338
2339test "bitNotWrap unsigned multi" {2339test "bitNotWrap unsigned multi" {
...@@ -2342,7 +2342,7 @@ test "bitNotWrap unsigned multi" {...@@ -2342,7 +2342,7 @@ test "bitNotWrap unsigned multi" {
23422342
2343 try a.bitNotWrap(&a, .unsigned, @bitSizeOf(DoubleLimb));2343 try a.bitNotWrap(&a, .unsigned, @bitSizeOf(DoubleLimb));
23442344
2345 try testing.expect((try a.toInt(DoubleLimb)) == maxInt(DoubleLimb));2345 try testing.expectEqual(maxInt(DoubleLimb), try a.toInt(DoubleLimb));
2346}2346}
23472347
2348test "bitNotWrap signed simple" {2348test "bitNotWrap signed simple" {
...@@ -2354,7 +2354,7 @@ test "bitNotWrap signed simple" {...@@ -2354,7 +2354,7 @@ test "bitNotWrap signed simple" {
23542354
2355 try a.bitNotWrap(&a, .signed, 11);2355 try a.bitNotWrap(&a, .signed, 11);
23562356
2357 try testing.expect((try a.toInt(i11)) == ~x);2357 try testing.expectEqual(~x, try a.toInt(i11));
2358}2358}
23592359
2360test "bitNotWrap signed multi" {2360test "bitNotWrap signed multi" {
...@@ -2363,7 +2363,7 @@ test "bitNotWrap signed multi" {...@@ -2363,7 +2363,7 @@ test "bitNotWrap signed multi" {
23632363
2364 try a.bitNotWrap(&a, .signed, @bitSizeOf(SignedDoubleLimb));2364 try a.bitNotWrap(&a, .signed, @bitSizeOf(SignedDoubleLimb));
23652365
2366 try testing.expect((try a.toInt(SignedDoubleLimb)) == -1);2366 try testing.expectEqual(-1, try a.toInt(SignedDoubleLimb));
2367}2367}
23682368
2369test "bitNotWrap more than two limbs" {2369test "bitNotWrap more than two limbs" {
...@@ -2400,7 +2400,7 @@ test "bitwise and simple" {...@@ -2400,7 +2400,7 @@ test "bitwise and simple" {
24002400
2401 try a.bitAnd(&a, &b);2401 try a.bitAnd(&a, &b);
24022402
2403 try testing.expect((try a.toInt(u64)) == 0xeeeeeeee00000000);2403 try testing.expectEqual(0xeeeeeeee00000000, try a.toInt(u64));
2404}2404}
24052405
2406test "bitwise and multi-limb" {2406test "bitwise and multi-limb" {
...@@ -2411,7 +2411,7 @@ test "bitwise and multi-limb" {...@@ -2411,7 +2411,7 @@ test "bitwise and multi-limb" {
24112411
2412 try a.bitAnd(&a, &b);2412 try a.bitAnd(&a, &b);
24132413
2414 try testing.expect((try a.toInt(u128)) == 0);2414 try testing.expectEqual(0, try a.toInt(u128));
2415}2415}
24162416
2417test "bitwise and negative-positive simple" {2417test "bitwise and negative-positive simple" {
...@@ -2422,7 +2422,7 @@ test "bitwise and negative-positive simple" {...@@ -2422,7 +2422,7 @@ test "bitwise and negative-positive simple" {
24222422
2423 try a.bitAnd(&a, &b);2423 try a.bitAnd(&a, &b);
24242424
2425 try testing.expect((try a.toInt(u64)) == 0x22222222);2425 try testing.expectEqual(0x22222222, try a.toInt(u64));
2426}2426}
24272427
2428test "bitwise and negative-positive multi-limb" {2428test "bitwise and negative-positive multi-limb" {
...@@ -2444,7 +2444,7 @@ test "bitwise and positive-negative simple" {...@@ -2444,7 +2444,7 @@ test "bitwise and positive-negative simple" {
24442444
2445 try a.bitAnd(&a, &b);2445 try a.bitAnd(&a, &b);
24462446
2447 try testing.expect((try a.toInt(u64)) == 0x1111111111111110);2447 try testing.expectEqual(0x1111111111111110, try a.toInt(u64));
2448}2448}
24492449
2450test "bitwise and positive-negative multi-limb" {2450test "bitwise and positive-negative multi-limb" {
...@@ -2466,7 +2466,7 @@ test "bitwise and negative-negative simple" {...@@ -2466,7 +2466,7 @@ test "bitwise and negative-negative simple" {
24662466
2467 try a.bitAnd(&a, &b);2467 try a.bitAnd(&a, &b);
24682468
2469 try testing.expect((try a.toInt(i128)) == -0xffffffff33333332);2469 try testing.expectEqual(-0xffffffff33333332, try a.toInt(i128));
2470}2470}
24712471
2472test "bitwise and negative-negative multi-limb" {2472test "bitwise and negative-negative multi-limb" {
...@@ -2477,7 +2477,7 @@ test "bitwise and negative-negative multi-limb" {...@@ -2477,7 +2477,7 @@ test "bitwise and negative-negative multi-limb" {
24772477
2478 try a.bitAnd(&a, &b);2478 try a.bitAnd(&a, &b);
24792479
2480 try testing.expect((try a.toInt(i128)) == -maxInt(Limb) * 2 - 2);2480 try testing.expectEqual(-maxInt(Limb) * 2 - 2, try a.toInt(i128));
2481}2481}
24822482
2483test "bitwise and negative overflow" {2483test "bitwise and negative overflow" {
...@@ -2488,7 +2488,7 @@ test "bitwise and negative overflow" {...@@ -2488,7 +2488,7 @@ test "bitwise and negative overflow" {
24882488
2489 try a.bitAnd(&a, &b);2489 try a.bitAnd(&a, &b);
24902490
2491 try testing.expect((try a.toInt(SignedDoubleLimb)) == -maxInt(Limb) - 1);2491 try testing.expectEqual(-maxInt(Limb) - 1, try a.toInt(SignedDoubleLimb));
2492}2492}
24932493
2494test "bitwise xor simple" {2494test "bitwise xor simple" {
...@@ -2499,7 +2499,7 @@ test "bitwise xor simple" {...@@ -2499,7 +2499,7 @@ test "bitwise xor simple" {
24992499
2500 try a.bitXor(&a, &b);2500 try a.bitXor(&a, &b);
25012501
2502 try testing.expect((try a.toInt(u64)) == 0x1111111133333333);2502 try testing.expectEqual(0x1111111133333333, try a.toInt(u64));
2503}2503}
25042504
2505test "bitwise xor multi-limb" {2505test "bitwise xor multi-limb" {
...@@ -2514,7 +2514,7 @@ test "bitwise xor multi-limb" {...@@ -2514,7 +2514,7 @@ test "bitwise xor multi-limb" {
25142514
2515 try a.bitXor(&a, &b);2515 try a.bitXor(&a, &b);
25162516
2517 try testing.expect((try a.toInt(DoubleLimb)) == x ^ y);2517 try testing.expectEqual(x ^ y, try a.toInt(DoubleLimb));
2518}2518}
25192519
2520test "bitwise xor single negative simple" {2520test "bitwise xor single negative simple" {
...@@ -2525,7 +2525,7 @@ test "bitwise xor single negative simple" {...@@ -2525,7 +2525,7 @@ test "bitwise xor single negative simple" {
25252525
2526 try a.bitXor(&a, &b);2526 try a.bitXor(&a, &b);
25272527
2528 try testing.expect((try a.toInt(i64)) == -0x2efed94fcb932ef9);2528 try testing.expectEqual(-0x2efed94fcb932ef9, try a.toInt(i64));
2529}2529}
25302530
2531test "bitwise xor single negative multi-limb" {2531test "bitwise xor single negative multi-limb" {
...@@ -2536,7 +2536,7 @@ test "bitwise xor single negative multi-limb" {...@@ -2536,7 +2536,7 @@ test "bitwise xor single negative multi-limb" {
25362536
2537 try a.bitXor(&a, &b);2537 try a.bitXor(&a, &b);
25382538
2539 try testing.expect((try a.toInt(i128)) == -0x6a50889abd8834a24db1f19650d3999a);2539 try testing.expectEqual(-0x6a50889abd8834a24db1f19650d3999a, try a.toInt(i128));
2540}2540}
25412541
2542test "bitwise xor single negative overflow" {2542test "bitwise xor single negative overflow" {
...@@ -2547,7 +2547,7 @@ test "bitwise xor single negative overflow" {...@@ -2547,7 +2547,7 @@ test "bitwise xor single negative overflow" {
25472547
2548 try a.bitXor(&a, &b);2548 try a.bitXor(&a, &b);
25492549
2550 try testing.expect((try a.toInt(SignedDoubleLimb)) == -(maxInt(Limb) + 1));2550 try testing.expectEqual(-(maxInt(Limb) + 1), try a.toInt(SignedDoubleLimb));
2551}2551}
25522552
2553test "bitwise xor double negative simple" {2553test "bitwise xor double negative simple" {
...@@ -2558,7 +2558,7 @@ test "bitwise xor double negative simple" {...@@ -2558,7 +2558,7 @@ test "bitwise xor double negative simple" {
25582558
2559 try a.bitXor(&a, &b);2559 try a.bitXor(&a, &b);
25602560
2561 try testing.expect((try a.toInt(u64)) == 0xc39c47081a6eb759);2561 try testing.expectEqual(0xc39c47081a6eb759, try a.toInt(u64));
2562}2562}
25632563
2564test "bitwise xor double negative multi-limb" {2564test "bitwise xor double negative multi-limb" {
...@@ -2569,7 +2569,7 @@ test "bitwise xor double negative multi-limb" {...@@ -2569,7 +2569,7 @@ test "bitwise xor double negative multi-limb" {
25692569
2570 try a.bitXor(&a, &b);2570 try a.bitXor(&a, &b);
25712571
2572 try testing.expect((try a.toInt(u128)) == 0xa3492ec28e62c410dff92bf0549bf771);2572 try testing.expectEqual(0xa3492ec28e62c410dff92bf0549bf771, try a.toInt(u128));
2573}2573}
25742574
2575test "bitwise or simple" {2575test "bitwise or simple" {
...@@ -2580,7 +2580,7 @@ test "bitwise or simple" {...@@ -2580,7 +2580,7 @@ test "bitwise or simple" {
25802580
2581 try a.bitOr(&a, &b);2581 try a.bitOr(&a, &b);
25822582
2583 try testing.expect((try a.toInt(u64)) == 0xffffffff33333333);2583 try testing.expectEqual(0xffffffff33333333, try a.toInt(u64));
2584}2584}
25852585
2586test "bitwise or multi-limb" {2586test "bitwise or multi-limb" {
...@@ -2591,7 +2591,7 @@ test "bitwise or multi-limb" {...@@ -2591,7 +2591,7 @@ test "bitwise or multi-limb" {
25912591
2592 try a.bitOr(&a, &b);2592 try a.bitOr(&a, &b);
25932593
2594 try testing.expect((try a.toInt(DoubleLimb)) == (maxInt(Limb) + 1) + maxInt(Limb));2594 try testing.expectEqual((maxInt(Limb) + 1) + maxInt(Limb), try a.toInt(DoubleLimb));
2595}2595}
25962596
2597test "bitwise or negative-positive simple" {2597test "bitwise or negative-positive simple" {
...@@ -2602,7 +2602,7 @@ test "bitwise or negative-positive simple" {...@@ -2602,7 +2602,7 @@ test "bitwise or negative-positive simple" {
26022602
2603 try a.bitOr(&a, &b);2603 try a.bitOr(&a, &b);
26042604
2605 try testing.expect((try a.toInt(i64)) == -0x1111111111111111);2605 try testing.expectEqual(-0x1111111111111111, try a.toInt(i64));
2606}2606}
26072607
2608test "bitwise or negative-positive multi-limb" {2608test "bitwise or negative-positive multi-limb" {
...@@ -2613,7 +2613,7 @@ test "bitwise or negative-positive multi-limb" {...@@ -2613,7 +2613,7 @@ test "bitwise or negative-positive multi-limb" {
26132613
2614 try a.bitOr(&a, &b);2614 try a.bitOr(&a, &b);
26152615
2616 try testing.expect((try a.toInt(SignedDoubleLimb)) == -maxInt(Limb));2616 try testing.expectEqual(-maxInt(Limb), try a.toInt(SignedDoubleLimb));
2617}2617}
26182618
2619test "bitwise or positive-negative simple" {2619test "bitwise or positive-negative simple" {
...@@ -2624,7 +2624,7 @@ test "bitwise or positive-negative simple" {...@@ -2624,7 +2624,7 @@ test "bitwise or positive-negative simple" {
26242624
2625 try a.bitOr(&a, &b);2625 try a.bitOr(&a, &b);
26262626
2627 try testing.expect((try a.toInt(i64)) == -0x22222221);2627 try testing.expectEqual(-0x22222221, try a.toInt(i64));
2628}2628}
26292629
2630test "bitwise or positive-negative multi-limb" {2630test "bitwise or positive-negative multi-limb" {
...@@ -2635,7 +2635,7 @@ test "bitwise or positive-negative multi-limb" {...@@ -2635,7 +2635,7 @@ test "bitwise or positive-negative multi-limb" {
26352635
2636 try a.bitOr(&a, &b);2636 try a.bitOr(&a, &b);
26372637
2638 try testing.expect((try a.toInt(SignedDoubleLimb)) == -1);2638 try testing.expectEqual(-1, try a.toInt(SignedDoubleLimb));
2639}2639}
26402640
2641test "bitwise or negative-negative simple" {2641test "bitwise or negative-negative simple" {
...@@ -2646,7 +2646,7 @@ test "bitwise or negative-negative simple" {...@@ -2646,7 +2646,7 @@ test "bitwise or negative-negative simple" {
26462646
2647 try a.bitOr(&a, &b);2647 try a.bitOr(&a, &b);
26482648
2649 try testing.expect((try a.toInt(i128)) == -0xeeeeeeee00000001);2649 try testing.expectEqual(-0xeeeeeeee00000001, try a.toInt(i128));
2650}2650}
26512651
2652test "bitwise or negative-negative multi-limb" {2652test "bitwise or negative-negative multi-limb" {
...@@ -2657,7 +2657,7 @@ test "bitwise or negative-negative multi-limb" {...@@ -2657,7 +2657,7 @@ test "bitwise or negative-negative multi-limb" {
26572657
2658 try a.bitOr(&a, &b);2658 try a.bitOr(&a, &b);
26592659
2660 try testing.expect((try a.toInt(SignedDoubleLimb)) == -maxInt(Limb));2660 try testing.expectEqual(-maxInt(Limb), try a.toInt(SignedDoubleLimb));
2661}2661}
26622662
2663test "var args" {2663test "var args" {
...@@ -2667,11 +2667,11 @@ test "var args" {...@@ -2667,11 +2667,11 @@ test "var args" {
2667 var b = try Managed.initSet(testing.allocator, 6);2667 var b = try Managed.initSet(testing.allocator, 6);
2668 defer b.deinit();2668 defer b.deinit();
2669 try a.add(&a, &b);2669 try a.add(&a, &b);
2670 try testing.expect((try a.toInt(u64)) == 11);2670 try testing.expectEqual(11, try a.toInt(u64));
26712671
2672 var c = try Managed.initSet(testing.allocator, 11);2672 var c = try Managed.initSet(testing.allocator, 11);
2673 defer c.deinit();2673 defer c.deinit();
2674 try testing.expect(a.order(c) == .eq);2674 try testing.expectEqual(.eq, a.order(c));
26752675
2676 var d = try Managed.initSet(testing.allocator, 14);2676 var d = try Managed.initSet(testing.allocator, 14);
2677 defer d.deinit();2677 defer d.deinit();
...@@ -2688,7 +2688,7 @@ test "gcd non-one small" {...@@ -2688,7 +2688,7 @@ test "gcd non-one small" {
26882688
2689 try r.gcd(&a, &b);2689 try r.gcd(&a, &b);
26902690
2691 try testing.expect((try r.toInt(u32)) == 1);2691 try testing.expectEqual(1, try r.toInt(u32));
2692}2692}
26932693
2694test "gcd non-one medium" {2694test "gcd non-one medium" {
...@@ -2701,7 +2701,7 @@ test "gcd non-one medium" {...@@ -2701,7 +2701,7 @@ test "gcd non-one medium" {
27012701
2702 try r.gcd(&a, &b);2702 try r.gcd(&a, &b);
27032703
2704 try testing.expect((try r.toInt(u32)) == 38);2704 try testing.expectEqual(38, try r.toInt(u32));
2705}2705}
27062706
2707test "gcd non-one large" {2707test "gcd non-one large" {
...@@ -2714,7 +2714,7 @@ test "gcd non-one large" {...@@ -2714,7 +2714,7 @@ test "gcd non-one large" {
27142714
2715 try r.gcd(&a, &b);2715 try r.gcd(&a, &b);
27162716
2717 try testing.expect((try r.toInt(u32)) == 4369);2717 try testing.expectEqual(4369, try r.toInt(u32));
2718}2718}
27192719
2720test "gcd large multi-limb result" {2720test "gcd large multi-limb result" {
...@@ -2730,7 +2730,7 @@ test "gcd large multi-limb result" {...@@ -2730,7 +2730,7 @@ test "gcd large multi-limb result" {
2730 try r.gcd(&a, &b);2730 try r.gcd(&a, &b);
27312731
2732 const answer = (try r.toInt(u256));2732 const answer = (try r.toInt(u256));
2733 try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);2733 try testing.expectEqual(0xf000000ff00000fff0000ffff000fffff00ffffff1, answer);
2734}2734}
27352735
2736test "gcd one large" {2736test "gcd one large" {
...@@ -2743,7 +2743,7 @@ test "gcd one large" {...@@ -2743,7 +2743,7 @@ test "gcd one large" {
27432743
2744 try r.gcd(&a, &b);2744 try r.gcd(&a, &b);
27452745
2746 try testing.expect((try r.toInt(u64)) == 1);2746 try testing.expectEqual(1, try r.toInt(u64));
2747}2747}
27482748
2749test "mutable to managed" {2749test "mutable to managed" {
...@@ -2863,7 +2863,7 @@ test "regression test for 1 limb overflow with alias" {...@@ -2863,7 +2863,7 @@ test "regression test for 1 limb overflow with alias" {
2863 try a.ensureAddCapacity(a.toConst(), b.toConst());2863 try a.ensureAddCapacity(a.toConst(), b.toConst());
2864 try a.add(&a, &b);2864 try a.add(&a, &b);
28652865
2866 try testing.expect(a.toConst().orderAgainstScalar(19740274219868223167) == .eq);2866 try testing.expectEqual(.eq, a.toConst().orderAgainstScalar(19740274219868223167));
2867}2867}
28682868
2869test "regression test for realloc with alias" {2869test "regression test for realloc with alias" {
...@@ -2877,7 +2877,7 @@ test "regression test for realloc with alias" {...@@ -2877,7 +2877,7 @@ test "regression test for realloc with alias" {
2877 try a.ensureAddCapacity(a.toConst(), b.toConst());2877 try a.ensureAddCapacity(a.toConst(), b.toConst());
2878 try a.add(&a, &b);2878 try a.add(&a, &b);
28792879
2880 try testing.expect(a.toConst().orderAgainstScalar(14691098406862188148944207245954912110548093601382197697835) == .eq);2880 try testing.expectEqual(.eq, a.toConst().orderAgainstScalar(14691098406862188148944207245954912110548093601382197697835));
2881}2881}
28822882
2883test "big int popcount" {2883test "big int popcount" {
...@@ -2977,12 +2977,12 @@ test "big int conversion read/write twos complement" {...@@ -2977,12 +2977,12 @@ test "big int conversion read/write twos complement" {
2977 // Writing to buffer and back should not change anything2977 // Writing to buffer and back should not change anything
2978 a.toConst().writeTwosComplement(buffer1[0..abi_size], endian);2978 a.toConst().writeTwosComplement(buffer1[0..abi_size], endian);
2979 m.readTwosComplement(buffer1[0..abi_size], 493, endian, .unsigned);2979 m.readTwosComplement(buffer1[0..abi_size], 493, endian, .unsigned);
2980 try testing.expect(m.toConst().order(a.toConst()) == .eq);2980 try testing.expectEqual(.eq, m.toConst().order(a.toConst()));
29812981
2982 // Equivalent to @bitCast(i493, @as(u493, intMax(u493))2982 // Equivalent to @bitCast(i493, @as(u493, intMax(u493))
2983 a.toConst().writeTwosComplement(buffer1[0..abi_size], endian);2983 a.toConst().writeTwosComplement(buffer1[0..abi_size], endian);
2984 m.readTwosComplement(buffer1[0..abi_size], 493, endian, .signed);2984 m.readTwosComplement(buffer1[0..abi_size], 493, endian, .signed);
2985 try testing.expect(m.toConst().orderAgainstScalar(-1) == .eq);2985 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(-1));
2986 }2986 }
2987}2987}
29882988
...@@ -3076,19 +3076,19 @@ test "big int conversion write twos complement with padding" {...@@ -3076,19 +3076,19 @@ test "big int conversion write twos complement with padding" {
30763076
3077 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xb };3077 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xb };
3078 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);3078 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
3079 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);3079 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d));
30803080
3081 buffer = &[_]u8{ 0xb, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };3081 buffer = &[_]u8{ 0xb, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
3082 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);3082 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
3083 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);3083 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d));
30843084
3085 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xab, 0xaa, 0xaa, 0xaa };3085 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xab, 0xaa, 0xaa, 0xaa };
3086 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);3086 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);
3087 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);3087 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d));
30883088
3089 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xab, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };3089 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xab, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
3090 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);3090 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);
3091 try testing.expect(m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d) == .eq);3091 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x01_02030405_06070809_0a0b0c0d));
30923092
3093 bit_count = @sizeOf(Limb) * 8;3093 bit_count = @sizeOf(Limb) * 8;
30943094
...@@ -3096,19 +3096,19 @@ test "big int conversion write twos complement with padding" {...@@ -3096,19 +3096,19 @@ test "big int conversion write twos complement with padding" {
30963096
3097 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa };3097 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa };
3098 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);3098 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
3099 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq);3099 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))));
31003100
3101 buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };3101 buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
3102 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);3102 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
3103 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))) == .eq);3103 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaa_02030405_06070809_0a0b0c0d))));
31043104
3105 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa };3105 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa };
3106 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);3106 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);
3107 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq);3107 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))));
31083108
3109 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };3109 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
3110 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);3110 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);
3111 try testing.expect(m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))) == .eq);3111 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(@as(Limb, @truncate(0xaaaaaaaa_02030405_06070809_0a0b0c0d))));
31123112
3113 bit_count = 12 * 8 + 2;3113 bit_count = 12 * 8 + 2;
31143114
...@@ -3116,42 +3116,42 @@ test "big int conversion write twos complement with padding" {...@@ -3116,42 +3116,42 @@ test "big int conversion write twos complement with padding" {
31163116
3117 buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02 };3117 buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02 };
3118 m.readTwosComplement(buffer[0..13], bit_count, .little, .signed);3118 m.readTwosComplement(buffer[0..13], bit_count, .little, .signed);
3119 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);3119 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d));
31203120
3121 buffer = &[_]u8{ 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 };3121 buffer = &[_]u8{ 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 };
3122 m.readTwosComplement(buffer[0..13], bit_count, .big, .signed);3122 m.readTwosComplement(buffer[0..13], bit_count, .big, .signed);
3123 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);3123 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d));
31243124
3125 buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02, 0xaa, 0xaa, 0xaa };3125 buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02, 0xaa, 0xaa, 0xaa };
3126 m.readTwosComplement(buffer[0..16], bit_count, .little, .signed);3126 m.readTwosComplement(buffer[0..16], bit_count, .little, .signed);
3127 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);3127 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d));
31283128
3129 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 };3129 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 };
3130 m.readTwosComplement(buffer[0..16], bit_count, .big, .signed);3130 m.readTwosComplement(buffer[0..16], bit_count, .big, .signed);
3131 try testing.expect(m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d) == .eq);3131 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(-0x01_02030405_06070809_0a0b0c0d));
31323132
3133 // Test 03133 // Test 0
31343134
3135 buffer = &([_]u8{0} ** 16);3135 buffer = &([_]u8{0} ** 16);
3136 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);3136 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
3137 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3137 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3138 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);3138 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
3139 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3139 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3140 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);3140 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);
3141 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3141 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3142 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);3142 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);
3143 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3143 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
31443144
3145 bit_count = 0;3145 bit_count = 0;
3146 buffer = &([_]u8{0xaa} ** 16);3146 buffer = &([_]u8{0xaa} ** 16);
3147 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);3147 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
3148 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3148 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3149 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);3149 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
3150 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3150 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3151 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);3151 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);
3152 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3152 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3153 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);3153 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);
3154 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3154 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3155}3155}
31563156
3157test "big int conversion write twos complement zero" {3157test "big int conversion write twos complement zero" {
...@@ -3170,15 +3170,15 @@ test "big int conversion write twos complement zero" {...@@ -3170,15 +3170,15 @@ test "big int conversion write twos complement zero" {
31703170
3171 buffer = &([_]u8{0} ** 13);3171 buffer = &([_]u8{0} ** 13);
3172 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);3172 m.readTwosComplement(buffer[0..13], bit_count, .little, .unsigned);
3173 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3173 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3174 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);3174 m.readTwosComplement(buffer[0..13], bit_count, .big, .unsigned);
3175 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3175 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
31763176
3177 buffer = &([_]u8{0} ** 16);3177 buffer = &([_]u8{0} ** 16);
3178 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);3178 m.readTwosComplement(buffer[0..16], bit_count, .little, .unsigned);
3179 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3179 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3180 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);3180 m.readTwosComplement(buffer[0..16], bit_count, .big, .unsigned);
3181 try testing.expect(m.toConst().orderAgainstScalar(0x0) == .eq);3181 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(0x0));
3182}3182}
31833183
3184fn bitReverseTest(comptime T: type, comptime input: comptime_int, comptime expected_output: comptime_int) !void {3184fn bitReverseTest(comptime T: type, comptime input: comptime_int, comptime expected_output: comptime_int) !void {
...@@ -3191,7 +3191,7 @@ fn bitReverseTest(comptime T: type, comptime input: comptime_int, comptime expec...@@ -3191,7 +3191,7 @@ fn bitReverseTest(comptime T: type, comptime input: comptime_int, comptime expec
3191 try a.ensureCapacity(calcTwosCompLimbCount(bit_count));3191 try a.ensureCapacity(calcTwosCompLimbCount(bit_count));
3192 var m = a.toMutable();3192 var m = a.toMutable();
3193 m.bitReverse(a.toConst(), signedness, bit_count);3193 m.bitReverse(a.toConst(), signedness, bit_count);
3194 try testing.expect(m.toConst().orderAgainstScalar(expected_output) == .eq);3194 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(expected_output));
3195}3195}
31963196
3197test "big int bit reverse" {3197test "big int bit reverse" {
...@@ -3238,7 +3238,7 @@ fn byteSwapTest(comptime T: type, comptime input: comptime_int, comptime expecte...@@ -3238,7 +3238,7 @@ fn byteSwapTest(comptime T: type, comptime input: comptime_int, comptime expecte
3238 try a.ensureCapacity(calcTwosCompLimbCount(8 * byte_count));3238 try a.ensureCapacity(calcTwosCompLimbCount(8 * byte_count));
3239 var m = a.toMutable();3239 var m = a.toMutable();
3240 m.byteSwap(a.toConst(), signedness, byte_count);3240 m.byteSwap(a.toConst(), signedness, byte_count);
3241 try testing.expect(m.toConst().orderAgainstScalar(expected_output) == .eq);3241 try testing.expectEqual(.eq, m.toConst().orderAgainstScalar(expected_output));
3242}3242}
32433243
3244test "big int byte swap" {3244test "big int byte swap" {
...@@ -3449,111 +3449,111 @@ test "clz" {...@@ -3449,111 +3449,111 @@ test "clz" {
3449 .limbs = &.{ 1, maxInt(Limb) - 1 },3449 .limbs = &.{ 1, maxInt(Limb) - 1 },
3450 .positive = false,3450 .positive = false,
3451 };3451 };
3452 try testing.expect(neg_limb_max_squared.clz(@bitSizeOf(Limb) * 2 + 1) == 0);3452 try testing.expectEqual(0, neg_limb_max_squared.clz(@bitSizeOf(Limb) * 2 + 1));
34533453
3454 const neg_limb_max_squared_plus_one: std.math.big.int.Const = .{3454 const neg_limb_max_squared_plus_one: std.math.big.int.Const = .{
3455 .limbs = &.{ 0, maxInt(Limb) - 1 },3455 .limbs = &.{ 0, maxInt(Limb) - 1 },
3456 .positive = false,3456 .positive = false,
3457 };3457 };
3458 try testing.expect(neg_limb_max_squared_plus_one.clz(@bitSizeOf(Limb) * 2 + 1) == 0);3458 try testing.expectEqual(0, neg_limb_max_squared_plus_one.clz(@bitSizeOf(Limb) * 2 + 1));
34593459
3460 const neg_limb_msb_squared: std.math.big.int.Const = .{3460 const neg_limb_msb_squared: std.math.big.int.Const = .{
3461 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },3461 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
3462 .positive = false,3462 .positive = false,
3463 };3463 };
3464 try testing.expect(neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2) == 0);3464 try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2));
3465 try testing.expect(neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1) == 0);3465 try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1));
34663466
3467 const neg_limb_max: std.math.big.int.Const = .{3467 const neg_limb_max: std.math.big.int.Const = .{
3468 .limbs = &.{maxInt(Limb)},3468 .limbs = &.{maxInt(Limb)},
3469 .positive = false,3469 .positive = false,
3470 };3470 };
3471 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) + 1) == 0);3471 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) + 1));
3472 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) * 2 - 1) == 0);3472 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 - 1));
3473 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) * 2) == 0);3473 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2));
3474 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1) == 0);3474 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
34753475
3476 const neg_limb_msb: std.math.big.int.Const = .{3476 const neg_limb_msb: std.math.big.int.Const = .{
3477 .limbs = &.{1 << @bitSizeOf(Limb) - 1},3477 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
3478 .positive = false,3478 .positive = false,
3479 };3479 };
3480 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb)) == 0);3480 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb)));
3481 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) + 1) == 0);3481 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) + 1));
3482 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) * 2 - 1) == 0);3482 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) * 2 - 1));
3483 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) * 2) == 0);3483 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) * 2));
3484 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) * 2 + 1) == 0);3484 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) * 2 + 1));
34853485
3486 const neg_one: std.math.big.int.Const = .{3486 const neg_one: std.math.big.int.Const = .{
3487 .limbs = &.{1},3487 .limbs = &.{1},
3488 .positive = false,3488 .positive = false,
3489 };3489 };
3490 try testing.expect(neg_one.clz(@bitSizeOf(Limb)) == 0);3490 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb)));
3491 try testing.expect(neg_one.clz(@bitSizeOf(Limb) + 1) == 0);3491 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) + 1));
3492 try testing.expect(neg_one.clz(@bitSizeOf(Limb) * 2 - 1) == 0);3492 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) * 2 - 1));
3493 try testing.expect(neg_one.clz(@bitSizeOf(Limb) * 2) == 0);3493 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) * 2));
3494 try testing.expect(neg_one.clz(@bitSizeOf(Limb) * 2 + 1) == 0);3494 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) * 2 + 1));
34953495
3496 const zero: std.math.big.int.Const = .{3496 const zero: std.math.big.int.Const = .{
3497 .limbs = &.{0},3497 .limbs = &.{0},
3498 .positive = true,3498 .positive = true,
3499 };3499 };
3500 try testing.expect(zero.clz(@bitSizeOf(Limb)) == @bitSizeOf(Limb));3500 try testing.expectEqual(@bitSizeOf(Limb), zero.clz(@bitSizeOf(Limb)));
3501 try testing.expect(zero.clz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) + 1);3501 try testing.expectEqual(@bitSizeOf(Limb) + 1, zero.clz(@bitSizeOf(Limb) + 1));
3502 try testing.expect(zero.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 1);3502 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 1, zero.clz(@bitSizeOf(Limb) * 2 - 1));
3503 try testing.expect(zero.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2);3503 try testing.expectEqual(@bitSizeOf(Limb) * 2, zero.clz(@bitSizeOf(Limb) * 2));
3504 try testing.expect(zero.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2 + 1);3504 try testing.expectEqual(@bitSizeOf(Limb) * 2 + 1, zero.clz(@bitSizeOf(Limb) * 2 + 1));
35053505
3506 const one: std.math.big.int.Const = .{3506 const one: std.math.big.int.Const = .{
3507 .limbs = &.{1},3507 .limbs = &.{1},
3508 .positive = true,3508 .positive = true,
3509 };3509 };
3510 try testing.expect(one.clz(@bitSizeOf(Limb)) == @bitSizeOf(Limb) - 1);3510 try testing.expectEqual(@bitSizeOf(Limb) - 1, one.clz(@bitSizeOf(Limb)));
3511 try testing.expect(one.clz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb));3511 try testing.expectEqual(@bitSizeOf(Limb), one.clz(@bitSizeOf(Limb) + 1));
3512 try testing.expect(one.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 2);3512 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, one.clz(@bitSizeOf(Limb) * 2 - 1));
3513 try testing.expect(one.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2 - 1);3513 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 1, one.clz(@bitSizeOf(Limb) * 2));
3514 try testing.expect(one.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2);3514 try testing.expectEqual(@bitSizeOf(Limb) * 2, one.clz(@bitSizeOf(Limb) * 2 + 1));
35153515
3516 const limb_msb: std.math.big.int.Const = .{3516 const limb_msb: std.math.big.int.Const = .{
3517 .limbs = &.{1 << @bitSizeOf(Limb) - 1},3517 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
3518 .positive = true,3518 .positive = true,
3519 };3519 };
3520 try testing.expect(limb_msb.clz(@bitSizeOf(Limb)) == 0);3520 try testing.expectEqual(0, limb_msb.clz(@bitSizeOf(Limb)));
3521 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) + 1) == 1);3521 try testing.expectEqual(1, limb_msb.clz(@bitSizeOf(Limb) + 1));
3522 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);3522 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.clz(@bitSizeOf(Limb) * 2 - 1));
3523 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb));3523 try testing.expectEqual(@bitSizeOf(Limb), limb_msb.clz(@bitSizeOf(Limb) * 2));
3524 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) + 1);3524 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_msb.clz(@bitSizeOf(Limb) * 2 + 1));
35253525
3526 const limb_max: std.math.big.int.Const = .{3526 const limb_max: std.math.big.int.Const = .{
3527 .limbs = &.{maxInt(Limb)},3527 .limbs = &.{maxInt(Limb)},
3528 .positive = true,3528 .positive = true,
3529 };3529 };
3530 try testing.expect(limb_max.clz(@bitSizeOf(Limb)) == 0);3530 try testing.expectEqual(0, limb_max.clz(@bitSizeOf(Limb)));
3531 try testing.expect(limb_max.clz(@bitSizeOf(Limb) + 1) == 1);3531 try testing.expectEqual(1, limb_max.clz(@bitSizeOf(Limb) + 1));
3532 try testing.expect(limb_max.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);3532 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_max.clz(@bitSizeOf(Limb) * 2 - 1));
3533 try testing.expect(limb_max.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb));3533 try testing.expectEqual(@bitSizeOf(Limb), limb_max.clz(@bitSizeOf(Limb) * 2));
3534 try testing.expect(limb_max.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) + 1);3534 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
35353535
3536 const limb_msb_squared: std.math.big.int.Const = .{3536 const limb_msb_squared: std.math.big.int.Const = .{
3537 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },3537 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
3538 .positive = true,3538 .positive = true,
3539 };3539 };
3540 try testing.expect(limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1) == 0);3540 try testing.expectEqual(0, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1));
3541 try testing.expect(limb_msb_squared.clz(@bitSizeOf(Limb) * 2) == 1);3541 try testing.expectEqual(1, limb_msb_squared.clz(@bitSizeOf(Limb) * 2));
3542 try testing.expect(limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1) == 2);3542 try testing.expectEqual(2, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1));
35433543
3544 const limb_max_squared_minus_one: std.math.big.int.Const = .{3544 const limb_max_squared_minus_one: std.math.big.int.Const = .{
3545 .limbs = &.{ 0, maxInt(Limb) - 1 },3545 .limbs = &.{ 0, maxInt(Limb) - 1 },
3546 .positive = true,3546 .positive = true,
3547 };3547 };
3548 try testing.expect(limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2) == 0);3548 try testing.expectEqual(0, limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2));
3549 try testing.expect(limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2 + 1) == 1);3549 try testing.expectEqual(1, limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2 + 1));
35503550
3551 const limb_max_squared: std.math.big.int.Const = .{3551 const limb_max_squared: std.math.big.int.Const = .{
3552 .limbs = &.{ 1, maxInt(Limb) - 1 },3552 .limbs = &.{ 1, maxInt(Limb) - 1 },
3553 .positive = true,3553 .positive = true,
3554 };3554 };
3555 try testing.expect(limb_max_squared.clz(@bitSizeOf(Limb) * 2) == 0);3555 try testing.expectEqual(0, limb_max_squared.clz(@bitSizeOf(Limb) * 2));
3556 try testing.expect(limb_max_squared.clz(@bitSizeOf(Limb) * 2 + 1) == 1);3556 try testing.expectEqual(1, limb_max_squared.clz(@bitSizeOf(Limb) * 2 + 1));
3557}3557}
35583558
3559test "ctz" {3559test "ctz" {
...@@ -3561,109 +3561,109 @@ test "ctz" {...@@ -3561,109 +3561,109 @@ test "ctz" {
3561 .limbs = &.{ 1, maxInt(Limb) - 1 },3561 .limbs = &.{ 1, maxInt(Limb) - 1 },
3562 .positive = false,3562 .positive = false,
3563 };3563 };
3564 try testing.expect(neg_limb_max_squared.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);3564 try testing.expectEqual(0, neg_limb_max_squared.ctz(@bitSizeOf(Limb) * 2 + 1));
35653565
3566 const neg_limb_max_squared_plus_one: std.math.big.int.Const = .{3566 const neg_limb_max_squared_plus_one: std.math.big.int.Const = .{
3567 .limbs = &.{ 0, maxInt(Limb) - 1 },3567 .limbs = &.{ 0, maxInt(Limb) - 1 },
3568 .positive = false,3568 .positive = false,
3569 };3569 };
3570 try testing.expect(neg_limb_max_squared_plus_one.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) + 1);3570 try testing.expectEqual(@bitSizeOf(Limb) + 1, neg_limb_max_squared_plus_one.ctz(@bitSizeOf(Limb) * 2 + 1));
35713571
3572 const neg_limb_msb_squared: std.math.big.int.Const = .{3572 const neg_limb_msb_squared: std.math.big.int.Const = .{
3573 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },3573 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
3574 .positive = false,3574 .positive = false,
3575 };3575 };
3576 try testing.expect(neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2 - 2);3576 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));
3577 try testing.expect(neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2 - 2);3577 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 + 1));
35783578
3579 const neg_limb_max: std.math.big.int.Const = .{3579 const neg_limb_max: std.math.big.int.Const = .{
3580 .limbs = &.{maxInt(Limb)},3580 .limbs = &.{maxInt(Limb)},
3581 .positive = false,3581 .positive = false,
3582 };3582 };
3583 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) + 1) == 0);3583 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) + 1));
3584 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);3584 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 - 1));
3585 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) * 2) == 0);3585 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2));
3586 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);3586 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
35873587
3588 const neg_limb_msb: std.math.big.int.Const = .{3588 const neg_limb_msb: std.math.big.int.Const = .{
3589 .limbs = &.{1 << @bitSizeOf(Limb) - 1},3589 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
3590 .positive = false,3590 .positive = false,
3591 };3591 };
3592 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb)) == @bitSizeOf(Limb) - 1);3592 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb)));
3593 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) - 1);3593 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) + 1));
3594 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);3594 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1));
3595 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) - 1);3595 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) * 2));
3596 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) - 1);3596 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1));
35973597
3598 const neg_one: std.math.big.int.Const = .{3598 const neg_one: std.math.big.int.Const = .{
3599 .limbs = &.{1},3599 .limbs = &.{1},
3600 .positive = false,3600 .positive = false,
3601 };3601 };
3602 try testing.expect(neg_one.ctz(@bitSizeOf(Limb)) == 0);3602 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb)));
3603 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) + 1) == 0);3603 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) + 1));
3604 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);3604 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) * 2 - 1));
3605 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) * 2) == 0);3605 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) * 2));
3606 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);3606 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) * 2 + 1));
36073607
3608 const zero: std.math.big.int.Const = .{3608 const zero: std.math.big.int.Const = .{
3609 .limbs = &.{0},3609 .limbs = &.{0},
3610 .positive = true,3610 .positive = true,
3611 };3611 };
3612 try testing.expect(zero.ctz(@bitSizeOf(Limb)) == @bitSizeOf(Limb));3612 try testing.expectEqual(@bitSizeOf(Limb), zero.ctz(@bitSizeOf(Limb)));
3613 try testing.expect(zero.ctz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) + 1);3613 try testing.expectEqual(@bitSizeOf(Limb) + 1, zero.ctz(@bitSizeOf(Limb) + 1));
3614 try testing.expect(zero.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 1);3614 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 1, zero.ctz(@bitSizeOf(Limb) * 2 - 1));
3615 try testing.expect(zero.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2);3615 try testing.expectEqual(@bitSizeOf(Limb) * 2, zero.ctz(@bitSizeOf(Limb) * 2));
3616 try testing.expect(zero.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2 + 1);3616 try testing.expectEqual(@bitSizeOf(Limb) * 2 + 1, zero.ctz(@bitSizeOf(Limb) * 2 + 1));
36173617
3618 const one: std.math.big.int.Const = .{3618 const one: std.math.big.int.Const = .{
3619 .limbs = &.{1},3619 .limbs = &.{1},
3620 .positive = true,3620 .positive = true,
3621 };3621 };
3622 try testing.expect(one.ctz(@bitSizeOf(Limb)) == 0);3622 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb)));
3623 try testing.expect(one.ctz(@bitSizeOf(Limb) + 1) == 0);3623 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) + 1));
3624 try testing.expect(one.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);3624 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 - 1));
3625 try testing.expect(one.ctz(@bitSizeOf(Limb) * 2) == 0);3625 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2));
3626 try testing.expect(one.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);3626 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 + 1));
36273627
3628 const limb_msb: std.math.big.int.Const = .{3628 const limb_msb: std.math.big.int.Const = .{
3629 .limbs = &.{1 << @bitSizeOf(Limb) - 1},3629 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
3630 .positive = true,3630 .positive = true,
3631 };3631 };
3632 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb)) == @bitSizeOf(Limb) - 1);3632 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb)));
3633 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) - 1);3633 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) + 1));
3634 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);3634 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1));
3635 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) - 1);3635 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) * 2));
3636 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) - 1);3636 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1));
36373637
3638 const limb_max: std.math.big.int.Const = .{3638 const limb_max: std.math.big.int.Const = .{
3639 .limbs = &.{maxInt(Limb)},3639 .limbs = &.{maxInt(Limb)},
3640 .positive = true,3640 .positive = true,
3641 };3641 };
3642 try testing.expect(limb_max.ctz(@bitSizeOf(Limb)) == 0);3642 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb)));
3643 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) + 1) == 0);3643 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) + 1));
3644 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);3644 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 - 1));
3645 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) * 2) == 0);3645 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2));
3646 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);3646 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
36473647
3648 const limb_msb_squared: std.math.big.int.Const = .{3648 const limb_msb_squared: std.math.big.int.Const = .{
3649 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },3649 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
3650 .positive = true,3650 .positive = true,
3651 };3651 };
3652 try testing.expect(limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 2);3652 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 - 1));
3653 try testing.expect(limb_msb_squared.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2 - 2);3653 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));
3654 try testing.expect(limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2 - 2);3654 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 + 1));
36553655
3656 const limb_max_squared_minus_one: std.math.big.int.Const = .{3656 const limb_max_squared_minus_one: std.math.big.int.Const = .{
3657 .limbs = &.{ 0, maxInt(Limb) - 1 },3657 .limbs = &.{ 0, maxInt(Limb) - 1 },
3658 .positive = true,3658 .positive = true,
3659 };3659 };
3660 try testing.expect(limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) + 1);3660 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2));
3661 try testing.expect(limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) + 1);3661 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2 + 1));
36623662
3663 const limb_max_squared: std.math.big.int.Const = .{3663 const limb_max_squared: std.math.big.int.Const = .{
3664 .limbs = &.{ 1, maxInt(Limb) - 1 },3664 .limbs = &.{ 1, maxInt(Limb) - 1 },
3665 .positive = true,3665 .positive = true,
3666 };3666 };
3667 try testing.expect(limb_max_squared.ctz(@bitSizeOf(Limb) * 2) == 0);3667 try testing.expectEqual(0, limb_max_squared.ctz(@bitSizeOf(Limb) * 2));
3668 try testing.expect(limb_max_squared.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);3668 try testing.expectEqual(0, limb_max_squared.ctz(@bitSizeOf(Limb) * 2 + 1));
3669}3669}