Returns the base-10 logarithm of x.
Special Cases:
pub fn log10(x: anytype) @TypeOf(x)
pub fn log10(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
switch (@typeInfo(T)) {
.comptime_float => {
return @as(comptime_float, @log10(x));
},
.float => return @log10(x),
.comptime_int => {
const Int = @Int(
if (x < 0) .signed else .unsigned,
// We let log10_int check if x is 0, for a nicer error message.
@max(16, if (x == 0) 0 else 1 + std.math.log2(x)),
);
return @as(comptime_int, log10_int(@as(Int, x)));
},
.int => |IntType| switch (IntType.signedness) {
.signed => @compileError("log10 not implemented for signed integers"),
.unsigned => return log10_int(x),
},
else => @compileError("log10 not implemented for " ++ @typeName(T)),
}
}