|
16 | 16 |
|
17 | 17 | use approx::AbsDiffEq; |
18 | 18 | use num::complex::Complex; |
19 | | -use num::integer::sqrt; |
20 | 19 | pub use num::traits::identities::{One, Zero}; |
21 | 20 | use num::{integer, Integer, Rational64}; |
22 | 21 | use std::cmp::min; |
@@ -175,8 +174,8 @@ impl<T: Coeffs> Scalar<T> { |
175 | 174 | if coeffs.len() == 4 { |
176 | 175 | // cases where the phase is a multiple of 1/4 are handled exactly |
177 | 176 | match coeffs.iter_coeffs().collect::<Vec<_>>().as_slice() { |
178 | | - [a, b, 0, c] if -b == *c => { |
179 | | - return Phase::new(((-a - b * sqrt(2)).signum() as i64 + 1) / 2) |
| 177 | + [_, b, 0, c] if -b == *c => { |
| 178 | + return Phase::new(if self.complex_value().re > 0.0 { 0 } else { 1 }) |
180 | 179 | } |
181 | 180 | [0, c, 0, 0] => { |
182 | 181 | return Phase::new(Rational64::new(if *c > 0 { 1 } else { 5 }, 4)) |
@@ -810,8 +809,16 @@ mod tests { |
810 | 809 | #[case(ScalarN::from_int_coeffs(&[-2, 0, -2, 0]))] |
811 | 810 | #[case(ScalarN::from_int_coeffs(&[0, 1, 0, 1]))] |
812 | 811 | #[case(ScalarN::from_int_coeffs(&[0, 1, 0, -1]))] |
| 812 | + #[case(ScalarN::from_int_coeffs(&[0, -1, 0, 1]))] |
813 | 813 | #[case(ScalarN::from_int_coeffs(&[0, -2, 0, -2]))] |
814 | 814 | #[case(ScalarN::from_int_coeffs(&[0, 2, 0, -2]))] |
| 815 | + #[case(ScalarN::from_int_coeffs(&[1, 1, 0, -1]))] |
| 816 | + #[case(ScalarN::from_int_coeffs(&[1, 1, 0, 1]))] |
| 817 | + #[case(ScalarN::from_int_coeffs(&[1, -1, 0, 1]))] |
| 818 | + #[case(ScalarN::from_int_coeffs(&[1, 1, 0, -1]))] |
| 819 | + #[case(ScalarN::from_int_coeffs(&[2, -1, 0, 1]))] |
| 820 | + #[case(ScalarN::from_int_coeffs(&[-2, 1, 0, 1]))] |
| 821 | + #[case(ScalarN::from_int_coeffs(&[2, 2, 0, -2]))] |
815 | 822 | #[case(ScalarN::from_int_coeffs(&[-1, 2, 3, -4]))] |
816 | 823 | fn get_phase(#[case] s: ScalarN) { |
817 | 824 | assert_abs_diff_eq!(s.phase().to_f64(), s.complex_value().arg() / PI); |
|
0 commit comments