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 Constant

max_digits

Public Constant
std.fmt.parse_float.decimal.Decimal.max_digits
pub const max_digits = if (MantissaT == u64) 768 else 11564

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:

−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))

File

fmt/parse_float/decimal.zig:61
61
        pub const max_digits = if (MantissaT == u64) 768 else 11564