Skip to content

Commit

Permalink
Fix the f64 round-tripping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Feb 13, 2023
1 parent 106dbd1 commit a3bdd62
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions geom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ pub fn trim_f64(x: f64) -> f64 {
/// Serializes a trimmed `f64` as an `i32` to save space.
fn serialize_f64<S: Serializer>(x: &f64, s: S) -> Result<S::Ok, S::Error> {
// 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)
}

Expand Down

0 comments on commit a3bdd62

Please sign in to comment.