Remove max significant digits and zero cutoff checks in float formatting functions for improved simplicity and performance. This change streamlines the format_f32 and format_f64 functions, enhancing the overall efficiency of float serialization in JSON.

This commit is contained in:
Joe 2026-02-18 10:35:17 -06:00
parent b8a1dc269c
commit f59392581e

View file

@ -147,7 +147,6 @@ const F64_FLOAT_OPTIONS: Options = Options::builder()
.inf_string(Some(b"Infinity")) .inf_string(Some(b"Infinity"))
.positive_exponent_break(SCI_POSITIVE_BREAK) .positive_exponent_break(SCI_POSITIVE_BREAK)
.negative_exponent_break(SCI_NEGATIVE_BREAK) .negative_exponent_break(SCI_NEGATIVE_BREAK)
.max_significant_digits(NonZeroUsize::new(15))
.round_mode(RoundMode::Round) .round_mode(RoundMode::Round)
.build_strict(); .build_strict();
@ -163,9 +162,6 @@ fn format_f32(v: f32) -> String {
} }
fn format_f64(v: f64) -> String { fn format_f64(v: f64) -> String {
if v.is_finite() && v.abs() >= 1e308 {
return format!("{v:e}");
}
let mut buffer = [0u8; F64_BUF_SIZE]; let mut buffer = [0u8; F64_BUF_SIZE];
let digits = v.to_lexical_with_options::<STANDARD>(&mut buffer, &F64_FLOAT_OPTIONS); let digits = v.to_lexical_with_options::<STANDARD>(&mut buffer, &F64_FLOAT_OPTIONS);
std::str::from_utf8(digits) std::str::from_utf8(digits)