| ... | ... | @@ -391,16 +391,12 @@ pub const Mutable = struct { |
| 391 | 391 | /// Asserts the result fits in `r`. An upper bound on the number of limbs needed by |
| 392 | 392 | /// r is `math.max(a.limbs.len, calcLimbLen(scalar)) + 1`. |
| 393 | 393 | pub fn addScalar(r: *Mutable, a: Const, scalar: anytype) void { |
| 394 | | const Scalar = @TypeOf(scalar); |
| 395 | | const magnitude = switch (@typeInfo(Scalar)) { |
| 396 | | .ComptimeInt => scalar, |
| 397 | | .Int => |int| switch (int.signedness) { |
| 398 | | .signed => minInt(Scalar), |
| 399 | | .unsigned => maxInt(Scalar), |
| 400 | | }, |
| 394 | const limb_len = comptime switch (@typeInfo(@TypeOf(scalar))) { |
| 395 | .ComptimeInt => calcLimbLen(scalar), |
| 396 | .Int => |info| calcTwosCompLimbCount(info.bits), |
| 401 | 397 | else => @compileError("expected scalar to be an int"), |
| 402 | 398 | }; |
| 403 | | var limbs: [calcLimbLen(magnitude)]Limb = undefined; |
| 399 | var limbs: [limb_len]Limb = undefined; |
| 404 | 400 | const operand = init(&limbs, scalar).toConst(); |
| 405 | 401 | return add(r, a, operand); |
| 406 | 402 | } |
| ... | ... | @@ -2312,16 +2308,12 @@ pub const Const = struct { |
| 2312 | 2308 | |
| 2313 | 2309 | /// Same as `order` but the right-hand operand is a primitive integer. |
| 2314 | 2310 | pub fn orderAgainstScalar(lhs: Const, scalar: anytype) math.Order { |
| 2315 | | const Scalar = @TypeOf(scalar); |
| 2316 | | const magnitude = switch (@typeInfo(Scalar)) { |
| 2317 | | .ComptimeInt => scalar, |
| 2318 | | .Int => |int| switch (int.signedness) { |
| 2319 | | .signed => minInt(Scalar), |
| 2320 | | .unsigned => maxInt(Scalar), |
| 2321 | | }, |
| 2311 | const limb_len = comptime switch (@typeInfo(@TypeOf(scalar))) { |
| 2312 | .ComptimeInt => calcLimbLen(scalar), |
| 2313 | .Int => |info| calcTwosCompLimbCount(info.bits), |
| 2322 | 2314 | else => @compileError("expected scalar to be an int"), |
| 2323 | 2315 | }; |
| 2324 | | var limbs: [calcLimbLen(magnitude)]Limb = undefined; |
| 2316 | var limbs: [limb_len]Limb = undefined; |
| 2325 | 2317 | const rhs = Mutable.init(&limbs, scalar); |
| 2326 | 2318 | return order(lhs, rhs.toConst()); |
| 2327 | 2319 | } |