use crate::algebra::abstr::{Complex, Real, Sign};
use std::{f32, f64};
pub trait Exponential {
fn e() -> Self;
fn exp(self) -> Self;
fn ln(self) -> Self;
}
macro_rules! exponential_impl {
($t:ty, $e: expr) => {
impl Exponential for $t {
fn e() -> Self {
$e
}
fn exp(self) -> Self {
self.exp()
}
fn ln(self) -> Self {
self.ln()
}
}
};
}
exponential_impl!(f32, f32::consts::E);
exponential_impl!(f64, f64::consts::E);
impl<T> Exponential for Complex<T>
where
T: Real,
{
fn e() -> Self {
Complex {
re: T::e(),
im: T::zero(),
}
}
fn exp(self) -> Self {
let k: T = self.re.exp();
Complex {
re: k * self.im.cos(),
im: k * self.im.sin(),
}
}
fn ln(self) -> Self {
Complex {
re: self.abs().re.ln(),
im: self.arg().re,
}
}
}