use crate::RealField;
mod algebra;
mod arithmetic;
mod cast;
mod display;
mod identity;
mod ops;
mod ops_shared;
mod rotation;
#[derive(Copy, Clone, PartialEq, Default, Debug)]
pub struct Complex<T: RealField> {
pub re: T,
pub im: T,
}
impl<T: RealField> Eq for Complex<T> {}
impl<T: RealField> PartialOrd for Complex<T> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
match self.re.partial_cmp(&other.re) {
Some(core::cmp::Ordering::Equal) => self.im.partial_cmp(&other.im),
ord => ord,
}
}
}
impl<T: RealField + Ord> Ord for Complex<T> {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
match self.re.cmp(&other.re) {
core::cmp::Ordering::Equal => self.im.cmp(&other.im),
ord => ord,
}
}
}
pub type Complex32 = Complex<f32>;
pub type Complex64 = Complex<f64>;
impl<T: RealField> Complex<T> {
#[inline]
pub fn new(re: T, im: T) -> Self {
Self { re, im }
}
#[inline]
pub fn from_real(re: T) -> Self {
Self { re, im: T::zero() }
}
}
impl<T: RealField> Complex<T> {
#[inline]
pub fn re(&self) -> T {
self.re
}
#[inline]
pub fn im(&self) -> T {
self.im
}
}