From 17cf71f22bc3978cb50f21c50367f108aa8f9ee9 Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Thu, 17 Dec 2020 11:39:32 -0800 Subject: [PATCH] atan2: replace min, max with x, y --- dsp/src/trig.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dsp/src/trig.rs b/dsp/src/trig.rs index 5d73846..13ce844 100644 --- a/dsp/src/trig.rs +++ b/dsp/src/trig.rs @@ -48,9 +48,11 @@ pub fn atan2(y: i32, x: i32) -> i32 { // // which is taken from Rajan 2006: Efficient Approximations for // the Arctangent Function. - let (min, max) = if y_greater { (x, y) } else { (y, x) }; + if y_greater { + core::mem::swap(&mut x, &mut y); + } - if max == 0 { + if x == 0 { return 0; } @@ -61,7 +63,7 @@ pub fn atan2(y: i32, x: i32) -> i32 { // number of atan argument bits beyond 15 because we must square // it. const ATAN_ARGUMENT_BITS: usize = 15; - let ratio = (min << ATAN_ARGUMENT_BITS) / max; + let ratio = (y << ATAN_ARGUMENT_BITS) / x; let mut angle = { const K1: i32 = ((1. / 4. + 0.285 / PI)