| ... | @@ -18,11 +18,14 @@ const debug_safety = false; | ... | @@ -18,11 +18,14 @@ const debug_safety = false; |
| 18 | /// Returns the number of limbs needed to store `scalar`, which must be a | 18 | /// Returns the number of limbs needed to store `scalar`, which must be a |
| 19 | /// primitive integer value. | 19 | /// primitive integer value. |
| 20 | pub fn calcLimbLen(scalar: anytype) usize { | 20 | pub fn calcLimbLen(scalar: anytype) usize { |
| 21 | if (scalar == 0) { | 21 | const T = @TypeOf(scalar); |
| 22 | return 1; | 22 | const max_scalar = switch (@typeInfo(T)) { |
| 23 | } | 23 | .Int => maxInt(T), |
| | 24 | .ComptimeInt => scalar, |
| | 25 | else => @compileError("parameter must be a primitive integer type"), |
| | 26 | }; |
| 24 | | 27 | |
| 25 | const w_value = std.math.absCast(scalar); | 28 | const w_value = std.math.absCast(max_scalar); |
| 26 | return @divFloor(@intCast(Limb, math.log2(w_value)), limb_bits) + 1; | 29 | return @divFloor(@intCast(Limb, math.log2(w_value)), limb_bits) + 1; |
| 27 | } | 30 | } |
| 28 | | 31 | |