From e34c31bf02eb0f0ff4dd43ae72e0eae53f2ac519 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 1 Feb 2018 18:35:51 +0000 Subject: Use constant for 180/π in to_degrees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current `f32|f64.to_degrees` implementation uses a division to calculate 180/π, which causes a loss of precision. Using a constant is still not perfect (implementing a maximally-precise algorithm would come with a high performance cost), but improves precision with a minimal change. --- src/libstd/f32.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd') diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 9810dede618..ecf68f29d6f 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1531,6 +1531,7 @@ mod tests { assert!(nan.to_degrees().is_nan()); assert_eq!(inf.to_degrees(), inf); assert_eq!(neg_inf.to_degrees(), neg_inf); + assert_eq!(1_f32.to_degrees(), 57.2957795130823208767981548141051703); } #[test] -- cgit 1.4.1-3-g733a5