From 6f8eab114cae9b2395314f83777829fa07889b9e Mon Sep 17 00:00:00 2001 From: Felix Teutloff Date: Fri, 5 Dec 2025 18:47:16 +0100 Subject: [PATCH] "distributed" multiplication in deg2hms to avoid rounding error due to floating point errors. --- src/spatial.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spatial.rs b/src/spatial.rs index b57ef8a..3287c0b 100644 --- a/src/spatial.rs +++ b/src/spatial.rs @@ -78,7 +78,7 @@ pub fn deg2hms(deg: f64) -> String { let h = deg * 12.0 / 180.0; let hours = h.floor() as i32; - let m = (h - hours as f64) * 60.0; + let m = h * 60.0 - hours as f64 * 60.0; let minutes = m.floor() as i32; let seconds = (m - minutes as f64) * 60.0; let hms = format!("{:02.0}:{:02.0}:{:07.4}", hours, minutes, seconds);