Skip to main content

py_float_repr

Function py_float_repr 

Source
pub fn py_float_repr(x: f64) -> String
Expand description

CPython repr(float): shortest round-trip decimal digits (David Gay dtoa mode-0 semantics: among round-tripping candidates prefer the one nearest the exact binary value, ties to even), fixed notation when the decimal point position is in (-4, 16], otherwise exponent form with lowercase e, mandatory sign, and a minimum two-digit exponent. Integral in-range floats keep a .0 suffix. inf / -inf / nan.

NOTE: Rust’s own {}/{:e} shortest formatter is NOT equivalent — it diverges from CPython on exact-tie mantissas (e.g. the double nearest -101065508335255.125 reprs as ...12 in CPython, ...13 via {:e}), hence the exact-decimal search below.