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.
Zig › std/ › math/ › log10.zig › less_than_5
less_than_5
log10.less_than_5
inline fn less_than_5 (x : u32 ) u32
File
Code
inline fn less_than_5 (x : u32 ) u32 {
// we get two possible bit patterns above the low 17 bits,
// depending on whether val is below or above the threshold.
const C1 : u32 = 0b011_00000000000000000 - 10 ;
const C2 : u32 = 0b100_00000000000000000 - 100 ;
const C3 : u32 = 0b111_00000000000000000 - 1000 ;
const C4 : u32 = 0b100_00000000000000000 - 10000 ;
// Value of top bits:
// +c1 +c2 1&2 +c3 +c4 3&4 ^
// 0..=9 010 011 010 110 011 010 000 = 0
// 10..=99 011 011 011 110 011 010 001 = 1
// 100..=999 011 100 000 110 011 010 010 = 2
// 1000..=9999 011 100 000 111 011 011 011 = 3
// 10000..=99999 011 100 000 111 100 100 100 = 4
return (((x + C1 ) & (x + C2 )) ^ ((x + C3 ) & (x + C4 ))) >> 17 ;
}