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. Public Namespace

Backend64_TablesSmall

Public Namespace
std.fmt.float.Backend64_TablesSmall
pub const Backend64_TablesSmall = struct

Values

Functions

fn mulShift64(m: u64, mul: *const [2]u64, j: u32) u64
fn computePow5(i: u32) [2]u64
fn computeInvPow5(i: u32) [2]u64

File

fmt/float.zig:709
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
pub const Backend64_TablesSmall = struct {
    const T = u64;
    const mulShift = mulShift64;
    const POW5_INV_BITCOUNT = FLOAT64_POW5_INV_BITCOUNT;
    const POW5_BITCOUNT = FLOAT64_POW5_BITCOUNT;

    const bound1 = 21;
    const bound2 = 63;
    const adjust_q = false;

    fn computePow5(i: u32) [2]u64 {
        const base = i / FLOAT64_POW5_TABLE_SIZE;
        const base2 = base * FLOAT64_POW5_TABLE_SIZE;
        const mul = &FLOAT64_POW5_SPLIT2[base];
        if (i == base2) {
            return .{ mul[0], mul[1] };
        } else {
            const offset = i - base2;
            const m = FLOAT64_POW5_TABLE[offset];
            const b0 = @as(u128, m) * mul[0];
            const b2 = @as(u128, m) * mul[1];
            const delta: u7 = @intCast(pow5Bits(i) - pow5Bits(base2));
            const shift: u5 = @intCast((i % 16) << 1);
            const shifted_sum = ((b0 >> delta) + (b2 << (64 - delta))) + 1 + ((FLOAT64_POW5_OFFSETS[i / 16] >> shift) & 3);
            return .{ @truncate(shifted_sum), @truncate(shifted_sum >> 64) };
        }
    }

    fn computeInvPow5(i: u32) [2]u64 {
        const base = (i + FLOAT64_POW5_TABLE_SIZE - 1) / FLOAT64_POW5_TABLE_SIZE;
        const base2 = base * FLOAT64_POW5_TABLE_SIZE;
        const mul = &FLOAT64_POW5_INV_SPLIT2[base]; // 1 / 5^base2
        if (i == base2) {
            return .{ mul[0], mul[1] };
        } else {
            const offset = base2 - i;
            const m = FLOAT64_POW5_TABLE[offset]; // 5^offset
            const b0 = @as(u128, m) * (mul[0] - 1);
            const b2 = @as(u128, m) * mul[1]; // 1/5^base2 * 5^offset = 1/5^(base2-offset) = 1/5^i
            const delta: u7 = @intCast(pow5Bits(base2) - pow5Bits(i));
            const shift: u5 = @intCast((i % 16) << 1);
            const shifted_sum = ((b0 >> delta) + (b2 << (64 - delta))) + 1 + ((FLOAT64_POW5_INV_OFFSETS[i / 16] >> shift) & 3);
            return .{ @truncate(shifted_sum), @truncate(shifted_sum >> 64) };
        }
    }
}