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.

decimalLength

float.decimalLength
fn decimalLength(v: anytype) u32

File

lib/std/fmt/float.zig:498

Code

fn decimalLength(v: anytype) u32 {
    switch (@TypeOf(v)) {
        u32, u64 => {
            std.debug.assert(v < 100000000000000000);
            if (v >= 10000000000000000) return 17;
            if (v >= 1000000000000000) return 16;
            if (v >= 100000000000000) return 15;
            if (v >= 10000000000000) return 14;
            if (v >= 1000000000000) return 13;
            if (v >= 100000000000) return 12;
            if (v >= 10000000000) return 11;
            if (v >= 1000000000) return 10;
            if (v >= 100000000) return 9;
            if (v >= 10000000) return 8;
            if (v >= 1000000) return 7;
            if (v >= 100000) return 6;
            if (v >= 10000) return 5;
            if (v >= 1000) return 4;
            if (v >= 100) return 3;
            if (v >= 10) return 2;
            return 1;
        },
        u128 => {
            const LARGEST_POW10 = (@as(u128, 5421010862427522170) << 64) | 687399551400673280;
            var p10 = LARGEST_POW10;
            var i: u32 = 39;
            while (i > 0) : (i -= 1) {
                if (v >= p10) return i;
                p10 /= 10;
            }
            return 1;
        },
        else => unreachable,
    }
}