DoxigAlpha

log10

Returns the base-10 logarithm of x.

Special Cases:

  • log10(+inf) = +inf
  • log10(0) = -inf
  • log10(x) = nan if x < 0
  • log10(nan) = nan

Function parameters

Parameters

#
x:anytype

Returns the base-10 logarithm of x.

Functions

#
log10
Returns the base-10 logarithm of x.
log10_int
Return the log base 10 of integer value x, rounding down to the

Source

Implementation

#
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 => {
            return @as(comptime_int, @floor(@log10(@as(f64, 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)),
    }
}