Skip to main content

ohsl/complex/
trigonometric.rs

1use crate::complex::{Complex, Cmplx};
2use crate::traits::One;
3use crate::constant::{I, PI_2};
4
5impl Complex::<f64> {
6    ///Return the sin of a complex number z ( sin(z) )
7    #[inline]
8    pub fn sin(&self) -> Complex<f64> {
9        Cmplx::new(self.real.sin() * self.imag.cosh(), self.real.cos() * self.imag.sinh())
10    }
11
12    ///Return the cos of a complex number z ( cos(z) )
13    #[inline]
14    pub fn cos(&self) -> Complex<f64> {
15        Cmplx::new(self.real.cos() * self.imag.cosh(), -self.real.sin() * self.imag.sinh())
16    }
17
18    ///Return the tan of a complex number z ( tan(z) )
19    #[inline]
20    pub fn tan(&self) -> Complex<f64> {
21        self.sin() / self.cos()
22    }
23
24    ///Return the sec of a complex number z ( sec(z) )
25    #[inline]
26    pub fn sec(&self) -> Complex<f64> {
27        Complex::<f64>::one() / self.cos()
28    }
29
30    ///Return the csc of a complex number z ( csc(z) )
31    #[inline]
32    pub fn csc(&self) -> Complex<f64> {
33        Complex::<f64>::one() / self.sin()
34    }
35    
36    ///Return the cot of a complex number z ( cot(z) )
37    #[inline]
38    pub fn cot(&self) -> Complex<f64> {
39        Complex::<f64>::one() / self.tan()
40    }
41
42    /// Return the inverse sin of a complex number z ( asin(z) )
43    #[inline]
44    pub fn asin(&self) -> Complex<f64> {
45        let squared = self.clone() * self.clone();
46        - I * ((Cmplx::one() - squared).sqrt() + I * self.clone()).ln()
47    }
48
49    /// Return the inverse cos of a complex number z ( acos(z) )
50    #[inline]
51    pub fn acos(&self) -> Complex<f64> {
52        let squared = self.clone() * self.clone();
53        I * ((Cmplx::one() - squared).sqrt() + I * self.clone()).ln() + PI_2
54    }
55
56    /// Return the inverse tan of a complex number z ( atan(z) )
57    #[inline]
58    pub fn atan(&self) -> Complex<f64> {
59        let iz = I * self.clone();
60        ( (Cmplx::one() - iz).ln() - (Cmplx::one() + iz).ln() ) * I * 0.5
61    }
62
63    /// Return the inverse sec of a complex number z ( asec(z) )
64    #[inline]
65    pub fn asec(&self) -> Complex<f64> {
66        let inv = Cmplx::one() / self.clone();
67        inv.acos()
68    }
69
70    /// Return the inverse csc of a complex number z ( acsc(z) )
71    #[inline]
72    pub fn acsc(&self) -> Complex<f64> {
73        let inv = Cmplx::one() / self.clone();
74        inv.asin()
75    }
76
77    /// Return the inverse cot of a complex number z ( acot(z) )
78    #[inline]
79    pub fn acot(&self) -> Complex<f64> {
80        let inv = Cmplx::one() / self.clone();
81        inv.atan()
82    }
83}