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;
1717const Signedness = std.builtin.Signedness;
1818const native_endian = builtin.cpu.arch.endian();
1919
20const debug_safety = false;
21
2220/// Returns the number of limbs needed to store `scalar`, which must be a
2321/// primitive integer value.
2422/// Note: A comptime-known upper bound of this value that may be used
......@@ -92,8 +90,6 @@ pub fn calcTwosCompLimbCount(bit_count: usize) usize {
9290
9391/// a + b * c + *carry, sets carry to the overflow bits
9492pub fn addMulLimbWithCarry(a: Limb, b: Limb, c: Limb, carry: *Limb) Limb {
95 @setRuntimeSafety(debug_safety);
96
9793 // ov1[0] = a + *carry
9894 const ov1 = @addWithOverflow(a, carry.*);
9995
......@@ -213,7 +209,7 @@ pub const Mutable = struct {
213209 for (self.limbs[0..self.len]) |limb| {
214210 std.debug.print("{x} ", .{limb});
215211 }
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 });
217213 }
218214
219215 /// 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 {
11071103 /// Asserts there is enough memory to fit the result. The upper bound Limb count is
11081104 /// `a.limbs.len + (shift / (@sizeOf(Limb) * 8))`.
11091105 pub fn shiftLeft(r: *Mutable, a: Const, shift: usize) void {
1110 llshl(r.limbs, a.limbs, shift);
1111 r.normalize(a.limbs.len + (shift / limb_bits) + 1);
1106 const new_len = llshl(r.limbs, a.limbs, shift);
1107 r.normalize(new_len);
11121108 r.positive = a.positive;
11131109 }
11141110
......@@ -1176,8 +1172,8 @@ pub const Mutable = struct {
11761172
11771173 // This shift should not be able to overflow, so invoke llshl and normalize manually
11781174 // to avoid the extra required limb.
1179 llshl(r.limbs, a.limbs, shift);
1180 r.normalize(a.limbs.len + (shift / limb_bits));
1175 const new_len = llshl(r.limbs, a.limbs, shift);
1176 r.normalize(new_len);
11811177 r.positive = a.positive;
11821178 }
11831179
......@@ -1185,7 +1181,7 @@ pub const Mutable = struct {
11851181 /// r and a may alias.
11861182 ///
11871183 /// 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)))`.
11891185 pub fn shiftRight(r: *Mutable, a: Const, shift: usize) void {
11901186 const full_limbs_shifted_out = shift / limb_bits;
11911187 const remaining_bits_shifted_out = shift % limb_bits;
......@@ -1213,9 +1209,9 @@ pub const Mutable = struct {
12131209 break :nonzero a.limbs[full_limbs_shifted_out] << not_covered != 0;
12141210 };
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;
12191215 r.positive = a.positive;
12201216 if (nonzero_negative_shiftout) r.addScalar(r.toConst(), -1);
12211217 r.normalize(r.len);
......@@ -1974,7 +1970,7 @@ pub const Const = struct {
19741970 for (self.limbs[0..self.limbs.len]) |limb| {
19751971 std.debug.print("{x} ", .{limb});
19761972 }
1977 std.debug.print("positive={}\n", .{self.positive});
1973 std.debug.print("len={} positive={}\n", .{ self.len, self.positive });
19781974 }
19791975
19801976 pub fn abs(self: Const) Const {
......@@ -2676,7 +2672,7 @@ pub const Managed = struct {
26762672 for (self.limbs[0..self.len()]) |limb| {
26772673 std.debug.print("{x} ", .{limb});
26782674 }
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() });
26802676 }
26812677
26822678 /// Negate the sign.
......@@ -3277,9 +3273,10 @@ const AccOp = enum {
32773273///
32783274/// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs.
32793275fn llmulacc(comptime op: AccOp, opt_allocator: ?Allocator, r: []Limb, a: []const Limb, b: []const Limb) void {
3280 @setRuntimeSafety(debug_safety);
32813276 assert(r.len >= a.len);
32823277 assert(r.len >= b.len);
3278 assert(!slicesOverlap(r, a));
3279 assert(!slicesOverlap(r, b));
32833280
32843281 // Order greatest first.
32853282 var x = a;
......@@ -3316,9 +3313,10 @@ fn llmulaccKaratsuba(
33163313 a: []const Limb,
33173314 b: []const Limb,
33183315) error{OutOfMemory}!void {
3319 @setRuntimeSafety(debug_safety);
33203316 assert(r.len >= a.len);
33213317 assert(a.len >= b.len);
3318 assert(!slicesOverlap(r, a));
3319 assert(!slicesOverlap(r, b));
33223320
33233321 // Classical karatsuba algorithm:
33243322 // a = a1 * B + a0
......@@ -3479,7 +3477,6 @@ fn llmulaccKaratsuba(
34793477/// r = r (op) a.
34803478/// The result is computed modulo `r.len`.
34813479fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {
3482 @setRuntimeSafety(debug_safety);
34833480 if (op == .sub) {
34843481 _ = llsubcarry(r, r, a);
34853482 return;
......@@ -3508,7 +3505,6 @@ fn llaccum(comptime op: AccOp, r: []Limb, a: []const Limb) void {
35083505
35093506/// Returns -1, 0, 1 if |a| < |b|, |a| == |b| or |a| > |b| respectively for limbs.
35103507pub fn llcmp(a: []const Limb, b: []const Limb) i8 {
3511 @setRuntimeSafety(debug_safety);
35123508 const a_len = llnormalize(a);
35133509 const b_len = llnormalize(b);
35143510 if (a_len < b_len) {
......@@ -3537,7 +3533,6 @@ pub fn llcmp(a: []const Limb, b: []const Limb) i8 {
35373533/// r = r (op) y * xi
35383534/// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs.
35393535fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb) void {
3540 @setRuntimeSafety(debug_safety);
35413536 assert(r.len >= a.len);
35423537 assert(a.len >= b.len);
35433538
......@@ -3551,7 +3546,6 @@ fn llmulaccLong(comptime op: AccOp, r: []Limb, a: []const Limb, b: []const Limb)
35513546/// The result is computed modulo `r.len`.
35523547/// Returns whether the operation overflowed.
35533548fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {
3554 @setRuntimeSafety(debug_safety);
35553549 if (xi == 0) {
35563550 return false;
35573551 }
......@@ -3598,7 +3592,6 @@ fn llmulLimb(comptime op: AccOp, acc: []Limb, y: []const Limb, xi: Limb) bool {
35983592
35993593/// returns the min length the limb could be.
36003594fn llnormalize(a: []const Limb) usize {
3601 @setRuntimeSafety(debug_safety);
36023595 var j = a.len;
36033596 while (j > 0) : (j -= 1) {
36043597 if (a[j - 1] != 0) {
......@@ -3612,7 +3605,6 @@ fn llnormalize(a: []const Limb) usize {
36123605
36133606/// Knuth 4.3.1, Algorithm S.
36143607fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
3615 @setRuntimeSafety(debug_safety);
36163608 assert(a.len != 0 and b.len != 0);
36173609 assert(a.len >= b.len);
36183610 assert(r.len >= a.len);
......@@ -3638,14 +3630,12 @@ fn llsubcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
36383630}
36393631
36403632fn llsub(r: []Limb, a: []const Limb, b: []const Limb) void {
3641 @setRuntimeSafety(debug_safety);
36423633 assert(a.len > b.len or (a.len == b.len and a[a.len - 1] >= b[b.len - 1]));
36433634 assert(llsubcarry(r, a, b) == 0);
36443635}
36453636
36463637/// Knuth 4.3.1, Algorithm A.
36473638fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
3648 @setRuntimeSafety(debug_safety);
36493639 assert(a.len != 0 and b.len != 0);
36503640 assert(a.len >= b.len);
36513641 assert(r.len >= a.len);
......@@ -3671,14 +3661,12 @@ fn lladdcarry(r: []Limb, a: []const Limb, b: []const Limb) Limb {
36713661}
36723662
36733663fn lladd(r: []Limb, a: []const Limb, b: []const Limb) void {
3674 @setRuntimeSafety(debug_safety);
36753664 assert(r.len >= a.len + 1);
36763665 r[a.len] = lladdcarry(r, a, b);
36773666}
36783667
36793668/// Knuth 4.3.1, Exercise 16.
36803669fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
3681 @setRuntimeSafety(debug_safety);
36823670 assert(a.len > 1 or a[0] >= b);
36833671 assert(quo.len >= a.len);
36843672
......@@ -3704,7 +3692,6 @@ fn lldiv1(quo: []Limb, rem: *Limb, a: []const Limb, b: Limb) void {
37043692}
37053693
37063694fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void {
3707 @setRuntimeSafety(debug_safety);
37083695 assert(a.len > 1 or a[0] >= b);
37093696 assert(quo.len >= a.len);
37103697
......@@ -3727,69 +3714,114 @@ fn lldiv0p5(quo: []Limb, rem: *Limb, a: []const Limb, b: HalfLimb) void {
37273714 }
37283715}
37293716
3730fn llshl(r: []Limb, a: []const Limb, shift: usize) void {
3731 @setRuntimeSafety(debug_safety);
3732 assert(a.len >= 1);
3717/// Performs r = a << shift and returns the amount of limbs affected
3718///
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
37363744 // We only need the extra limb if the shift of the last element overflows.
37373745 // This is useful for the implementation of `shiftLeftSat`.
3738 if (a[a.len - 1] << interior_limb_shift >> interior_limb_shift != a[a.len - 1]) {
3739 assert(r.len >= a.len + (shift / limb_bits) + 1);
3746 const overflows = a[a.len - 1] >> opposite_bit_shift != 0;
3747 if (overflows) {
3748 std.debug.assert(r.len >= a.len + 1);
37403749 } 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);
37423761 }
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;
3747 var i: usize = 0;
3748 while (i < a.len) : (i += 1) {
3749 const src_i = a.len - i - 1;
3750 const dst_i = src_i + limb_shift;
3767/// Performs r = a >> shift and returns the amount of limbs affected
3768///
3769/// if a and r overlaps, then r.ptr <= a.ptr is asserted
3770/// r must have the capacity to store a >> 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];
3753 r[dst_i] = carry | @call(.always_inline, math.shr, .{
3754 Limb,
3755 src_digit,
3756 limb_bits - @as(Limb, @intCast(interior_limb_shift)),
3757 });
3758 carry = (src_digit << interior_limb_shift);
3779 if (shift == 0) {
3780 std.debug.assert(r.len >= a.len);
3781
3782 if (a.ptr != r.ptr)
3783 std.mem.copyForwards(Limb, r[0..a.len], a);
3784 return a.len;
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);
37593792 }
37603793
3761 r[limb_shift - 1] = carry;
3762 @memset(r[0 .. limb_shift - 1], 0);
3763}
3794 // shift is guaranteed to be < limb_bits
3795 const bit_shift: Log2Limb = @truncate(shift);
3796 const opposite_bit_shift: Log2Limb = @truncate(limb_bits - bit_shift);
37643797
3765fn llshr(r: []Limb, a: []const Limb, shift: usize) void {
3766 @setRuntimeSafety(debug_safety);
3767 assert(a.len >= 1);
3768 assert(r.len >= a.len - (shift / limb_bits));
3798 // special case, where there is a risk to set r to 0
3799 if (a.len == 1) {
3800 r[0] = a[0] >> bit_shift;
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;
3771 const interior_limb_shift = @as(Log2Limb, @truncate(shift));
3808 // if the most significant limb becomes 0 after the shift
3809 const shrink = a[a.len - 1] >> bit_shift == 0;
3810 std.debug.assert(r.len >= a.len - @intFromBool(!shrink));
37723811
37733812 var i: usize = 0;
3774 while (i < a.len - limb_shift) : (i += 1) {
3775 const dst_i = i;
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);
3813 while (i < a.len - 1) : (i += 1) {
3814 r[i] = (a[i] >> bit_shift) | (a[i + 1] << opposite_bit_shift);
37863815 }
3816
3817 if (!shrink)
3818 r[i] = a[i] >> bit_shift;
3819
3820 return a.len - @intFromBool(shrink);
37873821}
37883822
37893823// r = ~r
37903824fn llnot(r: []Limb) void {
3791 @setRuntimeSafety(debug_safety);
3792
37933825 for (r) |*elem| {
37943826 elem.* = ~elem.*;
37953827 }
......@@ -3802,7 +3834,6 @@ fn llnot(r: []Limb) void {
38023834// When b is positive, r requires at least `a.len` limbs of storage.
38033835// When b is negative, r requires at least `b.len` limbs of storage.
38043836fn llsignedor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {
3805 @setRuntimeSafety(debug_safety);
38063837 assert(r.len >= a.len);
38073838 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
39333964// 2. when b is negative but a is positive, r requires at least `a.len` limbs of storage,
39343965// 3. when both a and b are negative, r requires at least `a.len + 1` limbs of storage.
39353966fn llsignedand(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {
3936 @setRuntimeSafety(debug_safety);
39373967 assert(a.len != 0 and b.len != 0);
39383968 assert(a.len >= b.len);
39393969 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_
40434073// If the sign of a and b is equal, then r requires at least `@max(a.len, b.len)` limbs are required.
40444074// Otherwise, r requires at least `@max(a.len, b.len) + 1` limbs.
40454075fn llsignedxor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_positive: bool) bool {
4046 @setRuntimeSafety(debug_safety);
40474076 assert(a.len != 0 and b.len != 0);
40484077 assert(r.len >= a.len);
40494078 assert(a.len >= b.len);
......@@ -4102,10 +4131,9 @@ fn llsignedxor(r: []Limb, a: []const Limb, a_positive: bool, b: []const Limb, b_
41024131
41034132/// r MUST NOT alias x.
41044133fn llsquareBasecase(r: []Limb, x: []const Limb) void {
4105 @setRuntimeSafety(debug_safety);
4106
41074134 const x_norm = x;
41084135 assert(r.len >= 2 * x_norm.len + 1);
4136 assert(!slicesOverlap(r, x));
41094137
41104138 // Compute the square of a N-limb bigint with only (N^2 + N)/2
41114139 // multiplications by exploiting the symmetry of the coefficients around the
......@@ -4129,7 +4157,7 @@ fn llsquareBasecase(r: []Limb, x: []const Limb) void {
41294157 }
41304158
41314159 // 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
41344162 for (x_norm, 0..) |v, i| {
41354163 // Compute and add the squares
......@@ -4201,6 +4229,290 @@ fn fixedIntFromSignedDoubleLimb(A: SignedDoubleLimb, storage: []Limb) Mutable {
42014229 };
42024230}
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
42044237test {
42054238 _ = @import("int_test.zig");
42064239}
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" {
2929 const result = @as(Limb, s & maxInt(Limb));
3030 s >>= @typeInfo(Limb).int.bits / 2;
3131 s >>= @typeInfo(Limb).int.bits / 2;
32 try testing.expect(a.limbs[i] == result);
32 try testing.expectEqual(result, a.limbs[i]);
3333 }
3434}
3535
......@@ -37,37 +37,37 @@ test "comptime_int set negative" {
3737 var a = try Managed.initSet(testing.allocator, -10);
3838 defer a.deinit();
3939
40 try testing.expect(a.limbs[0] == 10);
41 try testing.expect(a.isPositive() == false);
40 try testing.expectEqual(10, a.limbs[0]);
41 try testing.expectEqual(false, a.isPositive());
4242}
4343
4444test "int set unaligned small" {
4545 var a = try Managed.initSet(testing.allocator, @as(u7, 45));
4646 defer a.deinit();
4747
48 try testing.expect(a.limbs[0] == 45);
49 try testing.expect(a.isPositive() == true);
48 try testing.expectEqual(45, a.limbs[0]);
49 try testing.expectEqual(true, a.isPositive());
5050}
5151
5252test "comptime_int to" {
5353 var a = try Managed.initSet(testing.allocator, 0xefffffff00000001eeeeeeefaaaaaaab);
5454 defer a.deinit();
5555
56 try testing.expect((try a.toInt(u128)) == 0xefffffff00000001eeeeeeefaaaaaaab);
56 try testing.expectEqual(0xefffffff00000001eeeeeeefaaaaaaab, try a.toInt(u128));
5757}
5858
5959test "sub-limb to" {
6060 var a = try Managed.initSet(testing.allocator, 10);
6161 defer a.deinit();
6262
63 try testing.expect((try a.toInt(u8)) == 10);
63 try testing.expectEqual(10, try a.toInt(u8));
6464}
6565
6666test "set negative minimum" {
6767 var a = try Managed.initSet(testing.allocator, @as(i64, minInt(i64)));
6868 defer a.deinit();
6969
70 try testing.expect((try a.toInt(i64)) == minInt(i64));
70 try testing.expectEqual(minInt(i64), try a.toInt(i64));
7171}
7272
7373test "set double-width maximum then zero" {
......@@ -95,22 +95,22 @@ test "normalize" {
9595 a.limbs[2] = 3;
9696 a.limbs[3] = 0;
9797 a.normalize(4);
98 try testing.expect(a.len() == 3);
98 try testing.expectEqual(3, a.len());
9999
100100 a.limbs[0] = 1;
101101 a.limbs[1] = 2;
102102 a.limbs[2] = 3;
103103 a.normalize(3);
104 try testing.expect(a.len() == 3);
104 try testing.expectEqual(3, a.len());
105105
106106 a.limbs[0] = 0;
107107 a.limbs[1] = 0;
108108 a.normalize(2);
109 try testing.expect(a.len() == 1);
109 try testing.expectEqual(1, a.len());
110110
111111 a.limbs[0] = 0;
112112 a.normalize(1);
113 try testing.expect(a.len() == 1);
113 try testing.expectEqual(1, a.len());
114114}
115115
116116test "normalize multi" {
......@@ -123,24 +123,24 @@ test "normalize multi" {
123123 a.limbs[2] = 0;
124124 a.limbs[3] = 0;
125125 a.normalize(4);
126 try testing.expect(a.len() == 2);
126 try testing.expectEqual(2, a.len());
127127
128128 a.limbs[0] = 1;
129129 a.limbs[1] = 2;
130130 a.limbs[2] = 3;
131131 a.normalize(3);
132 try testing.expect(a.len() == 3);
132 try testing.expectEqual(3, a.len());
133133
134134 a.limbs[0] = 0;
135135 a.limbs[1] = 0;
136136 a.limbs[2] = 0;
137137 a.limbs[3] = 0;
138138 a.normalize(4);
139 try testing.expect(a.len() == 1);
139 try testing.expectEqual(1, a.len());
140140
141141 a.limbs[0] = 0;
142142 a.normalize(1);
143 try testing.expect(a.len() == 1);
143 try testing.expectEqual(1, a.len());
144144}
145145
146146test "parity" {
......@@ -161,26 +161,26 @@ test "bitcount + sizeInBaseUpperBound" {
161161 defer a.deinit();
162162
163163 try a.set(0b100);
164 try testing.expect(a.bitCountAbs() == 3);
164 try testing.expectEqual(3, a.bitCountAbs());
165165 try testing.expect(a.sizeInBaseUpperBound(2) >= 3);
166166 try testing.expect(a.sizeInBaseUpperBound(10) >= 1);
167167
168168 a.negate();
169 try testing.expect(a.bitCountAbs() == 3);
169 try testing.expectEqual(3, a.bitCountAbs());
170170 try testing.expect(a.sizeInBaseUpperBound(2) >= 4);
171171 try testing.expect(a.sizeInBaseUpperBound(10) >= 2);
172172
173173 try a.set(0xffffffff);
174 try testing.expect(a.bitCountAbs() == 32);
174 try testing.expectEqual(32, a.bitCountAbs());
175175 try testing.expect(a.sizeInBaseUpperBound(2) >= 32);
176176 try testing.expect(a.sizeInBaseUpperBound(10) >= 10);
177177
178178 try a.shiftLeft(&a, 5000);
179 try testing.expect(a.bitCountAbs() == 5032);
179 try testing.expectEqual(5032, a.bitCountAbs());
180180 try testing.expect(a.sizeInBaseUpperBound(2) >= 5032);
181181 a.setSign(false);
182182
183 try testing.expect(a.bitCountAbs() == 5032);
183 try testing.expectEqual(5032, a.bitCountAbs());
184184 try testing.expect(a.sizeInBaseUpperBound(2) >= 5033);
185185}
186186
......@@ -189,30 +189,30 @@ test "bitcount/to" {
189189 defer a.deinit();
190190
191191 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);
195 try testing.expect((try a.toInt(i0)) == 0);
194 try testing.expectEqual(0, try a.toInt(u0));
195 try testing.expectEqual(0, try a.toInt(i0));
196196
197197 try a.set(-1);
198 try testing.expect(a.bitCountTwosComp() == 1);
199 try testing.expect((try a.toInt(i1)) == -1);
198 try testing.expectEqual(1, a.bitCountTwosComp());
199 try testing.expectEqual(-1, try a.toInt(i1));
200200
201201 try a.set(-8);
202 try testing.expect(a.bitCountTwosComp() == 4);
203 try testing.expect((try a.toInt(i4)) == -8);
202 try testing.expectEqual(4, a.bitCountTwosComp());
203 try testing.expectEqual(-8, try a.toInt(i4));
204204
205205 try a.set(127);
206 try testing.expect(a.bitCountTwosComp() == 7);
207 try testing.expect((try a.toInt(u7)) == 127);
206 try testing.expectEqual(7, a.bitCountTwosComp());
207 try testing.expectEqual(127, try a.toInt(u7));
208208
209209 try a.set(-128);
210 try testing.expect(a.bitCountTwosComp() == 8);
211 try testing.expect((try a.toInt(i8)) == -128);
210 try testing.expectEqual(8, a.bitCountTwosComp());
211 try testing.expectEqual(-128, try a.toInt(i8));
212212
213213 try a.set(-129);
214 try testing.expect(a.bitCountTwosComp() == 9);
215 try testing.expect((try a.toInt(i9)) == -129);
214 try testing.expectEqual(9, a.bitCountTwosComp());
215 try testing.expectEqual(-129, try a.toInt(i9));
216216}
217217
218218test "fits" {
......@@ -248,7 +248,7 @@ test "string set" {
248248 defer a.deinit();
249249
250250 try a.setString(10, "120317241209124781241290847124");
251 try testing.expect((try a.toInt(u128)) == 120317241209124781241290847124);
251 try testing.expectEqual(120317241209124781241290847124, try a.toInt(u128));
252252}
253253
254254test "string negative" {
......@@ -256,7 +256,7 @@ test "string negative" {
256256 defer a.deinit();
257257
258258 try a.setString(10, "-1023");
259 try testing.expect((try a.toInt(i32)) == -1023);
259 try testing.expectEqual(-1023, try a.toInt(i32));
260260}
261261
262262test "string set number with underscores" {
......@@ -264,7 +264,7 @@ test "string set number with underscores" {
264264 defer a.deinit();
265265
266266 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));
268268}
269269
270270test "string set case insensitive number" {
......@@ -272,7 +272,7 @@ test "string set case insensitive number" {
272272 defer a.deinit();
273273
274274 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));
276276}
277277
278278test "string set base 36" {
......@@ -280,7 +280,7 @@ test "string set base 36" {
280280 defer a.deinit();
281281
282282 try a.setString(36, "fifvthrv1mzt79ez9");
283 try testing.expect((try a.to(u128)) == 123456789123456789123456789);
283 try testing.expectEqual(123456789123456789123456789, try a.to(u128));
284284}
285285
286286test "string set bad char error" {
......@@ -314,11 +314,11 @@ fn testTwosComplementLimit(comptime T: type) !void {
314314
315315 try a.setTwosCompIntLimit(.max, int_info.signedness, int_info.bits);
316316 const max: T = maxInt(T);
317 try testing.expect(max == try a.toInt(T));
317 try testing.expectEqual(max, try a.toInt(T));
318318
319319 try a.setTwosCompIntLimit(.min, int_info.signedness, int_info.bits);
320320 const min: T = minInt(T);
321 try testing.expect(min == try a.toInt(T));
321 try testing.expectEqual(min, try a.toInt(T));
322322}
323323
324324test "string to" {
......@@ -400,12 +400,12 @@ test "clone" {
400400 var b = try a.clone();
401401 defer b.deinit();
402402
403 try testing.expect((try a.toInt(u32)) == 1234);
404 try testing.expect((try b.toInt(u32)) == 1234);
403 try testing.expectEqual(1234, try a.toInt(u32));
404 try testing.expectEqual(1234, try b.toInt(u32));
405405
406406 try a.set(77);
407 try testing.expect((try a.toInt(u32)) == 77);
408 try testing.expect((try b.toInt(u32)) == 1234);
407 try testing.expectEqual(77, try a.toInt(u32));
408 try testing.expectEqual(1234, try b.toInt(u32));
409409}
410410
411411test "swap" {
......@@ -414,20 +414,20 @@ test "swap" {
414414 var b = try Managed.initSet(testing.allocator, 5678);
415415 defer b.deinit();
416416
417 try testing.expect((try a.toInt(u32)) == 1234);
418 try testing.expect((try b.toInt(u32)) == 5678);
417 try testing.expectEqual(1234, try a.toInt(u32));
418 try testing.expectEqual(5678, try b.toInt(u32));
419419
420420 a.swap(&b);
421421
422 try testing.expect((try a.toInt(u32)) == 5678);
423 try testing.expect((try b.toInt(u32)) == 1234);
422 try testing.expectEqual(5678, try a.toInt(u32));
423 try testing.expectEqual(1234, try b.toInt(u32));
424424}
425425
426426test "to negative" {
427427 var a = try Managed.initSet(testing.allocator, -10);
428428 defer a.deinit();
429429
430 try testing.expect((try a.toInt(i32)) == -10);
430 try testing.expectEqual(-10, try a.toInt(i32));
431431}
432432
433433test "compare" {
......@@ -436,8 +436,8 @@ test "compare" {
436436 var b = try Managed.initSet(testing.allocator, 10);
437437 defer b.deinit();
438438
439 try testing.expect(a.orderAbs(b) == .gt);
440 try testing.expect(a.order(b) == .lt);
439 try testing.expectEqual(.gt, a.orderAbs(b));
440 try testing.expectEqual(.lt, a.order(b));
441441}
442442
443443test "compare similar" {
......@@ -446,8 +446,8 @@ test "compare similar" {
446446 var b = try Managed.initSet(testing.allocator, 0xffffffffeeeeeeeeffffffffeeeeeeef);
447447 defer b.deinit();
448448
449 try testing.expect(a.orderAbs(b) == .lt);
450 try testing.expect(b.orderAbs(a) == .gt);
449 try testing.expectEqual(.lt, a.orderAbs(b));
450 try testing.expectEqual(.gt, b.orderAbs(a));
451451}
452452
453453test "compare different limb size" {
......@@ -456,8 +456,8 @@ test "compare different limb size" {
456456 var b = try Managed.initSet(testing.allocator, 1);
457457 defer b.deinit();
458458
459 try testing.expect(a.orderAbs(b) == .gt);
460 try testing.expect(b.orderAbs(a) == .lt);
459 try testing.expectEqual(.gt, a.orderAbs(b));
460 try testing.expectEqual(.lt, b.orderAbs(a));
461461}
462462
463463test "compare multi-limb" {
......@@ -466,8 +466,8 @@ test "compare multi-limb" {
466466 var b = try Managed.initSet(testing.allocator, 0x7777777799999999ffffeeeeffffeeeeffffeeeee);
467467 defer b.deinit();
468468
469 try testing.expect(a.orderAbs(b) == .gt);
470 try testing.expect(a.order(b) == .lt);
469 try testing.expectEqual(.gt, a.orderAbs(b));
470 try testing.expectEqual(.lt, a.order(b));
471471}
472472
473473test "equality" {
......@@ -485,10 +485,10 @@ test "abs" {
485485 defer a.deinit();
486486
487487 a.abs();
488 try testing.expect((try a.toInt(u32)) == 5);
488 try testing.expectEqual(5, try a.toInt(u32));
489489
490490 a.abs();
491 try testing.expect((try a.toInt(u32)) == 5);
491 try testing.expectEqual(5, try a.toInt(u32));
492492}
493493
494494test "negate" {
......@@ -496,10 +496,10 @@ test "negate" {
496496 defer a.deinit();
497497
498498 a.negate();
499 try testing.expect((try a.toInt(i32)) == -5);
499 try testing.expectEqual(-5, try a.toInt(i32));
500500
501501 a.negate();
502 try testing.expect((try a.toInt(i32)) == 5);
502 try testing.expectEqual(5, try a.toInt(i32));
503503}
504504
505505test "add single-single" {
......@@ -512,7 +512,7 @@ test "add single-single" {
512512 defer c.deinit();
513513 try c.add(&a, &b);
514514
515 try testing.expect((try c.toInt(u32)) == 55);
515 try testing.expectEqual(55, try c.toInt(u32));
516516}
517517
518518test "add multi-single" {
......@@ -525,10 +525,10 @@ test "add multi-single" {
525525 defer c.deinit();
526526
527527 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
530530 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));
532532}
533533
534534test "add multi-multi" {
......@@ -546,7 +546,7 @@ test "add multi-multi" {
546546 defer c.deinit();
547547 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));
550550}
551551
552552test "add zero-zero" {
......@@ -559,7 +559,7 @@ test "add zero-zero" {
559559 defer c.deinit();
560560 try c.add(&a, &b);
561561
562 try testing.expect((try c.toInt(u32)) == 0);
562 try testing.expectEqual(0, try c.toInt(u32));
563563}
564564
565565test "add alias multi-limb nonzero-zero" {
......@@ -571,7 +571,7 @@ test "add alias multi-limb nonzero-zero" {
571571
572572 try a.add(&a, &b);
573573
574 try testing.expect((try a.toInt(u128)) == op1);
574 try testing.expectEqual(op1, try a.toInt(u128));
575575}
576576
577577test "add sign" {
......@@ -588,16 +588,16 @@ test "add sign" {
588588 defer neg_two.deinit();
589589
590590 try a.add(&one, &two);
591 try testing.expect((try a.toInt(i32)) == 3);
591 try testing.expectEqual(3, try a.toInt(i32));
592592
593593 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
596596 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
599599 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));
601601}
602602
603603test "add comptime scalar" {
......@@ -608,7 +608,7 @@ test "add comptime scalar" {
608608 defer b.deinit();
609609 try b.addScalar(&a, 5);
610610
611 try testing.expect((try b.toInt(u32)) == 55);
611 try testing.expectEqual(55, try b.toInt(u32));
612612}
613613
614614test "add scalar" {
......@@ -619,7 +619,7 @@ test "add scalar" {
619619 defer b.deinit();
620620 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));
623623}
624624
625625test "addWrap single-single, unsigned" {
......@@ -632,7 +632,7 @@ test "addWrap single-single, unsigned" {
632632 const wrapped = try a.addWrap(&a, &b, .unsigned, 17);
633633
634634 try testing.expect(wrapped);
635 try testing.expect((try a.toInt(u17)) == 9);
635 try testing.expectEqual(9, try a.toInt(u17));
636636}
637637
638638test "subWrap single-single, unsigned" {
......@@ -645,7 +645,7 @@ test "subWrap single-single, unsigned" {
645645 const wrapped = try a.subWrap(&a, &b, .unsigned, 17);
646646
647647 try testing.expect(wrapped);
648 try testing.expect((try a.toInt(u17)) == 1);
648 try testing.expectEqual(1, try a.toInt(u17));
649649}
650650
651651test "addWrap multi-multi, unsigned, limb aligned" {
......@@ -658,7 +658,7 @@ test "addWrap multi-multi, unsigned, limb aligned" {
658658 const wrapped = try a.addWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));
659659
660660 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));
662662}
663663
664664test "subWrap single-multi, unsigned, limb aligned" {
......@@ -671,7 +671,7 @@ test "subWrap single-multi, unsigned, limb aligned" {
671671 const wrapped = try a.subWrap(&a, &b, .unsigned, @bitSizeOf(DoubleLimb));
672672
673673 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));
675675}
676676
677677test "addWrap single-single, signed" {
......@@ -684,7 +684,7 @@ test "addWrap single-single, signed" {
684684 const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(i21));
685685
686686 try testing.expect(wrapped);
687 try testing.expect((try a.toInt(i21)) == minInt(i21));
687 try testing.expectEqual(minInt(i21), try a.toInt(i21));
688688}
689689
690690test "subWrap single-single, signed" {
......@@ -697,7 +697,7 @@ test "subWrap single-single, signed" {
697697 const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(i21));
698698
699699 try testing.expect(wrapped);
700 try testing.expect((try a.toInt(i21)) == maxInt(i21));
700 try testing.expectEqual(maxInt(i21), try a.toInt(i21));
701701}
702702
703703test "addWrap multi-multi, signed, limb aligned" {
......@@ -710,7 +710,7 @@ test "addWrap multi-multi, signed, limb aligned" {
710710 const wrapped = try a.addWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));
711711
712712 try testing.expect(wrapped);
713 try testing.expect((try a.toInt(SignedDoubleLimb)) == -2);
713 try testing.expectEqual(-2, try a.toInt(SignedDoubleLimb));
714714}
715715
716716test "subWrap single-multi, signed, limb aligned" {
......@@ -723,7 +723,7 @@ test "subWrap single-multi, signed, limb aligned" {
723723 const wrapped = try a.subWrap(&a, &b, .signed, @bitSizeOf(SignedDoubleLimb));
724724
725725 try testing.expect(wrapped);
726 try testing.expect((try a.toInt(SignedDoubleLimb)) == maxInt(SignedDoubleLimb));
726 try testing.expectEqual(maxInt(SignedDoubleLimb), try a.toInt(SignedDoubleLimb));
727727}
728728
729729test "addWrap returns normalized result" {
......@@ -763,7 +763,7 @@ test "addSat single-single, unsigned" {
763763
764764 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));
767767}
768768
769769test "subSat single-single, unsigned" {
......@@ -775,7 +775,7 @@ test "subSat single-single, unsigned" {
775775
776776 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));
779779}
780780
781781test "addSat multi-multi, unsigned, limb aligned" {
......@@ -787,7 +787,7 @@ test "addSat multi-multi, unsigned, limb aligned" {
787787
788788 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));
791791}
792792
793793test "subSat single-multi, unsigned, limb aligned" {
......@@ -799,7 +799,7 @@ test "subSat single-multi, unsigned, limb aligned" {
799799
800800 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));
803803}
804804
805805test "addSat single-single, signed" {
......@@ -811,7 +811,7 @@ test "addSat single-single, signed" {
811811
812812 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));
815815}
816816
817817test "subSat single-single, signed" {
......@@ -823,7 +823,7 @@ test "subSat single-single, signed" {
823823
824824 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));
827827}
828828
829829test "addSat multi-multi, signed, limb aligned" {
......@@ -835,7 +835,7 @@ test "addSat multi-multi, signed, limb aligned" {
835835
836836 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));
839839}
840840
841841test "subSat single-multi, signed, limb aligned" {
......@@ -847,7 +847,7 @@ test "subSat single-multi, signed, limb aligned" {
847847
848848 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));
851851}
852852
853853test "sub single-single" {
......@@ -860,7 +860,7 @@ test "sub single-single" {
860860 defer c.deinit();
861861 try c.sub(&a, &b);
862862
863 try testing.expect((try c.toInt(u32)) == 45);
863 try testing.expectEqual(45, try c.toInt(u32));
864864}
865865
866866test "sub multi-single" {
......@@ -873,7 +873,7 @@ test "sub multi-single" {
873873 defer c.deinit();
874874 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));
877877}
878878
879879test "sub multi-multi" {
......@@ -890,7 +890,7 @@ test "sub multi-multi" {
890890 defer c.deinit();
891891 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));
894894}
895895
896896test "sub equal" {
......@@ -903,7 +903,7 @@ test "sub equal" {
903903 defer c.deinit();
904904 try c.sub(&a, &b);
905905
906 try testing.expect((try c.toInt(u32)) == 0);
906 try testing.expectEqual(0, try c.toInt(u32));
907907}
908908
909909test "sub sign" {
......@@ -920,19 +920,19 @@ test "sub sign" {
920920 defer neg_two.deinit();
921921
922922 try a.sub(&one, &two);
923 try testing.expect((try a.toInt(i32)) == -1);
923 try testing.expectEqual(-1, try a.toInt(i32));
924924
925925 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
928928 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
931931 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
934934 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));
936936}
937937
938938test "mul single-single" {
......@@ -945,7 +945,7 @@ test "mul single-single" {
945945 defer c.deinit();
946946 try c.mul(&a, &b);
947947
948 try testing.expect((try c.toInt(u64)) == 250);
948 try testing.expectEqual(250, try c.toInt(u64));
949949}
950950
951951test "mul multi-single" {
......@@ -958,7 +958,7 @@ test "mul multi-single" {
958958 defer c.deinit();
959959 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));
962962}
963963
964964test "mul multi-multi" {
......@@ -977,7 +977,7 @@ test "mul multi-multi" {
977977 defer c.deinit();
978978 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));
981981}
982982
983983test "mul alias r with a" {
......@@ -988,7 +988,7 @@ test "mul alias r with a" {
988988
989989 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));
992992}
993993
994994test "mul alias r with b" {
......@@ -999,7 +999,7 @@ test "mul alias r with b" {
999999
10001000 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));
10031003}
10041004
10051005test "mul alias r with a and b" {
......@@ -1008,7 +1008,7 @@ test "mul alias r with a and b" {
10081008
10091009 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));
10121012}
10131013
10141014test "mul a*0" {
......@@ -1021,7 +1021,7 @@ test "mul a*0" {
10211021 defer c.deinit();
10221022 try c.mul(&a, &b);
10231023
1024 try testing.expect((try c.toInt(u32)) == 0);
1024 try testing.expectEqual(0, try c.toInt(u32));
10251025}
10261026
10271027test "mul 0*0" {
......@@ -1034,7 +1034,7 @@ test "mul 0*0" {
10341034 defer c.deinit();
10351035 try c.mul(&a, &b);
10361036
1037 try testing.expect((try c.toInt(u32)) == 0);
1037 try testing.expectEqual(0, try c.toInt(u32));
10381038}
10391039
10401040test "mul large" {
......@@ -1068,7 +1068,7 @@ test "mulWrap single-single unsigned" {
10681068 defer c.deinit();
10691069 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));
10721072}
10731073
10741074test "mulWrap single-single signed" {
......@@ -1081,7 +1081,7 @@ test "mulWrap single-single signed" {
10811081 defer c.deinit();
10821082 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));
10851085}
10861086
10871087test "mulWrap multi-multi unsigned" {
......@@ -1100,7 +1100,7 @@ test "mulWrap multi-multi unsigned" {
11001100 defer c.deinit();
11011101 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));
11041104}
11051105
11061106test "mulWrap multi-multi signed" {
......@@ -1118,7 +1118,7 @@ test "mulWrap multi-multi signed" {
11181118 defer c.deinit();
11191119 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));
11221122}
11231123
11241124test "mulWrap large" {
......@@ -1157,8 +1157,8 @@ test "div single-half no rem" {
11571157 defer r.deinit();
11581158 try Managed.divTrunc(&q, &r, &a, &b);
11591159
1160 try testing.expect((try q.toInt(u32)) == 10);
1161 try testing.expect((try r.toInt(u32)) == 0);
1160 try testing.expectEqual(10, try q.toInt(u32));
1161 try testing.expectEqual(0, try r.toInt(u32));
11621162}
11631163
11641164test "div single-half with rem" {
......@@ -1173,8 +1173,8 @@ test "div single-half with rem" {
11731173 defer r.deinit();
11741174 try Managed.divTrunc(&q, &r, &a, &b);
11751175
1176 try testing.expect((try q.toInt(u32)) == 9);
1177 try testing.expect((try r.toInt(u32)) == 4);
1176 try testing.expectEqual(9, try q.toInt(u32));
1177 try testing.expectEqual(4, try r.toInt(u32));
11781178}
11791179
11801180test "div single-single no rem" {
......@@ -1190,8 +1190,8 @@ test "div single-single no rem" {
11901190 defer r.deinit();
11911191 try Managed.divTrunc(&q, &r, &a, &b);
11921192
1193 try testing.expect((try q.toInt(u32)) == 131072);
1194 try testing.expect((try r.toInt(u32)) == 0);
1193 try testing.expectEqual(131072, try q.toInt(u32));
1194 try testing.expectEqual(0, try r.toInt(u32));
11951195}
11961196
11971197test "div single-single with rem" {
......@@ -1206,8 +1206,8 @@ test "div single-single with rem" {
12061206 defer r.deinit();
12071207 try Managed.divTrunc(&q, &r, &a, &b);
12081208
1209 try testing.expect((try q.toInt(u64)) == 131072);
1210 try testing.expect((try r.toInt(u64)) == 8589934592);
1209 try testing.expectEqual(131072, try q.toInt(u64));
1210 try testing.expectEqual(8589934592, try r.toInt(u64));
12111211}
12121212
12131213test "div multi-single no rem" {
......@@ -1226,8 +1226,8 @@ test "div multi-single no rem" {
12261226 defer r.deinit();
12271227 try Managed.divTrunc(&q, &r, &a, &b);
12281228
1229 try testing.expect((try q.toInt(u64)) == op1 / op2);
1230 try testing.expect((try r.toInt(u64)) == 0);
1229 try testing.expectEqual(op1 / op2, try q.toInt(u64));
1230 try testing.expectEqual(0, try r.toInt(u64));
12311231}
12321232
12331233test "div multi-single with rem" {
......@@ -1246,8 +1246,8 @@ test "div multi-single with rem" {
12461246 defer r.deinit();
12471247 try Managed.divTrunc(&q, &r, &a, &b);
12481248
1249 try testing.expect((try q.toInt(u64)) == op1 / op2);
1250 try testing.expect((try r.toInt(u64)) == 3);
1249 try testing.expectEqual(op1 / op2, try q.toInt(u64));
1250 try testing.expectEqual(3, try r.toInt(u64));
12511251}
12521252
12531253test "div multi>2-single" {
......@@ -1266,8 +1266,8 @@ test "div multi>2-single" {
12661266 defer r.deinit();
12671267 try Managed.divTrunc(&q, &r, &a, &b);
12681268
1269 try testing.expect((try q.toInt(u128)) == op1 / op2);
1270 try testing.expect((try r.toInt(u32)) == 0x3e4e);
1269 try testing.expectEqual(op1 / op2, try q.toInt(u128));
1270 try testing.expectEqual(0x3e4e, try r.toInt(u32));
12711271}
12721272
12731273test "div single-single q < r" {
......@@ -1282,8 +1282,8 @@ test "div single-single q < r" {
12821282 defer r.deinit();
12831283 try Managed.divTrunc(&q, &r, &a, &b);
12841284
1285 try testing.expect((try q.toInt(u64)) == 0);
1286 try testing.expect((try r.toInt(u64)) == 0x0078f432);
1285 try testing.expectEqual(0, try q.toInt(u64));
1286 try testing.expectEqual(0x0078f432, try r.toInt(u64));
12871287}
12881288
12891289test "div single-single q == r" {
......@@ -1298,8 +1298,8 @@ test "div single-single q == r" {
12981298 defer r.deinit();
12991299 try Managed.divTrunc(&q, &r, &a, &b);
13001300
1301 try testing.expect((try q.toInt(u64)) == 1);
1302 try testing.expect((try r.toInt(u64)) == 0);
1301 try testing.expectEqual(1, try q.toInt(u64));
1302 try testing.expectEqual(0, try r.toInt(u64));
13031303}
13041304
13051305test "div q=0 alias" {
......@@ -1310,8 +1310,8 @@ test "div q=0 alias" {
13101310
13111311 try Managed.divTrunc(&a, &b, &a, &b);
13121312
1313 try testing.expect((try a.toInt(u64)) == 0);
1314 try testing.expect((try b.toInt(u64)) == 3);
1313 try testing.expectEqual(0, try a.toInt(u64));
1314 try testing.expectEqual(3, try b.toInt(u64));
13151315}
13161316
13171317test "div multi-multi q < r" {
......@@ -1330,8 +1330,8 @@ test "div multi-multi q < r" {
13301330 defer r.deinit();
13311331 try Managed.divTrunc(&q, &r, &a, &b);
13321332
1333 try testing.expect((try q.toInt(u128)) == 0);
1334 try testing.expect((try r.toInt(u128)) == op1);
1333 try testing.expectEqual(0, try q.toInt(u128));
1334 try testing.expectEqual(op1, try r.toInt(u128));
13351335}
13361336
13371337test "div trunc single-single +/+" {
......@@ -1354,8 +1354,8 @@ test "div trunc single-single +/+" {
13541354 const eq = @divTrunc(u, v);
13551355 const er = @mod(u, v);
13561356
1357 try testing.expect((try q.toInt(i32)) == eq);
1358 try testing.expect((try r.toInt(i32)) == er);
1357 try testing.expectEqual(eq, try q.toInt(i32));
1358 try testing.expectEqual(er, try r.toInt(i32));
13591359}
13601360
13611361test "div trunc single-single -/+" {
......@@ -1378,8 +1378,8 @@ test "div trunc single-single -/+" {
13781378 const eq = -1;
13791379 const er = -2;
13801380
1381 try testing.expect((try q.toInt(i32)) == eq);
1382 try testing.expect((try r.toInt(i32)) == er);
1381 try testing.expectEqual(eq, try q.toInt(i32));
1382 try testing.expectEqual(er, try r.toInt(i32));
13831383}
13841384
13851385test "div trunc single-single +/-" {
......@@ -1402,8 +1402,8 @@ test "div trunc single-single +/-" {
14021402 const eq = -1;
14031403 const er = 2;
14041404
1405 try testing.expect((try q.toInt(i32)) == eq);
1406 try testing.expect((try r.toInt(i32)) == er);
1405 try testing.expectEqual(eq, try q.toInt(i32));
1406 try testing.expectEqual(er, try r.toInt(i32));
14071407}
14081408
14091409test "div trunc single-single -/-" {
......@@ -1426,8 +1426,8 @@ test "div trunc single-single -/-" {
14261426 const eq = 1;
14271427 const er = -2;
14281428
1429 try testing.expect((try q.toInt(i32)) == eq);
1430 try testing.expect((try r.toInt(i32)) == er);
1429 try testing.expectEqual(eq, try q.toInt(i32));
1430 try testing.expectEqual(er, try r.toInt(i32));
14311431}
14321432
14331433test "divTrunc #15535" {
......@@ -1440,7 +1440,7 @@ test "divTrunc #15535" {
14401440 var q = try Managed.init(testing.allocator);
14411441 defer q.deinit();
14421442 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));
14441444}
14451445
14461446test "divFloor #10932" {
......@@ -1463,8 +1463,8 @@ test "divFloor #10932" {
14631463
14641464 const ress = try res.toString(testing.allocator, 16, .lower);
14651465 defer testing.allocator.free(ress);
1466 try testing.expect(std.mem.eql(u8, ress, "194bd136316c046d070b763396297bf8869a605030216b52597015902a172b2a752f62af1568dcd431602f03725bfa62b0be71ae86616210972c0126e173503011ca48c5747ff066d159c95e46b69cbb14c8fc0bd2bf0919f921be96463200000000000000000000000000000000000000000000000000000000000000000000000000000000"));
1467 try testing.expect((try mod.toInt(i32)) == 0);
1466 try testing.expectEqualStrings("194bd136316c046d070b763396297bf8869a605030216b52597015902a172b2a752f62af1568dcd431602f03725bfa62b0be71ae86616210972c0126e173503011ca48c5747ff066d159c95e46b69cbb14c8fc0bd2bf0919f921be96463200000000000000000000000000000000000000000000000000000000000000000000000000000000", ress);
1467 try testing.expectEqual(0, try mod.toInt(i32));
14681468}
14691469
14701470test "divFloor #11166" {
......@@ -1487,11 +1487,11 @@ test "divFloor #11166" {
14871487
14881488 const ress = try res.toString(testing.allocator, 10, .lower);
14891489 defer testing.allocator.free(ress);
1490 try testing.expect(std.mem.eql(u8, ress, "1000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
1490 try testing.expectEqualStrings("1000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", ress);
14911491
14921492 const mods = try mod.toString(testing.allocator, 10, .lower);
14931493 defer testing.allocator.free(mods);
1494 try testing.expect(std.mem.eql(u8, mods, "870000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
1494 try testing.expectEqualStrings("870000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", mods);
14951495}
14961496
14971497test "gcd #10932" {
......@@ -1511,7 +1511,7 @@ test "gcd #10932" {
15111511
15121512 const ress = try res.toString(testing.allocator, 16, .lower);
15131513 defer testing.allocator.free(ress);
1514 try testing.expect(std.mem.eql(u8, ress, "1a974a5c9734476ff5a3604bcc678a756beacfc21b4427d1f2c1f56f5d4e411a162c56136e20000000000000000000000000000000"));
1514 try testing.expectEqualStrings("1a974a5c9734476ff5a3604bcc678a756beacfc21b4427d1f2c1f56f5d4e411a162c56136e20000000000000000000000000000000", ress);
15151515}
15161516
15171517test "bitAnd #10932" {
......@@ -1529,7 +1529,7 @@ test "bitAnd #10932" {
15291529
15301530 try res.bitAnd(&a, &b);
15311531
1532 try testing.expect((try res.toInt(i32)) == 0);
1532 try testing.expectEqual(0, try res.toInt(i32));
15331533}
15341534
15351535test "bit And #19235" {
......@@ -1542,7 +1542,7 @@ test "bit And #19235" {
15421542
15431543 try r.bitAnd(&a, &b);
15441544
1545 try testing.expect((try r.toInt(i128)) == 0x10000000000000000);
1545 try testing.expectEqual(0x10000000000000000, try r.toInt(i128));
15461546}
15471547
15481548test "div floor single-single +/+" {
......@@ -1565,8 +1565,8 @@ test "div floor single-single +/+" {
15651565 const eq = 1;
15661566 const er = 2;
15671567
1568 try testing.expect((try q.toInt(i32)) == eq);
1569 try testing.expect((try r.toInt(i32)) == er);
1568 try testing.expectEqual(eq, try q.toInt(i32));
1569 try testing.expectEqual(er, try r.toInt(i32));
15701570}
15711571
15721572test "div floor single-single -/+" {
......@@ -1589,8 +1589,8 @@ test "div floor single-single -/+" {
15891589 const eq = -2;
15901590 const er = 1;
15911591
1592 try testing.expect((try q.toInt(i32)) == eq);
1593 try testing.expect((try r.toInt(i32)) == er);
1592 try testing.expectEqual(eq, try q.toInt(i32));
1593 try testing.expectEqual(er, try r.toInt(i32));
15941594}
15951595
15961596test "div floor single-single +/-" {
......@@ -1613,8 +1613,8 @@ test "div floor single-single +/-" {
16131613 const eq = -2;
16141614 const er = -1;
16151615
1616 try testing.expect((try q.toInt(i32)) == eq);
1617 try testing.expect((try r.toInt(i32)) == er);
1616 try testing.expectEqual(eq, try q.toInt(i32));
1617 try testing.expectEqual(er, try r.toInt(i32));
16181618}
16191619
16201620test "div floor single-single -/-" {
......@@ -1637,8 +1637,8 @@ test "div floor single-single -/-" {
16371637 const eq = 1;
16381638 const er = -2;
16391639
1640 try testing.expect((try q.toInt(i32)) == eq);
1641 try testing.expect((try r.toInt(i32)) == er);
1640 try testing.expectEqual(eq, try q.toInt(i32));
1641 try testing.expectEqual(er, try r.toInt(i32));
16421642}
16431643
16441644test "div floor no remainder negative quotient" {
......@@ -1656,8 +1656,8 @@ test "div floor no remainder negative quotient" {
16561656 defer r.deinit();
16571657 try Managed.divFloor(&q, &r, &a, &b);
16581658
1659 try testing.expect((try q.toInt(i32)) == -0x80000000);
1660 try testing.expect((try r.toInt(i32)) == 0);
1659 try testing.expectEqual(-0x80000000, try q.toInt(i32));
1660 try testing.expectEqual(0, try r.toInt(i32));
16611661}
16621662
16631663test "div floor negative close to zero" {
......@@ -1675,8 +1675,8 @@ test "div floor negative close to zero" {
16751675 defer r.deinit();
16761676 try Managed.divFloor(&q, &r, &a, &b);
16771677
1678 try testing.expect((try q.toInt(i32)) == -1);
1679 try testing.expect((try r.toInt(i32)) == 10);
1678 try testing.expectEqual(-1, try q.toInt(i32));
1679 try testing.expectEqual(10, try r.toInt(i32));
16801680}
16811681
16821682test "div floor positive close to zero" {
......@@ -1694,8 +1694,8 @@ test "div floor positive close to zero" {
16941694 defer r.deinit();
16951695 try Managed.divFloor(&q, &r, &a, &b);
16961696
1697 try testing.expect((try q.toInt(i32)) == 0);
1698 try testing.expect((try r.toInt(i32)) == 10);
1697 try testing.expectEqual(0, try q.toInt(i32));
1698 try testing.expectEqual(10, try r.toInt(i32));
16991699}
17001700
17011701test "div multi-multi with rem" {
......@@ -1712,8 +1712,8 @@ test "div multi-multi with rem" {
17121712 defer r.deinit();
17131713 try Managed.divTrunc(&q, &r, &a, &b);
17141714
1715 try testing.expect((try q.toInt(u128)) == 0xe38f38e39161aaabd03f0f1b);
1716 try testing.expect((try r.toInt(u128)) == 0x28de0acacd806823638);
1715 try testing.expectEqual(0xe38f38e39161aaabd03f0f1b, try q.toInt(u128));
1716 try testing.expectEqual(0x28de0acacd806823638, try r.toInt(u128));
17171717}
17181718
17191719test "div multi-multi no rem" {
......@@ -1730,8 +1730,8 @@ test "div multi-multi no rem" {
17301730 defer r.deinit();
17311731 try Managed.divTrunc(&q, &r, &a, &b);
17321732
1733 try testing.expect((try q.toInt(u128)) == 0xe38f38e39161aaabd03f0f1b);
1734 try testing.expect((try r.toInt(u128)) == 0);
1733 try testing.expectEqual(0xe38f38e39161aaabd03f0f1b, try q.toInt(u128));
1734 try testing.expectEqual(0, try r.toInt(u128));
17351735}
17361736
17371737test "div multi-multi (2 branch)" {
......@@ -1748,8 +1748,8 @@ test "div multi-multi (2 branch)" {
17481748 defer r.deinit();
17491749 try Managed.divTrunc(&q, &r, &a, &b);
17501750
1751 try testing.expect((try q.toInt(u128)) == 0x10000000000000000);
1752 try testing.expect((try r.toInt(u128)) == 0x44444443444444431111111111111111);
1751 try testing.expectEqual(0x10000000000000000, try q.toInt(u128));
1752 try testing.expectEqual(0x44444443444444431111111111111111, try r.toInt(u128));
17531753}
17541754
17551755test "div multi-multi (3.1/3.3 branch)" {
......@@ -1766,8 +1766,8 @@ test "div multi-multi (3.1/3.3 branch)" {
17661766 defer r.deinit();
17671767 try Managed.divTrunc(&q, &r, &a, &b);
17681768
1769 try testing.expect((try q.toInt(u128)) == 0xfffffffffffffffffff);
1770 try testing.expect((try r.toInt(u256)) == 0x1111111111111111111110b12222222222222222282);
1769 try testing.expectEqual(0xfffffffffffffffffff, try q.toInt(u128));
1770 try testing.expectEqual(0x1111111111111111111110b12222222222222222282, try r.toInt(u256));
17711771}
17721772
17731773test "div multi-single zero-limb trailing" {
......@@ -1804,11 +1804,11 @@ test "div multi-multi zero-limb trailing (with rem)" {
18041804 defer r.deinit();
18051805 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
18091809 const rs = try r.toString(testing.allocator, 16, .lower);
18101810 defer testing.allocator.free(rs);
1811 try testing.expect(std.mem.eql(u8, rs, "4444444344444443111111111111111100000000000000000000000000000000"));
1811 try testing.expectEqualStrings("4444444344444443111111111111111100000000000000000000000000000000", rs);
18121812}
18131813
18141814test "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
18251825 defer r.deinit();
18261826 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
18301830 const rs = try r.toString(testing.allocator, 16, .lower);
18311831 defer testing.allocator.free(rs);
1832 try testing.expect(std.mem.eql(u8, rs, "444444434444444311111111111111110000000000000000"));
1832 try testing.expectEqualStrings("444444434444444311111111111111110000000000000000", rs);
18331833}
18341834
18351835test "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
18481848
18491849 const qs = try q.toString(testing.allocator, 16, .lower);
18501850 defer testing.allocator.free(qs);
1851 try testing.expect(std.mem.eql(u8, qs, "10000000000000000820820803105186f"));
1851 try testing.expectEqualStrings("10000000000000000820820803105186f", qs);
18521852
18531853 const rs = try r.toString(testing.allocator, 16, .lower);
18541854 defer testing.allocator.free(rs);
1855 try testing.expect(std.mem.eql(u8, rs, "4e11f2baa5896a321d463b543d0104e30000000000000000"));
1855 try testing.expectEqualStrings("4e11f2baa5896a321d463b543d0104e30000000000000000", rs);
18561856}
18571857
18581858test "div multi-multi fuzz case #1" {
......@@ -1872,11 +1872,11 @@ test "div multi-multi fuzz case #1" {
18721872
18731873 const qs = try q.toString(testing.allocator, 16, .lower);
18741874 defer testing.allocator.free(qs);
1875 try testing.expect(std.mem.eql(u8, qs, "3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1"));
1875 try testing.expectEqualStrings("3ffffffffffffffffffffffffffff0000000000000000000000000000000000001ffffffffffffffffffffffffffff7fffffffe000000000000000000000000000180000000000000000000003fffffbfffffffdfffffffffffffeffff800000100101000000100000000020003fffffdfbfffffe3ffffffffffffeffff7fffc00800a100000017ffe000002000400007efbfff7fe9f00000037ffff3fff7fffa004006100000009ffe00000190038200bf7d2ff7fefe80400060000f7d7f8fbf9401fe38e0403ffc0bdffffa51102c300d7be5ef9df4e5060007b0127ad3fa69f97d0f820b6605ff617ddf7f32ad7a05c0d03f2e7bc78a6000e087a8bbcdc59e07a5a079128a7861f553ddebed7e8e56701756f9ead39b48cd1b0831889ea6ec1fddf643d0565b075ff07e6caea4e2854ec9227fd635ed60a2f5eef2893052ffd54718fa08604acbf6a15e78a467c4a3c53c0278af06c4416573f925491b195e8fd79302cb1aaf7caf4ecfc9aec1254cc969786363ac729f914c6ddcc26738d6b0facd54eba026580aba2eb6482a088b0d224a8852420b91ec1", qs);
18761876
18771877 const rs = try r.toString(testing.allocator, 16, .lower);
18781878 defer testing.allocator.free(rs);
1879 try testing.expect(std.mem.eql(u8, rs, "310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1"));
1879 try testing.expectEqualStrings("310d1d4c414426b4836c2635bad1df3a424e50cbdd167ffccb4dfff57d36b4aae0d6ca0910698220171a0f3373c1060a046c2812f0027e321f72979daa5e7973214170d49e885de0c0ecc167837d44502430674a82522e5df6a0759548052420b91ec1", rs);
18801880}
18811881
18821882test "div multi-multi fuzz case #2" {
......@@ -1896,11 +1896,11 @@ test "div multi-multi fuzz case #2" {
18961896
18971897 const qs = try q.toString(testing.allocator, 16, .lower);
18981898 defer testing.allocator.free(qs);
1899 try testing.expect(std.mem.eql(u8, qs, "40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4"));
1899 try testing.expectEqualStrings("40100400fe3f8fe3f8fe3f8fe3f8fe3f8fe4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f93e4f91e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4992649926499264991e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4791e4792e4b92e4b92e4b92e4b92a4a92a4a92a4", qs);
19001900
19011901 const rs = try r.toString(testing.allocator, 16, .lower);
19021902 defer testing.allocator.free(rs);
1903 try testing.expect(std.mem.eql(u8, rs, "a900000000000000000000000000000000000000000000000000"));
1903 try testing.expectEqualStrings("a900000000000000000000000000000000000000000000000000", rs);
19041904}
19051905
19061906test "truncate single unsigned" {
......@@ -1909,7 +1909,7 @@ test "truncate single unsigned" {
19091909
19101910 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));
19131913}
19141914
19151915test "truncate single signed" {
......@@ -1918,7 +1918,7 @@ test "truncate single signed" {
19181918
19191919 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));
19221922}
19231923
19241924test "truncate multi to single unsigned" {
......@@ -1927,7 +1927,7 @@ test "truncate multi to single unsigned" {
19271927
19281928 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));
19311931}
19321932
19331933test "truncate multi to single signed" {
......@@ -1936,7 +1936,7 @@ test "truncate multi to single signed" {
19361936
19371937 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));
19401940}
19411941
19421942test "truncate multi to multi unsigned" {
......@@ -1948,7 +1948,7 @@ test "truncate multi to multi unsigned" {
19481948
19491949 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));
19521952}
19531953
19541954test "truncate multi to multi signed" {
......@@ -1957,7 +1957,7 @@ test "truncate multi to multi signed" {
19571957
19581958 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)));
19611961}
19621962
19631963test "truncate negative multi to single" {
......@@ -1966,7 +1966,7 @@ test "truncate negative multi to single" {
19661966
19671967 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));
19701970}
19711971
19721972test "truncate multi unsigned many" {
......@@ -1978,7 +1978,7 @@ test "truncate multi unsigned many" {
19781978 defer b.deinit();
19791979 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));
19821982}
19831983
19841984test "truncate to mutable with fewer limbs" {
......@@ -2067,7 +2067,7 @@ test "saturate single signed positive" {
20672067
20682068 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));
20712071}
20722072
20732073test "saturate single signed negative" {
......@@ -2076,7 +2076,7 @@ test "saturate single signed negative" {
20762076
20772077 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));
20802080}
20812081
20822082test "saturate single signed" {
......@@ -2085,7 +2085,7 @@ test "saturate single signed" {
20852085
20862086 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));
20892089}
20902090
20912091test "saturate multi signed" {
......@@ -2094,7 +2094,7 @@ test "saturate multi signed" {
20942094
20952095 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));
20982098}
20992099
21002100test "saturate single unsigned" {
......@@ -2103,7 +2103,7 @@ test "saturate single unsigned" {
21032103
21042104 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));
21072107}
21082108
21092109test "saturate multi unsigned zero" {
......@@ -2121,7 +2121,7 @@ test "saturate multi unsigned" {
21212121
21222122 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));
21252125}
21262126
21272127test "shift-right single" {
......@@ -2129,7 +2129,7 @@ test "shift-right single" {
21292129 defer a.deinit();
21302130 try a.shiftRight(&a, 16);
21312131
2132 try testing.expect((try a.toInt(u32)) == 0xffff);
2132 try testing.expectEqual(0xffff, try a.toInt(u32));
21332133}
21342134
21352135test "shift-right multi" {
......@@ -2137,7 +2137,7 @@ test "shift-right multi" {
21372137 defer a.deinit();
21382138 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
21422142 try a.set(0xffff0000eeee1111dddd2222cccc3333);
21432143 try a.shiftRight(&a, 63);
......@@ -2154,8 +2154,8 @@ test "shift-right multi" {
21542154 );
21552155 defer testing.allocator.free(string);
21562156 try std.testing.expectEqualStrings(
2157 string,
21582157 "ffff0000eeee1111dddd2222cccc3333",
2158 string,
21592159 );
21602160}
21612161
......@@ -2164,7 +2164,7 @@ test "shift-left single" {
21642164 defer a.deinit();
21652165 try a.shiftLeft(&a, 16);
21662166
2167 try testing.expect((try a.toInt(u64)) == 0xffff0000);
2167 try testing.expectEqual(0xffff0000, try a.toInt(u64));
21682168}
21692169
21702170test "shift-left multi" {
......@@ -2172,7 +2172,7 @@ test "shift-left multi" {
21722172 defer a.deinit();
21732173 try a.shiftLeft(&a, 67);
21742174
2175 try testing.expect((try a.toInt(u128)) == 0xffff0000eeee11100000000000000000);
2175 try testing.expectEqual(0xffff0000eeee11100000000000000000, try a.toInt(u128));
21762176}
21772177
21782178test "shift-right negative" {
......@@ -2182,43 +2182,43 @@ test "shift-right negative" {
21822182 var arg = try Managed.initSet(testing.allocator, -20);
21832183 defer arg.deinit();
21842184 try a.shiftRight(&arg, 2);
2185 try testing.expect((try a.toInt(i32)) == -5); // -20 >> 2 == -5
2185 try testing.expectEqual(-5, try a.toInt(i32)); // -20 >> 2 == -5
21862186
21872187 var arg2 = try Managed.initSet(testing.allocator, -5);
21882188 defer arg2.deinit();
21892189 try a.shiftRight(&arg2, 10);
2190 try testing.expect((try a.toInt(i32)) == -1); // -5 >> 10 == -1
2190 try testing.expectEqual(-1, try a.toInt(i32)); // -5 >> 10 == -1
21912191
21922192 var arg3 = try Managed.initSet(testing.allocator, -10);
21932193 defer arg3.deinit();
21942194 try a.shiftRight(&arg3, 1232);
2195 try testing.expect((try a.toInt(i32)) == -1); // -10 >> 1232 == -1
2195 try testing.expectEqual(-1, try a.toInt(i32)); // -10 >> 1232 == -1
21962196
21972197 var arg4 = try Managed.initSet(testing.allocator, -5);
21982198 defer arg4.deinit();
21992199 try a.shiftRight(&arg4, 2);
2200 try testing.expect(try a.toInt(i32) == -2); // -5 >> 2 == -2
2200 try testing.expectEqual(-2, try a.toInt(i32)); // -5 >> 2 == -2
22012201
22022202 var arg5 = try Managed.initSet(testing.allocator, -0xffff0000eeee1111dddd2222cccc3333);
22032203 defer arg5.deinit();
22042204 try a.shiftRight(&arg5, 67);
2205 try testing.expect(try a.toInt(i64) == -0x1fffe0001dddc223);
2205 try testing.expectEqual(-0x1fffe0001dddc223, try a.toInt(i64));
22062206
22072207 var arg6 = try Managed.initSet(testing.allocator, -0x1ffffffffffffffff);
22082208 defer arg6.deinit();
22092209 try a.shiftRight(&arg6, 1);
22102210 try a.shiftRight(&a, 1);
22112211 a.setSign(true);
2212 try testing.expect(try a.toInt(u64) == 0x8000000000000000);
2212 try testing.expectEqual(0x8000000000000000, try a.toInt(u64));
22132213
22142214 var arg7 = try Managed.initSet(testing.allocator, -32767);
22152215 defer arg7.deinit();
22162216 a.setSign(false);
22172217 try a.shiftRight(&arg7, 4);
2218 try testing.expect(try a.toInt(i16) == -2048);
2218 try testing.expectEqual(-2048, try a.toInt(i16));
22192219 a.setSign(true);
22202220 try a.shiftRight(&arg7, 4);
2221 try testing.expect(try a.toInt(i16) == -2048);
2221 try testing.expectEqual(-2048, try a.toInt(i16));
22222222
22232223 var arg8_limbs: [1]Limb = undefined;
22242224 var arg8: Mutable = .{
......@@ -2235,7 +2235,7 @@ test "sat shift-left simple unsigned" {
22352235 defer a.deinit();
22362236 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));
22392239}
22402240
22412241test "sat shift-left simple unsigned no sat" {
......@@ -2243,7 +2243,7 @@ test "sat shift-left simple unsigned no sat" {
22432243 defer a.deinit();
22442244 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));
22472247}
22482248
22492249test "sat shift-left multi unsigned" {
......@@ -2251,7 +2251,7 @@ test "sat shift-left multi unsigned" {
22512251 defer a.deinit();
22522252 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));
22552255}
22562256
22572257test "sat shift-left unsigned shift > bitcount" {
......@@ -2259,7 +2259,7 @@ test "sat shift-left unsigned shift > bitcount" {
22592259 defer a.deinit();
22602260 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));
22632263}
22642264
22652265test "sat shift-left unsigned zero" {
......@@ -2267,7 +2267,7 @@ test "sat shift-left unsigned zero" {
22672267 defer a.deinit();
22682268 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));
22712271}
22722272
22732273test "sat shift-left unsigned negative" {
......@@ -2275,7 +2275,7 @@ test "sat shift-left unsigned negative" {
22752275 defer a.deinit();
22762276 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));
22792279}
22802280
22812281test "sat shift-left signed simple negative" {
......@@ -2283,7 +2283,7 @@ test "sat shift-left signed simple negative" {
22832283 defer a.deinit();
22842284 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));
22872287}
22882288
22892289test "sat shift-left signed simple positive" {
......@@ -2291,7 +2291,7 @@ test "sat shift-left signed simple positive" {
22912291 defer a.deinit();
22922292 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));
22952295}
22962296
22972297test "sat shift-left signed multi positive" {
......@@ -2306,7 +2306,7 @@ test "sat shift-left signed multi positive" {
23062306 defer a.deinit();
23072307 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));
23102310}
23112311
23122312test "sat shift-left signed multi negative" {
......@@ -2321,7 +2321,7 @@ test "sat shift-left signed multi negative" {
23212321 defer a.deinit();
23222322 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));
23252325}
23262326
23272327test "bitNotWrap unsigned simple" {
......@@ -2333,7 +2333,7 @@ test "bitNotWrap unsigned simple" {
23332333
23342334 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));
23372337}
23382338
23392339test "bitNotWrap unsigned multi" {
......@@ -2342,7 +2342,7 @@ test "bitNotWrap unsigned multi" {
23422342
23432343 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));
23462346}
23472347
23482348test "bitNotWrap signed simple" {
......@@ -2354,7 +2354,7 @@ test "bitNotWrap signed simple" {
23542354
23552355 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));
23582358}
23592359
23602360test "bitNotWrap signed multi" {
......@@ -2363,7 +2363,7 @@ test "bitNotWrap signed multi" {
23632363
23642364 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));
23672367}
23682368
23692369test "bitNotWrap more than two limbs" {
......@@ -2400,7 +2400,7 @@ test "bitwise and simple" {
24002400
24012401 try a.bitAnd(&a, &b);
24022402
2403 try testing.expect((try a.toInt(u64)) == 0xeeeeeeee00000000);
2403 try testing.expectEqual(0xeeeeeeee00000000, try a.toInt(u64));
24042404}
24052405
24062406test "bitwise and multi-limb" {
......@@ -2411,7 +2411,7 @@ test "bitwise and multi-limb" {
24112411
24122412 try a.bitAnd(&a, &b);
24132413
2414 try testing.expect((try a.toInt(u128)) == 0);
2414 try testing.expectEqual(0, try a.toInt(u128));
24152415}
24162416
24172417test "bitwise and negative-positive simple" {
......@@ -2422,7 +2422,7 @@ test "bitwise and negative-positive simple" {
24222422
24232423 try a.bitAnd(&a, &b);
24242424
2425 try testing.expect((try a.toInt(u64)) == 0x22222222);
2425 try testing.expectEqual(0x22222222, try a.toInt(u64));
24262426}
24272427
24282428test "bitwise and negative-positive multi-limb" {
......@@ -2444,7 +2444,7 @@ test "bitwise and positive-negative simple" {
24442444
24452445 try a.bitAnd(&a, &b);
24462446
2447 try testing.expect((try a.toInt(u64)) == 0x1111111111111110);
2447 try testing.expectEqual(0x1111111111111110, try a.toInt(u64));
24482448}
24492449
24502450test "bitwise and positive-negative multi-limb" {
......@@ -2466,7 +2466,7 @@ test "bitwise and negative-negative simple" {
24662466
24672467 try a.bitAnd(&a, &b);
24682468
2469 try testing.expect((try a.toInt(i128)) == -0xffffffff33333332);
2469 try testing.expectEqual(-0xffffffff33333332, try a.toInt(i128));
24702470}
24712471
24722472test "bitwise and negative-negative multi-limb" {
......@@ -2477,7 +2477,7 @@ test "bitwise and negative-negative multi-limb" {
24772477
24782478 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));
24812481}
24822482
24832483test "bitwise and negative overflow" {
......@@ -2488,7 +2488,7 @@ test "bitwise and negative overflow" {
24882488
24892489 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));
24922492}
24932493
24942494test "bitwise xor simple" {
......@@ -2499,7 +2499,7 @@ test "bitwise xor simple" {
24992499
25002500 try a.bitXor(&a, &b);
25012501
2502 try testing.expect((try a.toInt(u64)) == 0x1111111133333333);
2502 try testing.expectEqual(0x1111111133333333, try a.toInt(u64));
25032503}
25042504
25052505test "bitwise xor multi-limb" {
......@@ -2514,7 +2514,7 @@ test "bitwise xor multi-limb" {
25142514
25152515 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));
25182518}
25192519
25202520test "bitwise xor single negative simple" {
......@@ -2525,7 +2525,7 @@ test "bitwise xor single negative simple" {
25252525
25262526 try a.bitXor(&a, &b);
25272527
2528 try testing.expect((try a.toInt(i64)) == -0x2efed94fcb932ef9);
2528 try testing.expectEqual(-0x2efed94fcb932ef9, try a.toInt(i64));
25292529}
25302530
25312531test "bitwise xor single negative multi-limb" {
......@@ -2536,7 +2536,7 @@ test "bitwise xor single negative multi-limb" {
25362536
25372537 try a.bitXor(&a, &b);
25382538
2539 try testing.expect((try a.toInt(i128)) == -0x6a50889abd8834a24db1f19650d3999a);
2539 try testing.expectEqual(-0x6a50889abd8834a24db1f19650d3999a, try a.toInt(i128));
25402540}
25412541
25422542test "bitwise xor single negative overflow" {
......@@ -2547,7 +2547,7 @@ test "bitwise xor single negative overflow" {
25472547
25482548 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));
25512551}
25522552
25532553test "bitwise xor double negative simple" {
......@@ -2558,7 +2558,7 @@ test "bitwise xor double negative simple" {
25582558
25592559 try a.bitXor(&a, &b);
25602560
2561 try testing.expect((try a.toInt(u64)) == 0xc39c47081a6eb759);
2561 try testing.expectEqual(0xc39c47081a6eb759, try a.toInt(u64));
25622562}
25632563
25642564test "bitwise xor double negative multi-limb" {
......@@ -2569,7 +2569,7 @@ test "bitwise xor double negative multi-limb" {
25692569
25702570 try a.bitXor(&a, &b);
25712571
2572 try testing.expect((try a.toInt(u128)) == 0xa3492ec28e62c410dff92bf0549bf771);
2572 try testing.expectEqual(0xa3492ec28e62c410dff92bf0549bf771, try a.toInt(u128));
25732573}
25742574
25752575test "bitwise or simple" {
......@@ -2580,7 +2580,7 @@ test "bitwise or simple" {
25802580
25812581 try a.bitOr(&a, &b);
25822582
2583 try testing.expect((try a.toInt(u64)) == 0xffffffff33333333);
2583 try testing.expectEqual(0xffffffff33333333, try a.toInt(u64));
25842584}
25852585
25862586test "bitwise or multi-limb" {
......@@ -2591,7 +2591,7 @@ test "bitwise or multi-limb" {
25912591
25922592 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));
25952595}
25962596
25972597test "bitwise or negative-positive simple" {
......@@ -2602,7 +2602,7 @@ test "bitwise or negative-positive simple" {
26022602
26032603 try a.bitOr(&a, &b);
26042604
2605 try testing.expect((try a.toInt(i64)) == -0x1111111111111111);
2605 try testing.expectEqual(-0x1111111111111111, try a.toInt(i64));
26062606}
26072607
26082608test "bitwise or negative-positive multi-limb" {
......@@ -2613,7 +2613,7 @@ test "bitwise or negative-positive multi-limb" {
26132613
26142614 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));
26172617}
26182618
26192619test "bitwise or positive-negative simple" {
......@@ -2624,7 +2624,7 @@ test "bitwise or positive-negative simple" {
26242624
26252625 try a.bitOr(&a, &b);
26262626
2627 try testing.expect((try a.toInt(i64)) == -0x22222221);
2627 try testing.expectEqual(-0x22222221, try a.toInt(i64));
26282628}
26292629
26302630test "bitwise or positive-negative multi-limb" {
......@@ -2635,7 +2635,7 @@ test "bitwise or positive-negative multi-limb" {
26352635
26362636 try a.bitOr(&a, &b);
26372637
2638 try testing.expect((try a.toInt(SignedDoubleLimb)) == -1);
2638 try testing.expectEqual(-1, try a.toInt(SignedDoubleLimb));
26392639}
26402640
26412641test "bitwise or negative-negative simple" {
......@@ -2646,7 +2646,7 @@ test "bitwise or negative-negative simple" {
26462646
26472647 try a.bitOr(&a, &b);
26482648
2649 try testing.expect((try a.toInt(i128)) == -0xeeeeeeee00000001);
2649 try testing.expectEqual(-0xeeeeeeee00000001, try a.toInt(i128));
26502650}
26512651
26522652test "bitwise or negative-negative multi-limb" {
......@@ -2657,7 +2657,7 @@ test "bitwise or negative-negative multi-limb" {
26572657
26582658 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));
26612661}
26622662
26632663test "var args" {
......@@ -2667,11 +2667,11 @@ test "var args" {
26672667 var b = try Managed.initSet(testing.allocator, 6);
26682668 defer b.deinit();
26692669 try a.add(&a, &b);
2670 try testing.expect((try a.toInt(u64)) == 11);
2670 try testing.expectEqual(11, try a.toInt(u64));
26712671
26722672 var c = try Managed.initSet(testing.allocator, 11);
26732673 defer c.deinit();
2674 try testing.expect(a.order(c) == .eq);
2674 try testing.expectEqual(.eq, a.order(c));
26752675
26762676 var d = try Managed.initSet(testing.allocator, 14);
26772677 defer d.deinit();
......@@ -2688,7 +2688,7 @@ test "gcd non-one small" {
26882688
26892689 try r.gcd(&a, &b);
26902690
2691 try testing.expect((try r.toInt(u32)) == 1);
2691 try testing.expectEqual(1, try r.toInt(u32));
26922692}
26932693
26942694test "gcd non-one medium" {
......@@ -2701,7 +2701,7 @@ test "gcd non-one medium" {
27012701
27022702 try r.gcd(&a, &b);
27032703
2704 try testing.expect((try r.toInt(u32)) == 38);
2704 try testing.expectEqual(38, try r.toInt(u32));
27052705}
27062706
27072707test "gcd non-one large" {
......@@ -2714,7 +2714,7 @@ test "gcd non-one large" {
27142714
27152715 try r.gcd(&a, &b);
27162716
2717 try testing.expect((try r.toInt(u32)) == 4369);
2717 try testing.expectEqual(4369, try r.toInt(u32));
27182718}
27192719
27202720test "gcd large multi-limb result" {
......@@ -2730,7 +2730,7 @@ test "gcd large multi-limb result" {
27302730 try r.gcd(&a, &b);
27312731
27322732 const answer = (try r.toInt(u256));
2733 try testing.expect(answer == 0xf000000ff00000fff0000ffff000fffff00ffffff1);
2733 try testing.expectEqual(0xf000000ff00000fff0000ffff000fffff00ffffff1, answer);
27342734}
27352735
27362736test "gcd one large" {
......@@ -2743,7 +2743,7 @@ test "gcd one large" {
27432743
27442744 try r.gcd(&a, &b);
27452745
2746 try testing.expect((try r.toInt(u64)) == 1);
2746 try testing.expectEqual(1, try r.toInt(u64));
27472747}
27482748
27492749test "mutable to managed" {
......@@ -2863,7 +2863,7 @@ test "regression test for 1 limb overflow with alias" {
28632863 try a.ensureAddCapacity(a.toConst(), b.toConst());
28642864 try a.add(&a, &b);
28652865
2866 try testing.expect(a.toConst().orderAgainstScalar(19740274219868223167) == .eq);
2866 try testing.expectEqual(.eq, a.toConst().orderAgainstScalar(19740274219868223167));
28672867}
28682868
28692869test "regression test for realloc with alias" {
......@@ -2877,7 +2877,7 @@ test "regression test for realloc with alias" {
28772877 try a.ensureAddCapacity(a.toConst(), b.toConst());
28782878 try a.add(&a, &b);
28792879
2880 try testing.expect(a.toConst().orderAgainstScalar(14691098406862188148944207245954912110548093601382197697835) == .eq);
2880 try testing.expectEqual(.eq, a.toConst().orderAgainstScalar(14691098406862188148944207245954912110548093601382197697835));
28812881}
28822882
28832883test "big int popcount" {
......@@ -2977,12 +2977,12 @@ test "big int conversion read/write twos complement" {
29772977 // Writing to buffer and back should not change anything
29782978 a.toConst().writeTwosComplement(buffer1[0..abi_size], endian);
29792979 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
29822982 // Equivalent to @bitCast(i493, @as(u493, intMax(u493))
29832983 a.toConst().writeTwosComplement(buffer1[0..abi_size], endian);
29842984 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));
29862986 }
29872987}
29882988
......@@ -3076,19 +3076,19 @@ test "big int conversion write twos complement with padding" {
30763076
30773077 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xb };
30783078 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
30813081 buffer = &[_]u8{ 0xb, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
30823082 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
30853085 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xab, 0xaa, 0xaa, 0xaa };
30863086 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
30893089 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xab, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
30903090 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
30933093 bit_count = @sizeOf(Limb) * 8;
30943094
......@@ -3096,19 +3096,19 @@ test "big int conversion write twos complement with padding" {
30963096
30973097 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa };
30983098 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
31013101 buffer = &[_]u8{ 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
31023102 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
31053105 buffer = &[_]u8{ 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0xaa, 0xaa, 0xaa, 0xaa };
31063106 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
31093109 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0xaa, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd };
31103110 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
31133113 bit_count = 12 * 8 + 2;
31143114
......@@ -3116,42 +3116,42 @@ test "big int conversion write twos complement with padding" {
31163116
31173117 buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02 };
31183118 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
31213121 buffer = &[_]u8{ 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 };
31223122 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
31253125 buffer = &[_]u8{ 0xf3, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0x02, 0xaa, 0xaa, 0xaa };
31263126 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
31293129 buffer = &[_]u8{ 0xaa, 0xaa, 0xaa, 0x02, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf3 };
31303130 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
31333133 // Test 0
31343134
31353135 buffer = &([_]u8{0} ** 16);
31363136 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));
31383138 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));
31403140 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));
31423142 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
31453145 bit_count = 0;
31463146 buffer = &([_]u8{0xaa} ** 16);
31473147 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));
31493149 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));
31513151 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));
31533153 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));
31553155}
31563156
31573157test "big int conversion write twos complement zero" {
......@@ -3170,15 +3170,15 @@ test "big int conversion write twos complement zero" {
31703170
31713171 buffer = &([_]u8{0} ** 13);
31723172 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));
31743174 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
31773177 buffer = &([_]u8{0} ** 16);
31783178 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));
31803180 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));
31823182}
31833183
31843184fn 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
31913191 try a.ensureCapacity(calcTwosCompLimbCount(bit_count));
31923192 var m = a.toMutable();
31933193 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));
31953195}
31963196
31973197test "big int bit reverse" {
......@@ -3238,7 +3238,7 @@ fn byteSwapTest(comptime T: type, comptime input: comptime_int, comptime expecte
32383238 try a.ensureCapacity(calcTwosCompLimbCount(8 * byte_count));
32393239 var m = a.toMutable();
32403240 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));
32423242}
32433243
32443244test "big int byte swap" {
......@@ -3449,111 +3449,111 @@ test "clz" {
34493449 .limbs = &.{ 1, maxInt(Limb) - 1 },
34503450 .positive = false,
34513451 };
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
34543454 const neg_limb_max_squared_plus_one: std.math.big.int.Const = .{
34553455 .limbs = &.{ 0, maxInt(Limb) - 1 },
34563456 .positive = false,
34573457 };
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
34603460 const neg_limb_msb_squared: std.math.big.int.Const = .{
34613461 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
34623462 .positive = false,
34633463 };
3464 try testing.expect(neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2) == 0);
3465 try testing.expect(neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1) == 0);
3464 try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2));
3465 try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1));
34663466
34673467 const neg_limb_max: std.math.big.int.Const = .{
34683468 .limbs = &.{maxInt(Limb)},
34693469 .positive = false,
34703470 };
3471 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) + 1) == 0);
3472 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) * 2 - 1) == 0);
3473 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) * 2) == 0);
3474 try testing.expect(neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1) == 0);
3471 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) + 1));
3472 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 - 1));
3473 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2));
3474 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
34753475
34763476 const neg_limb_msb: std.math.big.int.Const = .{
34773477 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
34783478 .positive = false,
34793479 };
3480 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb)) == 0);
3481 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) + 1) == 0);
3482 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) * 2 - 1) == 0);
3483 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) * 2) == 0);
3484 try testing.expect(neg_limb_msb.clz(@bitSizeOf(Limb) * 2 + 1) == 0);
3480 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb)));
3481 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) + 1));
3482 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) * 2 - 1));
3483 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) * 2));
3484 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb) * 2 + 1));
34853485
34863486 const neg_one: std.math.big.int.Const = .{
34873487 .limbs = &.{1},
34883488 .positive = false,
34893489 };
3490 try testing.expect(neg_one.clz(@bitSizeOf(Limb)) == 0);
3491 try testing.expect(neg_one.clz(@bitSizeOf(Limb) + 1) == 0);
3492 try testing.expect(neg_one.clz(@bitSizeOf(Limb) * 2 - 1) == 0);
3493 try testing.expect(neg_one.clz(@bitSizeOf(Limb) * 2) == 0);
3494 try testing.expect(neg_one.clz(@bitSizeOf(Limb) * 2 + 1) == 0);
3490 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb)));
3491 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) + 1));
3492 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) * 2 - 1));
3493 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) * 2));
3494 try testing.expectEqual(0, neg_one.clz(@bitSizeOf(Limb) * 2 + 1));
34953495
34963496 const zero: std.math.big.int.Const = .{
34973497 .limbs = &.{0},
34983498 .positive = true,
34993499 };
3500 try testing.expect(zero.clz(@bitSizeOf(Limb)) == @bitSizeOf(Limb));
3501 try testing.expect(zero.clz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) + 1);
3502 try testing.expect(zero.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 1);
3503 try testing.expect(zero.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2);
3504 try testing.expect(zero.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2 + 1);
3500 try testing.expectEqual(@bitSizeOf(Limb), zero.clz(@bitSizeOf(Limb)));
3501 try testing.expectEqual(@bitSizeOf(Limb) + 1, zero.clz(@bitSizeOf(Limb) + 1));
3502 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 1, zero.clz(@bitSizeOf(Limb) * 2 - 1));
3503 try testing.expectEqual(@bitSizeOf(Limb) * 2, zero.clz(@bitSizeOf(Limb) * 2));
3504 try testing.expectEqual(@bitSizeOf(Limb) * 2 + 1, zero.clz(@bitSizeOf(Limb) * 2 + 1));
35053505
35063506 const one: std.math.big.int.Const = .{
35073507 .limbs = &.{1},
35083508 .positive = true,
35093509 };
3510 try testing.expect(one.clz(@bitSizeOf(Limb)) == @bitSizeOf(Limb) - 1);
3511 try testing.expect(one.clz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb));
3512 try testing.expect(one.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 2);
3513 try testing.expect(one.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2 - 1);
3514 try testing.expect(one.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2);
3510 try testing.expectEqual(@bitSizeOf(Limb) - 1, one.clz(@bitSizeOf(Limb)));
3511 try testing.expectEqual(@bitSizeOf(Limb), one.clz(@bitSizeOf(Limb) + 1));
3512 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, one.clz(@bitSizeOf(Limb) * 2 - 1));
3513 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 1, one.clz(@bitSizeOf(Limb) * 2));
3514 try testing.expectEqual(@bitSizeOf(Limb) * 2, one.clz(@bitSizeOf(Limb) * 2 + 1));
35153515
35163516 const limb_msb: std.math.big.int.Const = .{
35173517 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
35183518 .positive = true,
35193519 };
3520 try testing.expect(limb_msb.clz(@bitSizeOf(Limb)) == 0);
3521 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) + 1) == 1);
3522 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);
3523 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb));
3524 try testing.expect(limb_msb.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) + 1);
3520 try testing.expectEqual(0, limb_msb.clz(@bitSizeOf(Limb)));
3521 try testing.expectEqual(1, limb_msb.clz(@bitSizeOf(Limb) + 1));
3522 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.clz(@bitSizeOf(Limb) * 2 - 1));
3523 try testing.expectEqual(@bitSizeOf(Limb), limb_msb.clz(@bitSizeOf(Limb) * 2));
3524 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_msb.clz(@bitSizeOf(Limb) * 2 + 1));
35253525
35263526 const limb_max: std.math.big.int.Const = .{
35273527 .limbs = &.{maxInt(Limb)},
35283528 .positive = true,
35293529 };
3530 try testing.expect(limb_max.clz(@bitSizeOf(Limb)) == 0);
3531 try testing.expect(limb_max.clz(@bitSizeOf(Limb) + 1) == 1);
3532 try testing.expect(limb_max.clz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);
3533 try testing.expect(limb_max.clz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb));
3534 try testing.expect(limb_max.clz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) + 1);
3530 try testing.expectEqual(0, limb_max.clz(@bitSizeOf(Limb)));
3531 try testing.expectEqual(1, limb_max.clz(@bitSizeOf(Limb) + 1));
3532 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_max.clz(@bitSizeOf(Limb) * 2 - 1));
3533 try testing.expectEqual(@bitSizeOf(Limb), limb_max.clz(@bitSizeOf(Limb) * 2));
3534 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
35353535
35363536 const limb_msb_squared: std.math.big.int.Const = .{
35373537 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
35383538 .positive = true,
35393539 };
3540 try testing.expect(limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1) == 0);
3541 try testing.expect(limb_msb_squared.clz(@bitSizeOf(Limb) * 2) == 1);
3542 try testing.expect(limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1) == 2);
3540 try testing.expectEqual(0, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1));
3541 try testing.expectEqual(1, limb_msb_squared.clz(@bitSizeOf(Limb) * 2));
3542 try testing.expectEqual(2, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 + 1));
35433543
35443544 const limb_max_squared_minus_one: std.math.big.int.Const = .{
35453545 .limbs = &.{ 0, maxInt(Limb) - 1 },
35463546 .positive = true,
35473547 };
3548 try testing.expect(limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2) == 0);
3549 try testing.expect(limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2 + 1) == 1);
3548 try testing.expectEqual(0, limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2));
3549 try testing.expectEqual(1, limb_max_squared_minus_one.clz(@bitSizeOf(Limb) * 2 + 1));
35503550
35513551 const limb_max_squared: std.math.big.int.Const = .{
35523552 .limbs = &.{ 1, maxInt(Limb) - 1 },
35533553 .positive = true,
35543554 };
3555 try testing.expect(limb_max_squared.clz(@bitSizeOf(Limb) * 2) == 0);
3556 try testing.expect(limb_max_squared.clz(@bitSizeOf(Limb) * 2 + 1) == 1);
3555 try testing.expectEqual(0, limb_max_squared.clz(@bitSizeOf(Limb) * 2));
3556 try testing.expectEqual(1, limb_max_squared.clz(@bitSizeOf(Limb) * 2 + 1));
35573557}
35583558
35593559test "ctz" {
......@@ -3561,109 +3561,109 @@ test "ctz" {
35613561 .limbs = &.{ 1, maxInt(Limb) - 1 },
35623562 .positive = false,
35633563 };
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
35663566 const neg_limb_max_squared_plus_one: std.math.big.int.Const = .{
35673567 .limbs = &.{ 0, maxInt(Limb) - 1 },
35683568 .positive = false,
35693569 };
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
35723572 const neg_limb_msb_squared: std.math.big.int.Const = .{
35733573 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
35743574 .positive = false,
35753575 };
3576 try testing.expect(neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2 - 2);
3577 try testing.expect(neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2 - 2);
3576 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));
3577 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 + 1));
35783578
35793579 const neg_limb_max: std.math.big.int.Const = .{
35803580 .limbs = &.{maxInt(Limb)},
35813581 .positive = false,
35823582 };
3583 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) + 1) == 0);
3584 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);
3585 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) * 2) == 0);
3586 try testing.expect(neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);
3583 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) + 1));
3584 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 - 1));
3585 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2));
3586 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
35873587
35883588 const neg_limb_msb: std.math.big.int.Const = .{
35893589 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
35903590 .positive = false,
35913591 };
3592 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb)) == @bitSizeOf(Limb) - 1);
3593 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) - 1);
3594 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);
3595 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) - 1);
3596 try testing.expect(neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) - 1);
3592 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb)));
3593 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) + 1));
3594 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1));
3595 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) * 2));
3596 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1));
35973597
35983598 const neg_one: std.math.big.int.Const = .{
35993599 .limbs = &.{1},
36003600 .positive = false,
36013601 };
3602 try testing.expect(neg_one.ctz(@bitSizeOf(Limb)) == 0);
3603 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) + 1) == 0);
3604 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);
3605 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) * 2) == 0);
3606 try testing.expect(neg_one.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);
3602 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb)));
3603 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) + 1));
3604 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) * 2 - 1));
3605 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) * 2));
3606 try testing.expectEqual(0, neg_one.ctz(@bitSizeOf(Limb) * 2 + 1));
36073607
36083608 const zero: std.math.big.int.Const = .{
36093609 .limbs = &.{0},
36103610 .positive = true,
36113611 };
3612 try testing.expect(zero.ctz(@bitSizeOf(Limb)) == @bitSizeOf(Limb));
3613 try testing.expect(zero.ctz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) + 1);
3614 try testing.expect(zero.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 1);
3615 try testing.expect(zero.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2);
3616 try testing.expect(zero.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) * 2 + 1);
3612 try testing.expectEqual(@bitSizeOf(Limb), zero.ctz(@bitSizeOf(Limb)));
3613 try testing.expectEqual(@bitSizeOf(Limb) + 1, zero.ctz(@bitSizeOf(Limb) + 1));
3614 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 1, zero.ctz(@bitSizeOf(Limb) * 2 - 1));
3615 try testing.expectEqual(@bitSizeOf(Limb) * 2, zero.ctz(@bitSizeOf(Limb) * 2));
3616 try testing.expectEqual(@bitSizeOf(Limb) * 2 + 1, zero.ctz(@bitSizeOf(Limb) * 2 + 1));
36173617
36183618 const one: std.math.big.int.Const = .{
36193619 .limbs = &.{1},
36203620 .positive = true,
36213621 };
3622 try testing.expect(one.ctz(@bitSizeOf(Limb)) == 0);
3623 try testing.expect(one.ctz(@bitSizeOf(Limb) + 1) == 0);
3624 try testing.expect(one.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);
3625 try testing.expect(one.ctz(@bitSizeOf(Limb) * 2) == 0);
3626 try testing.expect(one.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);
3622 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb)));
3623 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) + 1));
3624 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 - 1));
3625 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2));
3626 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 + 1));
36273627
36283628 const limb_msb: std.math.big.int.Const = .{
36293629 .limbs = &.{1 << @bitSizeOf(Limb) - 1},
36303630 .positive = true,
36313631 };
3632 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb)) == @bitSizeOf(Limb) - 1);
3633 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) + 1) == @bitSizeOf(Limb) - 1);
3634 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) - 1);
3635 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) - 1);
3636 try testing.expect(limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) - 1);
3632 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb)));
3633 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) + 1));
3634 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) * 2 - 1));
3635 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) * 2));
3636 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb) * 2 + 1));
36373637
36383638 const limb_max: std.math.big.int.Const = .{
36393639 .limbs = &.{maxInt(Limb)},
36403640 .positive = true,
36413641 };
3642 try testing.expect(limb_max.ctz(@bitSizeOf(Limb)) == 0);
3643 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) + 1) == 0);
3644 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) * 2 - 1) == 0);
3645 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) * 2) == 0);
3646 try testing.expect(limb_max.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);
3642 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb)));
3643 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) + 1));
3644 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 - 1));
3645 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2));
3646 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
36473647
36483648 const limb_msb_squared: std.math.big.int.Const = .{
36493649 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },
36503650 .positive = true,
36513651 };
3652 try testing.expect(limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 - 1) == @bitSizeOf(Limb) * 2 - 2);
3653 try testing.expect(limb_msb_squared.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) * 2 - 2);
3654 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.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));
3654 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 + 1));
36553655
36563656 const limb_max_squared_minus_one: std.math.big.int.Const = .{
36573657 .limbs = &.{ 0, maxInt(Limb) - 1 },
36583658 .positive = true,
36593659 };
3660 try testing.expect(limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2) == @bitSizeOf(Limb) + 1);
3661 try testing.expect(limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2 + 1) == @bitSizeOf(Limb) + 1);
3660 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2));
3661 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max_squared_minus_one.ctz(@bitSizeOf(Limb) * 2 + 1));
36623662
36633663 const limb_max_squared: std.math.big.int.Const = .{
36643664 .limbs = &.{ 1, maxInt(Limb) - 1 },
36653665 .positive = true,
36663666 };
3667 try testing.expect(limb_max_squared.ctz(@bitSizeOf(Limb) * 2) == 0);
3668 try testing.expect(limb_max_squared.ctz(@bitSizeOf(Limb) * 2 + 1) == 0);
3667 try testing.expectEqual(0, limb_max_squared.ctz(@bitSizeOf(Limb) * 2));
3668 try testing.expectEqual(0, limb_max_squared.ctz(@bitSizeOf(Limb) * 2 + 1));
36693669}