|
@@ -195,13 +195,6 @@ impl<T: Float + Numeric + Primitive> PartialEq for Complex<T> {
|
|
|
}
|
|
|
|
|
|
impl<T: Float + Primitive + Numeric> Float for Complex<T> {
|
|
|
- fn abs(self) -> Self {
|
|
|
- Self {
|
|
|
- r: (self.r * self.r + self.i * self.i).sqrt(),
|
|
|
- i: unsafe { T::whole(0) },
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
fn sqrt(self) -> Self {
|
|
|
let zero = unsafe { T::whole(0) };
|
|
|
let two = unsafe { T::whole(2) };
|
|
@@ -261,6 +254,13 @@ impl<T: Float + Numeric + Primitive> Numeric for Complex<T> {
|
|
|
unsafe fn whole(value: u32) -> Self {
|
|
|
Self { r: T::whole(value), i: T::whole(0) }
|
|
|
}
|
|
|
+
|
|
|
+ fn abs(self) -> Self {
|
|
|
+ Self {
|
|
|
+ r: (self.r * self.r + self.i * self.i).sqrt(),
|
|
|
+ i: unsafe { T::whole(0) },
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[cfg(test)]
|
|
@@ -292,7 +292,7 @@ mod tests {
|
|
|
#[test]
|
|
|
fn square_root_with_negatives() {
|
|
|
let a = Complex { r: -1.0, i: -1.0 };
|
|
|
- let root = a.sqrt();
|
|
|
+ let root: Complex<f64> = a.sqrt();
|
|
|
let expected = Complex { r: 0.45508986, i: -1.09868411 };
|
|
|
assert!((root.r - expected.r).abs() < 0.00001);
|
|
|
assert!((root.i - expected.i).abs() < 0.00001);
|