Skip to main content

FMT_MAX_PRECISION

Constant FMT_MAX_PRECISION 

Source
pub const FMT_MAX_PRECISION: usize = _; // 65_535usize
Expand description

Rust’s format!("{:.*}", n, x) panics when n exceeds the fmt runtime’s internal precision limit. User-supplied precision can legally reach far higher values (e.g. f"{1.5:.1000000}") — clamp here so we produce a (truncated-but-valid) output instead of aborting the interpreter. Harmless in practice: f64 carries only ~17 significant digits, so precision beyond 65K is padding zeros at best.

The two caps differ by 1: {:.*} (plain) accepts u16::MAX, but {:.*e} (exponential) hits a tighter assertion (ndigits > 0 in core::num::flt2dec) at exactly u16::MAX. Keeping plain at the higher cap preserves byte-identical output with CPython up through precision == u16::MAX for fixed / percent / general-non-scientific paths.