oxiphysics_core/complex/
complex_traits.rs1#[allow(unused_imports)]
16use super::functions::*;
17use std::ops::{Add, Div, Mul, Neg, Sub};
18
19use super::types::Complex;
20
21impl Add for Complex {
22 type Output = Self;
23 fn add(self, rhs: Self) -> Self {
24 Self::new(self.re + rhs.re, self.im + rhs.im)
25 }
26}
27
28impl Sub for Complex {
29 type Output = Self;
30 fn sub(self, rhs: Self) -> Self {
31 Self::new(self.re - rhs.re, self.im - rhs.im)
32 }
33}
34
35impl Mul for Complex {
36 type Output = Self;
37 fn mul(self, rhs: Self) -> Self {
38 Self::new(
39 self.re * rhs.re - self.im * rhs.im,
40 self.re * rhs.im + self.im * rhs.re,
41 )
42 }
43}
44
45impl Div for Complex {
46 type Output = Self;
47 fn div(self, rhs: Self) -> Self {
48 let denom = rhs.norm_sq();
49 Self::new(
50 (self.re * rhs.re + self.im * rhs.im) / denom,
51 (self.im * rhs.re - self.re * rhs.im) / denom,
52 )
53 }
54}
55
56impl Neg for Complex {
57 type Output = Self;
58 fn neg(self) -> Self {
59 Self::new(-self.re, -self.im)
60 }
61}