From a3bdd62a5885a47b2b058c82423611351b60561a Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 13 Feb 2023 16:16:05 +0000 Subject: [PATCH] Fix the f64 round-tripping bug --- geom/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geom/src/lib.rs b/geom/src/lib.rs index a28af71601..da8b751f8e 100644 --- a/geom/src/lib.rs +++ b/geom/src/lib.rs @@ -56,8 +56,8 @@ pub fn trim_f64(x: f64) -> f64 { /// Serializes a trimmed `f64` as an `i32` to save space. fn serialize_f64(x: &f64, s: S) -> Result { // So a trimmed f64's range becomes 2**31 / 10,000 =~ 214,000, which is plenty - // We don't need to round() here; trim_f64 already handles that. - let int = (x * 10_000.0) as i32; + // We MUST round here, the same as trim_f64. The unit test demonstrates why. + let int = (x * 10_000.0).round() as i32; int.serialize(s) }