| ... | ... | @@ -394,6 +394,12 @@ pub const Mutable = struct { |
| 394 | 394 | /// Asserts the result fits in `r`. An upper bound on the number of limbs needed by |
| 395 | 395 | /// r is `math.max(a.limbs.len, calcLimbLen(scalar)) + 1`. |
| 396 | 396 | pub fn addScalar(r: *Mutable, a: Const, scalar: anytype) void { |
| 397 | // Normally we could just determine the number of limbs needed with calcLimbLen, |
| 398 | // but that is not comptime-known when scalar is not a comptime_int. Instead, we |
| 399 | // use calcTwosCompLimbCount for a non-comptime_int scalar, which can be pessimistic |
| 400 | // in the case that scalar happens to be small in magnitude within its type, but it |
| 401 | // is well worth being able to use the stack and not needing an allocator passed in. |
| 402 | // Note that Mutable.init still sets operand.len to calcLimbLen(scalar) in any case. |
| 397 | 403 | const limb_len = comptime switch (@typeInfo(@TypeOf(scalar))) { |
| 398 | 404 | .ComptimeInt => calcLimbLen(scalar), |
| 399 | 405 | .Int => |info| calcTwosCompLimbCount(info.bits), |
| ... | ... | @@ -2311,6 +2317,12 @@ pub const Const = struct { |
| 2311 | 2317 | |
| 2312 | 2318 | /// Same as `order` but the right-hand operand is a primitive integer. |
| 2313 | 2319 | pub fn orderAgainstScalar(lhs: Const, scalar: anytype) math.Order { |
| 2320 | // Normally we could just determine the number of limbs needed with calcLimbLen, |
| 2321 | // but that is not comptime-known when scalar is not a comptime_int. Instead, we |
| 2322 | // use calcTwosCompLimbCount for a non-comptime_int scalar, which can be pessimistic |
| 2323 | // in the case that scalar happens to be small in magnitude within its type, but it |
| 2324 | // is well worth being able to use the stack and not needing an allocator passed in. |
| 2325 | // Note that Mutable.init still sets rhs.len to calcLimbLen(scalar) in any case. |
| 2314 | 2326 | const limb_len = comptime switch (@typeInfo(@TypeOf(scalar))) { |
| 2315 | 2327 | .ComptimeInt => calcLimbLen(scalar), |
| 2316 | 2328 | .Int => |info| calcTwosCompLimbCount(info.bits), |