1- /* Format an f64 to a Python-display string (NaN, ±inf, ±0.0,
2- whole-number floats with trailing ".0", else Rust's default). */
1+ /* f64 -> Python-style string: nan/±inf/±0.0/whole->".0" suffix/else default. */
32pub fn format_f64 ( f : f64 ) -> alloc:: string:: String {
4- // Lowercase per CPython repr/str semantics (was "NaN" — capitalised mismatch) .
3+ // Lowercase per CPython semantics; "NaN" was a mismatch.
54 if f. is_nan ( ) { return alloc:: string:: String :: from ( "nan" ) ; }
65 if f == f64:: INFINITY { return alloc:: string:: String :: from ( "inf" ) ; }
76 if f == f64:: NEG_INFINITY { return alloc:: string:: String :: from ( "-inf" ) ; }
87 if f == 0.0 {
98 return if f. is_sign_negative ( ) { alloc:: string:: String :: from ( "-0.0" ) } else { alloc:: string:: String :: from ( "0.0" ) } ;
109 }
1110
12- // Whole-number floats : itoa + ".0" avoids Rust's "1" output for 1.0.
11+ // Whole float : itoa + ".0" avoids Rust's bare "1" for 1.0.
1312 const I64_UPPER : f64 = i64:: MAX as f64 ;
1413 if f. is_finite ( ) && f >= ( i64:: MIN as f64 ) && f < I64_UPPER && f == ( f as i64 ) as f64 {
1514 let mut b = itoa:: Buffer :: new ( ) ;
@@ -23,7 +22,7 @@ pub fn format_f64(f: f64) -> alloc::string::String {
2322 format_general ( f)
2423}
2524
26- /* 32-byte stack buffer is enough for any f64 in default formatting . */
25+ /* 32-byte stack buffer fits any f64 default format . */
2726fn format_general ( f : f64 ) -> alloc:: string:: String {
2827 let mut buf = FmtBuf :: new ( ) ;
2928 let _ = core:: fmt:: write ( & mut buf, core:: format_args!( "{}" , f) ) ;
@@ -71,8 +70,7 @@ macro_rules! s {
7170 ( $( $t: tt) * ) => { { let mut _s = alloc:: string:: String :: new( ) ; $crate:: s!( @b _s; $( $t) * ) ; _s } } ;
7271}
7372
74- /* Format little-endian base-10⁹ digit groups as a decimal string.
75- Highest group is unpadded; the rest are zero-padded to width 9. */
73+ /* Formats little-endian base-10⁹ groups as decimal; highest unpadded, rest zero-padded to 9. */
7674pub fn format_dec_groups ( groups : & [ u32 ] ) -> alloc:: string:: String {
7775 let mut out = alloc:: string:: String :: new ( ) ;
7876 for ( i, & g) in groups. iter ( ) . rev ( ) . enumerate ( ) {
0 commit comments