From b8a1dc269c3eeb9b009272917f052c6bcc9778ee Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 18 Feb 2026 10:33:19 -0600 Subject: [PATCH] Remove 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. --- src/json.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/json.rs b/src/json.rs index 0c8c3c65..9b3da17a 100644 --- a/src/json.rs +++ b/src/json.rs @@ -153,13 +153,8 @@ const F64_FLOAT_OPTIONS: Options = Options::builder() const F32_BUF_SIZE: usize = F32_FLOAT_OPTIONS.buffer_size_const::(); const F64_BUF_SIZE: usize = F64_FLOAT_OPTIONS.buffer_size_const::(); -const F32_ZERO_CUTOFF: f64 = 1e-6; -const F64_ZERO_CUTOFF: f64 = 1e-15; fn format_f32(v: f32) -> String { - if (v as f64).abs() < F32_ZERO_CUTOFF { - return "0".into(); - } let mut buffer = [0u8; F32_BUF_SIZE]; let digits = v.to_lexical_with_options::(&mut buffer, &F32_FLOAT_OPTIONS); std::str::from_utf8(digits) @@ -168,9 +163,6 @@ fn format_f32(v: f32) -> String { } fn format_f64(v: f64) -> String { - if v.abs() < F64_ZERO_CUTOFF { - return "0".into(); - } if v.is_finite() && v.abs() >= 1e308 { return format!("{v:e}"); }