Function calcLimbLen [src]
Returns the number of limbs needed to store scalar, which must be a
primitive integer or float value.
Note: A comptime-known upper bound of this value that may be used
instead if scalar is not already comptime-known is
calcTwosCompLimbCount(@typeInfo(@TypeOf(scalar)).int.bits)
Prototype
pub fn calcLimbLen(scalar: anytype) usize
Source
pub fn calcLimbLen(scalar: anytype) usize {
switch (@typeInfo(@TypeOf(scalar))) {
.int, .comptime_int => {
if (scalar == 0) return 1;
const w_value = @abs(scalar);
return @as(usize, @intCast(@divFloor(@as(Limb, @intCast(math.log2(w_value))), limb_bits) + 1));
},
.float => {
const repr: std.math.FloatRepr(@TypeOf(scalar)) = @bitCast(scalar);
return switch (repr.exponent) {
.denormal => 1,
else => return calcNonZeroTwosCompLimbCount(@as(usize, 2) + @max(repr.exponent.unbias(), 0)),
.infinite => 0,
};
},
.comptime_float => return calcLimbLen(@as(f128, scalar)),
else => @compileError("expected float or int, got " ++ @typeName(@TypeOf(scalar))),
}
}