| author | |
| committer | |
| log | 2b8687ba2d575de2dfbf857133121dfb92d00cb6 |
| tree | f20040fca24928dbb60a3362e6859f60846952fe |
| parent | 2583a39fb6f85fa65caba04f202c1654a5e8f3f6 |
All of the std except these few functions call it "eql" instead of "eq".
This has previously tripped me up when I expected the equality check function to be called "eql"
(just like all the rest of the std) instead of "eq".
The motivation is consistency.
If search "eq" on Autodoc, these functions stick out and it looks inconsistent.
I just noticed there are also a few functions spelling it out as "equal" (such as std.mem.allEqual).
Maybe those functions should also spell it "eql" but that can be done in a future PR.8 files changed, 71 insertions(+), 58 deletions(-)
lib/std/math/big/int.zig+47-34| ... | @@ -147,9 +147,12 @@ pub const Mutable = struct { | ... | @@ -147,9 +147,12 @@ pub const Mutable = struct { |
| 147 | }; | 147 | }; |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | // TODO: remove after release of 0.11 | ||
| 151 | pub const eqZero = @compileError("use eqlZero"); | ||
| 152 | |||
| 150 | /// Returns true if `a == 0`. | 153 | /// Returns true if `a == 0`. |
| 151 | pub fn eqZero(self: Mutable) bool { | 154 | pub fn eqlZero(self: Mutable) bool { |
| 152 | return self.toConst().eqZero(); | 155 | return self.toConst().eqlZero(); |
| 153 | } | 156 | } |
| 154 | 157 | ||
| 155 | /// Asserts that the allocator owns the limbs memory. If this is not the case, | 158 | /// Asserts that the allocator owns the limbs memory. If this is not the case, |
| ... | @@ -420,10 +423,10 @@ pub const Mutable = struct { | ... | @@ -420,10 +423,10 @@ pub const Mutable = struct { |
| 420 | /// | 423 | /// |
| 421 | /// Asserts r has enough elements to hold the result. The upper bound is `@max(a.limbs.len, b.limbs.len)`. | 424 | /// Asserts r has enough elements to hold the result. The upper bound is `@max(a.limbs.len, b.limbs.len)`. |
| 422 | fn addCarry(r: *Mutable, a: Const, b: Const) bool { | 425 | fn addCarry(r: *Mutable, a: Const, b: Const) bool { |
| 423 | if (a.eqZero()) { | 426 | if (a.eqlZero()) { |
| 424 | r.copy(b); | 427 | r.copy(b); |
| 425 | return false; | 428 | return false; |
| 426 | } else if (b.eqZero()) { | 429 | } else if (b.eqlZero()) { |
| 427 | r.copy(a); | 430 | r.copy(a); |
| 428 | return false; | 431 | return false; |
| 429 | } else if (a.positive != b.positive) { | 432 | } else if (a.positive != b.positive) { |
| ... | @@ -556,11 +559,11 @@ pub const Mutable = struct { | ... | @@ -556,11 +559,11 @@ pub const Mutable = struct { |
| 556 | /// | 559 | /// |
| 557 | /// Asserts r has enough elements to hold the result. The upper bound is `@max(a.limbs.len, b.limbs.len)`. | 560 | /// Asserts r has enough elements to hold the result. The upper bound is `@max(a.limbs.len, b.limbs.len)`. |
| 558 | fn subCarry(r: *Mutable, a: Const, b: Const) bool { | 561 | fn subCarry(r: *Mutable, a: Const, b: Const) bool { |
| 559 | if (a.eqZero()) { | 562 | if (a.eqlZero()) { |
| 560 | r.copy(b); | 563 | r.copy(b); |
| 561 | r.positive = !b.positive; | 564 | r.positive = !b.positive; |
| 562 | return false; | 565 | return false; |
| 563 | } else if (b.eqZero()) { | 566 | } else if (b.eqlZero()) { |
| 564 | r.copy(a); | 567 | r.copy(a); |
| 565 | return false; | 568 | return false; |
| 566 | } else if (a.positive != b.positive) { | 569 | } else if (a.positive != b.positive) { |
| ... | @@ -1002,7 +1005,7 @@ pub const Mutable = struct { | ... | @@ -1002,7 +1005,7 @@ pub const Mutable = struct { |
| 1002 | // Else: | 1005 | // Else: |
| 1003 | // @rem(a - 1, b) = @rem(a + b - 1, b) = @rem(b - 1, b) = b - 1 | 1006 | // @rem(a - 1, b) = @rem(a + b - 1, b) = @rem(b - 1, b) = b - 1 |
| 1004 | // => @mod(a, -b) = b - 1 - b + 1 = 0 | 1007 | // => @mod(a, -b) = b - 1 - b + 1 = 0 |
| 1005 | if (!r.eqZero()) { | 1008 | if (!r.eqlZero()) { |
| 1006 | q.addScalar(q.toConst(), -1); | 1009 | q.addScalar(q.toConst(), -1); |
| 1007 | r.positive = true; | 1010 | r.positive = true; |
| 1008 | r.sub(r.toConst(), y.toConst().abs()); | 1011 | r.sub(r.toConst(), y.toConst().abs()); |
| ... | @@ -1033,7 +1036,7 @@ pub const Mutable = struct { | ... | @@ -1033,7 +1036,7 @@ pub const Mutable = struct { |
| 1033 | // Else : | 1036 | // Else : |
| 1034 | // @rem(a - 1, b) = b - 1 | 1037 | // @rem(a - 1, b) = b - 1 |
| 1035 | // => @mod(-a, b) = -(b - 1) + b - 1 = 0 | 1038 | // => @mod(-a, b) = -(b - 1) + b - 1 = 0 |
| 1036 | if (!r.eqZero()) { | 1039 | if (!r.eqlZero()) { |
| 1037 | q.addScalar(q.toConst(), -1); | 1040 | q.addScalar(q.toConst(), -1); |
| 1038 | r.positive = false; | 1041 | r.positive = false; |
| 1039 | r.add(r.toConst(), y.toConst().abs()); | 1042 | r.add(r.toConst(), y.toConst().abs()); |
| ... | @@ -1119,7 +1122,7 @@ pub const Mutable = struct { | ... | @@ -1119,7 +1122,7 @@ pub const Mutable = struct { |
| 1119 | // 0-bit integers. | 1122 | // 0-bit integers. |
| 1120 | if (bit_count <= shift) { | 1123 | if (bit_count <= shift) { |
| 1121 | // In this case, there is only no overflow if `a` is zero. | 1124 | // In this case, there is only no overflow if `a` is zero. |
| 1122 | if (a.eqZero()) { | 1125 | if (a.eqlZero()) { |
| 1123 | r.set(0); | 1126 | r.set(0); |
| 1124 | } else { | 1127 | } else { |
| 1125 | r.setTwosCompIntLimit(if (a.positive) .max else .min, signedness, bit_count); | 1128 | r.setTwosCompIntLimit(if (a.positive) .max else .min, signedness, bit_count); |
| ... | @@ -1214,10 +1217,10 @@ pub const Mutable = struct { | ... | @@ -1214,10 +1217,10 @@ pub const Mutable = struct { |
| 1214 | /// Asserts that r has enough limbs to store the result. Upper bound is `@max(a.limbs.len, b.limbs.len)`. | 1217 | /// Asserts that r has enough limbs to store the result. Upper bound is `@max(a.limbs.len, b.limbs.len)`. |
| 1215 | pub fn bitOr(r: *Mutable, a: Const, b: Const) void { | 1218 | pub fn bitOr(r: *Mutable, a: Const, b: Const) void { |
| 1216 | // Trivial cases, llsignedor does not support zero. | 1219 | // Trivial cases, llsignedor does not support zero. |
| 1217 | if (a.eqZero()) { | 1220 | if (a.eqlZero()) { |
| 1218 | r.copy(b); | 1221 | r.copy(b); |
| 1219 | return; | 1222 | return; |
| 1220 | } else if (b.eqZero()) { | 1223 | } else if (b.eqlZero()) { |
| 1221 | r.copy(a); | 1224 | r.copy(a); |
| 1222 | return; | 1225 | return; |
| 1223 | } | 1226 | } |
| ... | @@ -1239,10 +1242,10 @@ pub const Mutable = struct { | ... | @@ -1239,10 +1242,10 @@ pub const Mutable = struct { |
| 1239 | /// If a and b are negative, the upper bound is `@max(a.limbs.len, b.limbs.len) + 1`. | 1242 | /// If a and b are negative, the upper bound is `@max(a.limbs.len, b.limbs.len) + 1`. |
| 1240 | pub fn bitAnd(r: *Mutable, a: Const, b: Const) void { | 1243 | pub fn bitAnd(r: *Mutable, a: Const, b: Const) void { |
| 1241 | // Trivial cases, llsignedand does not support zero. | 1244 | // Trivial cases, llsignedand does not support zero. |
| 1242 | if (a.eqZero()) { | 1245 | if (a.eqlZero()) { |
| 1243 | r.copy(a); | 1246 | r.copy(a); |
| 1244 | return; | 1247 | return; |
| 1245 | } else if (b.eqZero()) { | 1248 | } else if (b.eqlZero()) { |
| 1246 | r.copy(b); | 1249 | r.copy(b); |
| 1247 | return; | 1250 | return; |
| 1248 | } | 1251 | } |
| ... | @@ -1264,10 +1267,10 @@ pub const Mutable = struct { | ... | @@ -1264,10 +1267,10 @@ pub const Mutable = struct { |
| 1264 | /// but not both, the upper bound is `@max(a.limbs.len, b.limbs.len) + 1`. | 1267 | /// but not both, the upper bound is `@max(a.limbs.len, b.limbs.len) + 1`. |
| 1265 | pub fn bitXor(r: *Mutable, a: Const, b: Const) void { | 1268 | pub fn bitXor(r: *Mutable, a: Const, b: Const) void { |
| 1266 | // Trivial cases, because llsignedxor does not support negative zero. | 1269 | // Trivial cases, because llsignedxor does not support negative zero. |
| 1267 | if (a.eqZero()) { | 1270 | if (a.eqlZero()) { |
| 1268 | r.copy(b); | 1271 | r.copy(b); |
| 1269 | return; | 1272 | return; |
| 1270 | } else if (b.eqZero()) { | 1273 | } else if (b.eqlZero()) { |
| 1271 | r.copy(a); | 1274 | r.copy(a); |
| 1272 | return; | 1275 | return; |
| 1273 | } | 1276 | } |
| ... | @@ -1330,7 +1333,7 @@ pub const Mutable = struct { | ... | @@ -1330,7 +1333,7 @@ pub const Mutable = struct { |
| 1330 | else => {}, | 1333 | else => {}, |
| 1331 | } | 1334 | } |
| 1332 | 1335 | ||
| 1333 | if (a.eqZero()) { | 1336 | if (a.eqlZero()) { |
| 1334 | // 0^b = 0 | 1337 | // 0^b = 0 |
| 1335 | return r.set(0); | 1338 | return r.set(0); |
| 1336 | } else if (a.limbs.len == 1 and a.limbs[0] == 1) { | 1339 | } else if (a.limbs.len == 1 and a.limbs[0] == 1) { |
| ... | @@ -1442,7 +1445,7 @@ pub const Mutable = struct { | ... | @@ -1442,7 +1445,7 @@ pub const Mutable = struct { |
| 1442 | var tmp_x = try Managed.init(limbs_buffer.allocator); | 1445 | var tmp_x = try Managed.init(limbs_buffer.allocator); |
| 1443 | defer tmp_x.deinit(); | 1446 | defer tmp_x.deinit(); |
| 1444 | 1447 | ||
| 1445 | while (y.len() > 1 and !y.eqZero()) { | 1448 | while (y.len() > 1 and !y.eqlZero()) { |
| 1446 | assert(x.isPositive() and y.isPositive()); | 1449 | assert(x.isPositive() and y.isPositive()); |
| 1447 | assert(x.len() >= y.len()); | 1450 | assert(x.len() >= y.len()); |
| 1448 | 1451 | ||
| ... | @@ -1506,7 +1509,7 @@ pub const Mutable = struct { | ... | @@ -1506,7 +1509,7 @@ pub const Mutable = struct { |
| 1506 | // euclidean algorithm | 1509 | // euclidean algorithm |
| 1507 | assert(x.toConst().order(y.toConst()) != .lt); | 1510 | assert(x.toConst().order(y.toConst()) != .lt); |
| 1508 | 1511 | ||
| 1509 | while (!y.toConst().eqZero()) { | 1512 | while (!y.toConst().eqlZero()) { |
| 1510 | try t_big.divTrunc(&r, &x, &y); | 1513 | try t_big.divTrunc(&r, &x, &y); |
| 1511 | x.swap(&y); | 1514 | x.swap(&y); |
| 1512 | y.swap(&r); | 1515 | y.swap(&r); |
| ... | @@ -1517,7 +1520,7 @@ pub const Mutable = struct { | ... | @@ -1517,7 +1520,7 @@ pub const Mutable = struct { |
| 1517 | 1520 | ||
| 1518 | // Truncates by default. | 1521 | // Truncates by default. |
| 1519 | fn div(q: *Mutable, r: *Mutable, x: *Mutable, y: *Mutable) void { | 1522 | fn div(q: *Mutable, r: *Mutable, x: *Mutable, y: *Mutable) void { |
| 1520 | assert(!y.eqZero()); // division by zero | 1523 | assert(!y.eqlZero()); // division by zero |
| 1521 | assert(q != r); // illegal aliasing | 1524 | assert(q != r); // illegal aliasing |
| 1522 | 1525 | ||
| 1523 | const q_positive = (x.positive == y.positive); | 1526 | const q_positive = (x.positive == y.positive); |
| ... | @@ -1745,7 +1748,7 @@ pub const Mutable = struct { | ... | @@ -1745,7 +1748,7 @@ pub const Mutable = struct { |
| 1745 | } | 1748 | } |
| 1746 | 1749 | ||
| 1747 | const req_limbs = calcTwosCompLimbCount(bit_count); | 1750 | const req_limbs = calcTwosCompLimbCount(bit_count); |
| 1748 | if (req_limbs == 0 or a.eqZero()) { | 1751 | if (req_limbs == 0 or a.eqlZero()) { |
| 1749 | r.set(0); | 1752 | r.set(0); |
| 1750 | return; | 1753 | return; |
| 1751 | } | 1754 | } |
| ... | @@ -1776,7 +1779,7 @@ pub const Mutable = struct { | ... | @@ -1776,7 +1779,7 @@ pub const Mutable = struct { |
| 1776 | const req_limbs = calcTwosCompLimbCount(bit_count); | 1779 | const req_limbs = calcTwosCompLimbCount(bit_count); |
| 1777 | 1780 | ||
| 1778 | // Handle 0-bit integers. | 1781 | // Handle 0-bit integers. |
| 1779 | if (req_limbs == 0 or a.eqZero()) { | 1782 | if (req_limbs == 0 or a.eqlZero()) { |
| 1780 | r.set(0); | 1783 | r.set(0); |
| 1781 | return; | 1784 | return; |
| 1782 | } | 1785 | } |
| ... | @@ -2121,7 +2124,7 @@ pub const Const = struct { | ... | @@ -2121,7 +2124,7 @@ pub const Const = struct { |
| 2121 | } | 2124 | } |
| 2122 | 2125 | ||
| 2123 | pub fn fitsInTwosComp(self: Const, signedness: Signedness, bit_count: usize) bool { | 2126 | pub fn fitsInTwosComp(self: Const, signedness: Signedness, bit_count: usize) bool { |
| 2124 | if (self.eqZero()) { | 2127 | if (self.eqlZero()) { |
| 2125 | return true; | 2128 | return true; |
| 2126 | } | 2129 | } |
| 2127 | if (signedness == .unsigned and !self.positive) { | 2130 | if (signedness == .unsigned and !self.positive) { |
| ... | @@ -2159,7 +2162,7 @@ pub const Const = struct { | ... | @@ -2159,7 +2162,7 @@ pub const Const = struct { |
| 2159 | switch (@typeInfo(T)) { | 2162 | switch (@typeInfo(T)) { |
| 2160 | .Int => |info| { | 2163 | .Int => |info| { |
| 2161 | // Make sure -0 is handled correctly. | 2164 | // Make sure -0 is handled correctly. |
| 2162 | if (self.eqZero()) return 0; | 2165 | if (self.eqlZero()) return 0; |
| 2163 | 2166 | ||
| 2164 | const UT = std.meta.Int(.unsigned, info.bits); | 2167 | const UT = std.meta.Int(.unsigned, info.bits); |
| 2165 | 2168 | ||
| ... | @@ -2253,7 +2256,7 @@ pub const Const = struct { | ... | @@ -2253,7 +2256,7 @@ pub const Const = struct { |
| 2253 | assert(base >= 2); | 2256 | assert(base >= 2); |
| 2254 | assert(base <= 16); | 2257 | assert(base <= 16); |
| 2255 | 2258 | ||
| 2256 | if (self.eqZero()) { | 2259 | if (self.eqlZero()) { |
| 2257 | return allocator.dupe(u8, "0"); | 2260 | return allocator.dupe(u8, "0"); |
| 2258 | } | 2261 | } |
| 2259 | const string = try allocator.alloc(u8, self.sizeInBaseUpperBound(base)); | 2262 | const string = try allocator.alloc(u8, self.sizeInBaseUpperBound(base)); |
| ... | @@ -2278,7 +2281,7 @@ pub const Const = struct { | ... | @@ -2278,7 +2281,7 @@ pub const Const = struct { |
| 2278 | assert(base >= 2); | 2281 | assert(base >= 2); |
| 2279 | assert(base <= 16); | 2282 | assert(base <= 16); |
| 2280 | 2283 | ||
| 2281 | if (self.eqZero()) { | 2284 | if (self.eqlZero()) { |
| 2282 | string[0] = '0'; | 2285 | string[0] = '0'; |
| 2283 | return 1; | 2286 | return 1; |
| 2284 | } | 2287 | } |
| ... | @@ -2478,20 +2481,25 @@ pub const Const = struct { | ... | @@ -2478,20 +2481,25 @@ pub const Const = struct { |
| 2478 | return order(lhs, rhs.toConst()); | 2481 | return order(lhs, rhs.toConst()); |
| 2479 | } | 2482 | } |
| 2480 | 2483 | ||
| 2484 | // TODO: remove after release of 0.11 | ||
| 2485 | pub const eqZero = @compileError("use eqlZero"); | ||
| 2486 | pub const eqAbs = @compileError("use eqlAbs"); | ||
| 2487 | pub const eq = @compileError("use eql"); | ||
| 2488 | |||
| 2481 | /// Returns true if `a == 0`. | 2489 | /// Returns true if `a == 0`. |
| 2482 | pub fn eqZero(a: Const) bool { | 2490 | pub fn eqlZero(a: Const) bool { |
| 2483 | var d: Limb = 0; | 2491 | var d: Limb = 0; |
| 2484 | for (a.limbs) |limb| d |= limb; | 2492 | for (a.limbs) |limb| d |= limb; |
| 2485 | return d == 0; | 2493 | return d == 0; |
| 2486 | } | 2494 | } |
| 2487 | 2495 | ||
| 2488 | /// Returns true if `|a| == |b|`. | 2496 | /// Returns true if `|a| == |b|`. |
| 2489 | pub fn eqAbs(a: Const, b: Const) bool { | 2497 | pub fn eqlAbs(a: Const, b: Const) bool { |
| 2490 | return orderAbs(a, b) == .eq; | 2498 | return orderAbs(a, b) == .eq; |
| 2491 | } | 2499 | } |
| 2492 | 2500 | ||
| 2493 | /// Returns true if `a == b`. | 2501 | /// Returns true if `a == b`. |
| 2494 | pub fn eq(a: Const, b: Const) bool { | 2502 | pub fn eql(a: Const, b: Const) bool { |
| 2495 | return order(a, b) == .eq; | 2503 | return order(a, b) == .eq; |
| 2496 | } | 2504 | } |
| 2497 | 2505 | ||
| ... | @@ -2822,19 +2830,24 @@ pub const Managed = struct { | ... | @@ -2822,19 +2830,24 @@ pub const Managed = struct { |
| 2822 | return a.toConst().order(b.toConst()); | 2830 | return a.toConst().order(b.toConst()); |
| 2823 | } | 2831 | } |
| 2824 | 2832 | ||
| 2833 | // TODO: remove after release of 0.11 | ||
| 2834 | pub const eqZero = @compileError("use eqlZero"); | ||
| 2835 | pub const eqAbs = @compileError("use eqlAbs"); | ||
| 2836 | pub const eq = @compileError("use eql"); | ||
| 2837 | |||
| 2825 | /// Returns true if a == 0. | 2838 | /// Returns true if a == 0. |
| 2826 | pub fn eqZero(a: Managed) bool { | 2839 | pub fn eqlZero(a: Managed) bool { |
| 2827 | return a.toConst().eqZero(); | 2840 | return a.toConst().eqlZero(); |
| 2828 | } | 2841 | } |
| 2829 | 2842 | ||
| 2830 | /// Returns true if |a| == |b|. | 2843 | /// Returns true if |a| == |b|. |
| 2831 | pub fn eqAbs(a: Managed, b: Managed) bool { | 2844 | pub fn eqlAbs(a: Managed, b: Managed) bool { |
| 2832 | return a.toConst().eqAbs(b.toConst()); | 2845 | return a.toConst().eqlAbs(b.toConst()); |
| 2833 | } | 2846 | } |
| 2834 | 2847 | ||
| 2835 | /// Returns true if a == b. | 2848 | /// Returns true if a == b. |
| 2836 | pub fn eq(a: Managed, b: Managed) bool { | 2849 | pub fn eql(a: Managed, b: Managed) bool { |
| 2837 | return a.toConst().eq(b.toConst()); | 2850 | return a.toConst().eql(b.toConst()); |
| 2838 | } | 2851 | } |
| 2839 | 2852 | ||
| 2840 | /// Normalize a possible sequence of leading zeros. | 2853 | /// Normalize a possible sequence of leading zeros. |
lib/std/math/big/int_test.zig+16-16| ... | @@ -461,8 +461,8 @@ test "big.int equality" { | ... | @@ -461,8 +461,8 @@ test "big.int equality" { |
| 461 | var b = try Managed.initSet(testing.allocator, -0xffffffff1); | 461 | var b = try Managed.initSet(testing.allocator, -0xffffffff1); |
| 462 | defer b.deinit(); | 462 | defer b.deinit(); |
| 463 | 463 | ||
| 464 | try testing.expect(a.eqAbs(b)); | 464 | try testing.expect(a.eqlAbs(b)); |
| 465 | try testing.expect(!a.eq(b)); | 465 | try testing.expect(!a.eql(b)); |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | test "big.int abs" { | 468 | test "big.int abs" { |
| ... | @@ -1006,7 +1006,7 @@ test "big.int mul large" { | ... | @@ -1006,7 +1006,7 @@ test "big.int mul large" { |
| 1006 | try b.mul(&a, &a); | 1006 | try b.mul(&a, &a); |
| 1007 | try c.sqr(&a); | 1007 | try c.sqr(&a); |
| 1008 | 1008 | ||
| 1009 | try testing.expect(b.eq(c)); | 1009 | try testing.expect(b.eql(c)); |
| 1010 | } | 1010 | } |
| 1011 | 1011 | ||
| 1012 | test "big.int mulWrap single-single unsigned" { | 1012 | test "big.int mulWrap single-single unsigned" { |
| ... | @@ -1088,7 +1088,7 @@ test "big.int mulWrap large" { | ... | @@ -1088,7 +1088,7 @@ test "big.int mulWrap large" { |
| 1088 | try c.sqr(&a); | 1088 | try c.sqr(&a); |
| 1089 | try c.truncate(&c, .signed, testbits); | 1089 | try c.truncate(&c, .signed, testbits); |
| 1090 | 1090 | ||
| 1091 | try testing.expect(b.eq(c)); | 1091 | try testing.expect(b.eql(c)); |
| 1092 | } | 1092 | } |
| 1093 | 1093 | ||
| 1094 | test "big.int div single-half no rem" { | 1094 | test "big.int div single-half no rem" { |
| ... | @@ -1716,8 +1716,8 @@ test "big.int div multi-single zero-limb trailing" { | ... | @@ -1716,8 +1716,8 @@ test "big.int div multi-single zero-limb trailing" { |
| 1716 | 1716 | ||
| 1717 | var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000); | 1717 | var expected = try Managed.initSet(testing.allocator, 0x6000000000000000000000000000000000000000000000000); |
| 1718 | defer expected.deinit(); | 1718 | defer expected.deinit(); |
| 1719 | try testing.expect(q.eq(expected)); | 1719 | try testing.expect(q.eql(expected)); |
| 1720 | try testing.expect(r.eqZero()); | 1720 | try testing.expect(r.eqlZero()); |
| 1721 | } | 1721 | } |
| 1722 | 1722 | ||
| 1723 | test "big.int div multi-multi zero-limb trailing (with rem)" { | 1723 | test "big.int div multi-multi zero-limb trailing (with rem)" { |
| ... | @@ -1962,7 +1962,7 @@ test "big.int saturate multi unsigned zero" { | ... | @@ -1962,7 +1962,7 @@ test "big.int saturate multi unsigned zero" { |
| 1962 | 1962 | ||
| 1963 | try a.saturate(&a, .unsigned, @bitSizeOf(DoubleLimb)); | 1963 | try a.saturate(&a, .unsigned, @bitSizeOf(DoubleLimb)); |
| 1964 | 1964 | ||
| 1965 | try testing.expect(a.eqZero()); | 1965 | try testing.expect(a.eqlZero()); |
| 1966 | } | 1966 | } |
| 1967 | 1967 | ||
| 1968 | test "big.int saturate multi unsigned" { | 1968 | test "big.int saturate multi unsigned" { |
| ... | @@ -1993,7 +1993,7 @@ test "big.int shift-right multi" { | ... | @@ -1993,7 +1993,7 @@ test "big.int shift-right multi" { |
| 1993 | try a.shiftRight(&a, 63); | 1993 | try a.shiftRight(&a, 63); |
| 1994 | try a.shiftRight(&a, 63); | 1994 | try a.shiftRight(&a, 63); |
| 1995 | try a.shiftRight(&a, 2); | 1995 | try a.shiftRight(&a, 2); |
| 1996 | try testing.expect(a.eqZero()); | 1996 | try testing.expect(a.eqlZero()); |
| 1997 | } | 1997 | } |
| 1998 | 1998 | ||
| 1999 | test "big.int shift-left single" { | 1999 | test "big.int shift-left single" { |
| ... | @@ -2224,7 +2224,7 @@ test "big.int bitwise and negative-positive multi-limb" { | ... | @@ -2224,7 +2224,7 @@ test "big.int bitwise and negative-positive multi-limb" { |
| 2224 | 2224 | ||
| 2225 | try a.bitAnd(&a, &b); | 2225 | try a.bitAnd(&a, &b); |
| 2226 | 2226 | ||
| 2227 | try testing.expect(a.eqZero()); | 2227 | try testing.expect(a.eqlZero()); |
| 2228 | } | 2228 | } |
| 2229 | 2229 | ||
| 2230 | test "big.int bitwise and positive-negative simple" { | 2230 | test "big.int bitwise and positive-negative simple" { |
| ... | @@ -2246,7 +2246,7 @@ test "big.int bitwise and positive-negative multi-limb" { | ... | @@ -2246,7 +2246,7 @@ test "big.int bitwise and positive-negative multi-limb" { |
| 2246 | 2246 | ||
| 2247 | try a.bitAnd(&a, &b); | 2247 | try a.bitAnd(&a, &b); |
| 2248 | 2248 | ||
| 2249 | try testing.expect(a.eqZero()); | 2249 | try testing.expect(a.eqlZero()); |
| 2250 | } | 2250 | } |
| 2251 | 2251 | ||
| 2252 | test "big.int bitwise and negative-negative simple" { | 2252 | test "big.int bitwise and negative-negative simple" { |
| ... | @@ -2325,7 +2325,7 @@ test "big.int bitwise xor single negative zero" { | ... | @@ -2325,7 +2325,7 @@ test "big.int bitwise xor single negative zero" { |
| 2325 | 2325 | ||
| 2326 | try a.bitXor(&a, &b); | 2326 | try a.bitXor(&a, &b); |
| 2327 | 2327 | ||
| 2328 | try testing.expect(a.eqZero()); | 2328 | try testing.expect(a.eqlZero()); |
| 2329 | } | 2329 | } |
| 2330 | 2330 | ||
| 2331 | test "big.int bitwise xor single negative multi-limb" { | 2331 | test "big.int bitwise xor single negative multi-limb" { |
| ... | @@ -2554,7 +2554,7 @@ test "big.int mutable to managed" { | ... | @@ -2554,7 +2554,7 @@ test "big.int mutable to managed" { |
| 2554 | var a = Mutable.init(limbs_buf, 0xdeadbeef); | 2554 | var a = Mutable.init(limbs_buf, 0xdeadbeef); |
| 2555 | var a_managed = a.toManaged(allocator); | 2555 | var a_managed = a.toManaged(allocator); |
| 2556 | 2556 | ||
| 2557 | try testing.expect(a.toConst().eq(a_managed.toConst())); | 2557 | try testing.expect(a.toConst().eql(a_managed.toConst())); |
| 2558 | } | 2558 | } |
| 2559 | 2559 | ||
| 2560 | test "big.int const to managed" { | 2560 | test "big.int const to managed" { |
| ... | @@ -2564,7 +2564,7 @@ test "big.int const to managed" { | ... | @@ -2564,7 +2564,7 @@ test "big.int const to managed" { |
| 2564 | var b = try a.toConst().toManaged(testing.allocator); | 2564 | var b = try a.toConst().toManaged(testing.allocator); |
| 2565 | defer b.deinit(); | 2565 | defer b.deinit(); |
| 2566 | 2566 | ||
| 2567 | try testing.expect(a.toConst().eq(b.toConst())); | 2567 | try testing.expect(a.toConst().eql(b.toConst())); |
| 2568 | } | 2568 | } |
| 2569 | 2569 | ||
| 2570 | test "big.int pow" { | 2570 | test "big.int pow" { |
| ... | @@ -2590,7 +2590,7 @@ test "big.int pow" { | ... | @@ -2590,7 +2590,7 @@ test "big.int pow" { |
| 2590 | // y and a are aliased | 2590 | // y and a are aliased |
| 2591 | try a.pow(&a, 123); | 2591 | try a.pow(&a, 123); |
| 2592 | 2592 | ||
| 2593 | try testing.expect(a.eq(y)); | 2593 | try testing.expect(a.eql(y)); |
| 2594 | 2594 | ||
| 2595 | const ys = try y.toString(testing.allocator, 16, .lower); | 2595 | const ys = try y.toString(testing.allocator, 16, .lower); |
| 2596 | defer testing.allocator.free(ys); | 2596 | defer testing.allocator.free(ys); |
| ... | @@ -3096,7 +3096,7 @@ test "big.int mul multi-multi alias r with a and b" { | ... | @@ -3096,7 +3096,7 @@ test "big.int mul multi-multi alias r with a and b" { |
| 3096 | var want = try Managed.initSet(testing.allocator, 4 * maxInt(Limb) * maxInt(Limb)); | 3096 | var want = try Managed.initSet(testing.allocator, 4 * maxInt(Limb) * maxInt(Limb)); |
| 3097 | defer want.deinit(); | 3097 | defer want.deinit(); |
| 3098 | 3098 | ||
| 3099 | try testing.expect(a.eq(want)); | 3099 | try testing.expect(a.eql(want)); |
| 3100 | 3100 | ||
| 3101 | if (@typeInfo(Limb).Int.bits == 64) { | 3101 | if (@typeInfo(Limb).Int.bits == 64) { |
| 3102 | try testing.expectEqual(@as(usize, 5), a.limbs.len); | 3102 | try testing.expectEqual(@as(usize, 5), a.limbs.len); |
| ... | @@ -3112,7 +3112,7 @@ test "big.int sqr multi alias r with a" { | ... | @@ -3112,7 +3112,7 @@ test "big.int sqr multi alias r with a" { |
| 3112 | var want = try Managed.initSet(testing.allocator, 4 * maxInt(Limb) * maxInt(Limb)); | 3112 | var want = try Managed.initSet(testing.allocator, 4 * maxInt(Limb) * maxInt(Limb)); |
| 3113 | defer want.deinit(); | 3113 | defer want.deinit(); |
| 3114 | 3114 | ||
| 3115 | try testing.expect(a.eq(want)); | 3115 | try testing.expect(a.eql(want)); |
| 3116 | 3116 | ||
| 3117 | if (@typeInfo(Limb).Int.bits == 64) { | 3117 | if (@typeInfo(Limb).Int.bits == 64) { |
| 3118 | try testing.expectEqual(@as(usize, 5), a.limbs.len); | 3118 | try testing.expectEqual(@as(usize, 5), a.limbs.len); |
lib/std/math/big/rational.zig+3-3| ... | @@ -205,7 +205,7 @@ pub const Rational = struct { | ... | @@ -205,7 +205,7 @@ pub const Rational = struct { |
| 205 | const ebias = (1 << (esize - 1)) - 1; | 205 | const ebias = (1 << (esize - 1)) - 1; |
| 206 | const emin = 1 - ebias; | 206 | const emin = 1 - ebias; |
| 207 | 207 | ||
| 208 | if (self.p.eqZero()) { | 208 | if (self.p.eqlZero()) { |
| 209 | return 0; | 209 | return 0; |
| 210 | } | 210 | } |
| 211 | 211 | ||
| ... | @@ -294,7 +294,7 @@ pub const Rational = struct { | ... | @@ -294,7 +294,7 @@ pub const Rational = struct { |
| 294 | 294 | ||
| 295 | try self.reduce(); | 295 | try self.reduce(); |
| 296 | 296 | ||
| 297 | if (self.q.eqZero()) { | 297 | if (self.q.eqlZero()) { |
| 298 | @panic("cannot set rational with denominator = 0"); | 298 | @panic("cannot set rational with denominator = 0"); |
| 299 | } | 299 | } |
| 300 | } | 300 | } |
| ... | @@ -434,7 +434,7 @@ pub const Rational = struct { | ... | @@ -434,7 +434,7 @@ pub const Rational = struct { |
| 434 | /// | 434 | /// |
| 435 | /// Returns an error if memory could not be allocated. | 435 | /// Returns an error if memory could not be allocated. |
| 436 | pub fn div(r: *Rational, a: Rational, b: Rational) !void { | 436 | pub fn div(r: *Rational, a: Rational, b: Rational) !void { |
| 437 | if (b.p.eqZero()) { | 437 | if (b.p.eqlZero()) { |
| 438 | @panic("division by zero"); | 438 | @panic("division by zero"); |
| 439 | } | 439 | } |
| 440 | 440 |
src/InternPool.zig+1-1| ... | @@ -1037,7 +1037,7 @@ pub const Key = union(enum) { | ... | @@ -1037,7 +1037,7 @@ pub const Key = union(enum) { |
| 1037 | .big_int => |aa| switch (b_info.storage) { | 1037 | .big_int => |aa| switch (b_info.storage) { |
| 1038 | .u64 => |bb| aa.orderAgainstScalar(bb) == .eq, | 1038 | .u64 => |bb| aa.orderAgainstScalar(bb) == .eq, |
| 1039 | .i64 => |bb| aa.orderAgainstScalar(bb) == .eq, | 1039 | .i64 => |bb| aa.orderAgainstScalar(bb) == .eq, |
| 1040 | .big_int => |bb| aa.eq(bb), | 1040 | .big_int => |bb| aa.eql(bb), |
| 1041 | .lazy_align, .lazy_size => false, | 1041 | .lazy_align, .lazy_size => false, |
| 1042 | }, | 1042 | }, |
| 1043 | .lazy_align => |aa| switch (b_info.storage) { | 1043 | .lazy_align => |aa| switch (b_info.storage) { |
src/Module.zig+1-1| ... | @@ -7049,7 +7049,7 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 { | ... | @@ -7049,7 +7049,7 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 { |
| 7049 | if (big.positive) return @as(u16, @intCast(big.bitCountAbs() + @intFromBool(sign))); | 7049 | if (big.positive) return @as(u16, @intCast(big.bitCountAbs() + @intFromBool(sign))); |
| 7050 | 7050 | ||
| 7051 | // Zero is still a possibility, in which case unsigned is fine | 7051 | // Zero is still a possibility, in which case unsigned is fine |
| 7052 | if (big.eqZero()) return 0; | 7052 | if (big.eqlZero()) return 0; |
| 7053 | 7053 | ||
| 7054 | return @as(u16, @intCast(big.bitCountTwosComp())); | 7054 | return @as(u16, @intCast(big.bitCountTwosComp())); |
| 7055 | }, | 7055 | }, |
src/RangeSet.zig+1-1| ... | @@ -95,7 +95,7 @@ pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) ! | ... | @@ -95,7 +95,7 @@ pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) ! |
| 95 | try counter.addScalar(&counter, 1); | 95 | try counter.addScalar(&counter, 1); |
| 96 | 96 | ||
| 97 | const cur_start_int = cur.first.toValue().toBigInt(&space, mod); | 97 | const cur_start_int = cur.first.toValue().toBigInt(&space, mod); |
| 98 | if (!cur_start_int.eq(counter.toConst())) { | 98 | if (!cur_start_int.eql(counter.toConst())) { |
| 99 | return false; | 99 | return false; |
| 100 | } | 100 | } |
| 101 | } | 101 | } |
src/Sema.zig+1-1| ... | @@ -36375,7 +36375,7 @@ fn float128IntPartToBigInt( | ... | @@ -36375,7 +36375,7 @@ fn float128IntPartToBigInt( |
| 36375 | 36375 | ||
| 36376 | // The float is reduced in rational.setFloat, so we assert that denominator is equal to one | 36376 | // The float is reduced in rational.setFloat, so we assert that denominator is equal to one |
| 36377 | const big_one = std.math.big.int.Const{ .limbs = &.{1}, .positive = true }; | 36377 | const big_one = std.math.big.int.Const{ .limbs = &.{1}, .positive = true }; |
| 36378 | assert(rational.q.toConst().eqAbs(big_one)); | 36378 | assert(rational.q.toConst().eqlAbs(big_one)); |
| 36379 | 36379 | ||
| 36380 | if (is_negative) { | 36380 | if (is_negative) { |
| 36381 | rational.negate(); | 36381 | rational.negate(); |
src/value.zig+1-1| ... | @@ -1771,7 +1771,7 @@ pub const Value = struct { | ... | @@ -1771,7 +1771,7 @@ pub const Value = struct { |
| 1771 | .ptr => |ptr| switch (ptr.addr) { | 1771 | .ptr => |ptr| switch (ptr.addr) { |
| 1772 | .int => { | 1772 | .int => { |
| 1773 | var buf: BigIntSpace = undefined; | 1773 | var buf: BigIntSpace = undefined; |
| 1774 | return val.toBigInt(&buf, mod).eqZero(); | 1774 | return val.toBigInt(&buf, mod).eqlZero(); |
| 1775 | }, | 1775 | }, |
| 1776 | else => false, | 1776 | else => false, |
| 1777 | }, | 1777 | }, |