| ... | @@ -391,7 +391,16 @@ pub const Mutable = struct { | ... | @@ -391,7 +391,16 @@ pub const Mutable = struct { |
| 391 | /// Asserts the result fits in `r`. An upper bound on the number of limbs needed by | 391 | /// Asserts the result fits in `r`. An upper bound on the number of limbs needed by |
| 392 | /// r is `math.max(a.limbs.len, calcLimbLen(scalar)) + 1`. | 392 | /// r is `math.max(a.limbs.len, calcLimbLen(scalar)) + 1`. |
| 393 | pub fn addScalar(r: *Mutable, a: Const, scalar: anytype) void { | 393 | pub fn addScalar(r: *Mutable, a: Const, scalar: anytype) void { |
| 394 | var limbs: [calcLimbLen(scalar)]Limb = undefined; | 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 | }, |
| | 401 | else => @compileError("expected scalar to be an int"), |
| | 402 | }; |
| | 403 | var limbs: [calcLimbLen(magnitude)]Limb = undefined; |
| 395 | const operand = init(&limbs, scalar).toConst(); | 404 | const operand = init(&limbs, scalar).toConst(); |
| 396 | return add(r, a, operand); | 405 | return add(r, a, operand); |
| 397 | } | 406 | } |
| ... | @@ -2303,7 +2312,16 @@ pub const Const = struct { | ... | @@ -2303,7 +2312,16 @@ pub const Const = struct { |
| 2303 | | 2312 | |
| 2304 | /// Same as `order` but the right-hand operand is a primitive integer. | 2313 | /// Same as `order` but the right-hand operand is a primitive integer. |
| 2305 | pub fn orderAgainstScalar(lhs: Const, scalar: anytype) math.Order { | 2314 | pub fn orderAgainstScalar(lhs: Const, scalar: anytype) math.Order { |
| 2306 | var limbs: [calcLimbLen(scalar)]Limb = undefined; | 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 | }, |
| | 2322 | else => @compileError("expected scalar to be an int"), |
| | 2323 | }; |
| | 2324 | var limbs: [calcLimbLen(magnitude)]Limb = undefined; |
| 2307 | const rhs = Mutable.init(&limbs, scalar); | 2325 | const rhs = Mutable.init(&limbs, scalar); |
| 2308 | return order(lhs, rhs.toConst()); | 2326 | return order(lhs, rhs.toConst()); |
| 2309 | } | 2327 | } |