| ... | ... | @@ -18,11 +18,14 @@ const debug_safety = false; |
| 18 | 18 | /// Returns the number of limbs needed to store `scalar`, which must be a |
| 19 | 19 | /// primitive integer value. |
| 20 | 20 | pub fn calcLimbLen(scalar: anytype) usize { |
| 21 | | if (scalar == 0) { |
| 22 | | return 1; |
| 23 | | } |
| 21 | const T = @TypeOf(scalar); |
| 22 | const max_scalar = switch (@typeInfo(T)) { |
| 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 | 29 | return @divFloor(@intCast(Limb, math.log2(w_value)), limb_bits) + 1; |
| 27 | 30 | } |
| 28 | 31 | |