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 Constant
max_digits
Public Constant
std.fmt.parse_float.decimal.Decimal.max_digits
pubconstmax_digits = if (MantissaT == u64) 768else11564
The maximum number of digits required to unambiguously round a float.
For a double-precision IEEE-754 float, this required 767 digits, so we store the max digits + 1.
We can exactly represent a float in base b from base 2 if b is divisible by 2. This function calculates the exact number of digits required to exactly represent that float.
According to the "Handbook of Floating Point Arithmetic", for IEEE754, with emin being the min exponent, p2 being the precision, and b being the base, the number of digits follows as:
The maximum number of digits required to unambiguously round a float.
For a double-precision IEEE-754 float, this required 767 digits, so we store the max digits + 1.
We can exactly represent a float in base
bfrom base 2 ifbis divisible by 2. This function calculates the exact number of digits required to exactly represent that float.According to the "Handbook of Floating Point Arithmetic", for IEEE754, with emin being the min exponent, p2 being the precision, and b being the base, the number of digits follows as:
−emin + p2 + ⌊(emin + 1) log(2, b) − log(1 − 2^(−p2), b)⌋For f32, this follows as: emin = -126 p2 = 24
For f64, this follows as: emin = -1022 p2 = 53
For f128, this follows as: emin = -16383 p2 = 112
In Python:
-emin + p2 + math.floor((emin+ 1)*math.log(2, b)-math.log(1-2**(-p2), b))