Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

log10

Returns the base-10 logarithm of x.

Special Cases:

log10.log10
pub fn log10(x: anytype) @TypeOf(x)

File

lib/std/math/log10.zig:12

Code

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)),
    }
}