use crate::complex::{Complex, Cmplx};
use crate::traits::One;
use crate::constant::{I, PI_2};
impl Complex::<f64> {
#[inline]
pub fn sin(&self) -> Complex<f64> {
Cmplx::new(self.real.sin() * self.imag.cosh(), self.real.cos() * self.imag.sinh())
}
#[inline]
pub fn cos(&self) -> Complex<f64> {
Cmplx::new(self.real.cos() * self.imag.cosh(), -self.real.sin() * self.imag.sinh())
}
#[inline]
pub fn tan(&self) -> Complex<f64> {
self.sin() / self.cos()
}
#[inline]
pub fn sec(&self) -> Complex<f64> {
Complex::<f64>::one() / self.cos()
}
#[inline]
pub fn csc(&self) -> Complex<f64> {
Complex::<f64>::one() / self.sin()
}
#[inline]
pub fn cot(&self) -> Complex<f64> {
Complex::<f64>::one() / self.tan()
}
#[inline]
pub fn asin(&self) -> Complex<f64> {
let squared = self.clone() * self.clone();
- I * ((Cmplx::one() - squared).sqrt() + I * self.clone()).ln()
}
#[inline]
pub fn acos(&self) -> Complex<f64> {
let squared = self.clone() * self.clone();
I * ((Cmplx::one() - squared).sqrt() + I * self.clone()).ln() + PI_2
}
#[inline]
pub fn atan(&self) -> Complex<f64> {
let iz = I * self.clone();
( (Cmplx::one() - iz).ln() - (Cmplx::one() + iz).ln() ) * I * 0.5
}
#[inline]
pub fn asec(&self) -> Complex<f64> {
let inv = Cmplx::one() / self.clone();
inv.acos()
}
#[inline]
pub fn acsc(&self) -> Complex<f64> {
let inv = Cmplx::one() / self.clone();
inv.asin()
}
#[inline]
pub fn acot(&self) -> Complex<f64> {
let inv = Cmplx::one() / self.clone();
inv.atan()
}
}