ohsl/complex/
trigonometric.rs1use crate::complex::{Complex, Cmplx};
2use crate::traits::One;
3use crate::constant::{I, PI_2};
4
5impl Complex::<f64> {
6 #[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 #[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 #[inline]
20 pub fn tan(&self) -> Complex<f64> {
21 self.sin() / self.cos()
22 }
23
24 #[inline]
26 pub fn sec(&self) -> Complex<f64> {
27 Complex::<f64>::one() / self.cos()
28 }
29
30 #[inline]
32 pub fn csc(&self) -> Complex<f64> {
33 Complex::<f64>::one() / self.sin()
34 }
35
36 #[inline]
38 pub fn cot(&self) -> Complex<f64> {
39 Complex::<f64>::one() / self.tan()
40 }
41
42 #[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 #[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 #[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 #[inline]
65 pub fn asec(&self) -> Complex<f64> {
66 let inv = Cmplx::one() / self.clone();
67 inv.acos()
68 }
69
70 #[inline]
72 pub fn acsc(&self) -> Complex<f64> {
73 let inv = Cmplx::one() / self.clone();
74 inv.asin()
75 }
76
77 #[inline]
79 pub fn acot(&self) -> Complex<f64> {
80 let inv = Cmplx::one() / self.clone();
81 inv.atan()
82 }
83}