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 standard library.
std › math › big › int › Const › log10 Public Function log10 Doc Source Public Function std.math.big.int.Const.log10
pub fn log10 (a : Const , limbs_buffer : []Limb ) Limb Params File math/big/int.zig: 2764
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796 pub fn log10 (a : Const , limbs_buffer : []Limb ) Limb {
assert (a .positive );
assert (!a .eqlZero ());
const limb_base_as_bigint : Const = .{ .limbs = &.{constants .big_bases [10 ]}, .positive = true };
var q : Mutable = .{
.limbs = limbs_buffer [0 .. a .limbs .len + 2 ],
.positive = true ,
.len = a .limbs .len ,
};
@memcpy (q .limbs [0 ..a .limbs .len ], a .limbs );
var remainder : Mutable = .{
.limbs = limbs_buffer [q .limbs .len ..][0 ..a .limbs .len ],
.positive = true ,
.len = 1 ,
};
const division_buf = limbs_buffer [q .limbs .len + remainder .limbs .len ..];
var num_digits : Limb = 0 ;
while (q .len >= 2 ) {
q .divTrunc (&remainder , q .toConst (), limb_base_as_bigint , division_buf );
num_digits += constants .digits_per_limb [10 ];
}
var remaining_limb = q .limbs [0 ];
while (remaining_limb != 0 ) {
remaining_limb /= 10 ;
num_digits += 1 ;
}
return num_digits - 1 ;
}
Calculate the base 10 logarithm, rounded down.
limbs_bufferis used for temporary storage. The amount required is given bycalcLog10LimbsBufferLen.