Skip to main content

oxilean_std/spectral_methods/
complex_traits.rs

1//! # Complex - Trait Implementations
2//!
3//! This module contains trait implementations for `Complex`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Add`
8//! - `Sub`
9//! - `Mul`
10//! - `Mul`
11//! - `Div`
12//!
13//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
14
15use super::types::Complex;
16
17impl std::ops::Add for Complex {
18    type Output = Complex;
19    fn add(self, rhs: Complex) -> Complex {
20        Complex::new(self.re + rhs.re, self.im + rhs.im)
21    }
22}
23
24impl std::ops::Sub for Complex {
25    type Output = Complex;
26    fn sub(self, rhs: Complex) -> Complex {
27        Complex::new(self.re - rhs.re, self.im - rhs.im)
28    }
29}
30
31impl std::ops::Mul for Complex {
32    type Output = Complex;
33    fn mul(self, rhs: Complex) -> Complex {
34        Complex::new(
35            self.re * rhs.re - self.im * rhs.im,
36            self.re * rhs.im + self.im * rhs.re,
37        )
38    }
39}
40
41impl std::ops::Mul<f64> for Complex {
42    type Output = Complex;
43    fn mul(self, s: f64) -> Complex {
44        Complex::new(self.re * s, self.im * s)
45    }
46}
47
48impl std::ops::Div<f64> for Complex {
49    type Output = Complex;
50    fn div(self, s: f64) -> Complex {
51        Complex::new(self.re / s, self.im / s)
52    }
53}