Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Private Function

decimalLength

Private Function
std.fmt.float.decimalLength
fn decimalLength(v: anytype) u32

Params

  • v

File

fmt/float.zig:498
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
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,
    }
}