iir1
Loading...
Searching...
No Matches
MathSupplement.h
1
36#ifndef IIR1_MATHSUPPLEMENT_H
37#define IIR1_MATHSUPPLEMENT_H
38
39#include "Common.h"
40
41#include<complex>
42
43#ifdef _MSC_VER
44 // Under Unix these have already default instantiations but not under Vis Studio
45template class DllExport std::complex<double>;
46template class DllExport std::complex<float>;
47#endif
48
49namespace Iir {
50
51const double doublePi =3.1415926535897932384626433832795028841971;
52const double doublePi_2 =1.5707963267948966192313216916397514420986;
53const double doubleLn2 =0.69314718055994530941723212145818;
54const double doubleLn10 =2.3025850929940456840179914546844;
55
56typedef std::complex<double> complex_t;
57typedef std::pair<complex_t, complex_t> complex_pair_t;
58
59template<typename Real>
60inline std::complex<Real> solve_quadratic_1 (Real a, Real b, Real c)
61{
62 return (-b + sqrt (std::complex<Real> (b*b - 4*a*c, 0))) / (2. * a);
63}
64
65template<typename Real>
66inline std::complex<Real> solve_quadratic_2 (Real a, Real b, Real c)
67{
68 return (-b - sqrt (std::complex<Real> (b*b - 4*a*c, 0))) / (2. * a);
69}
70
71inline const complex_t infinity()
72{
73 return complex_t (std::numeric_limits<double>::infinity());
74}
75
76inline const complex_t adjust_imag (const complex_t& c)
77{
78 if (fabs (c.imag()) < 1e-30)
79 return complex_t (c.real(), 0);
80 else
81 return c;
82}
83
84template <typename Ty, typename To>
85inline std::complex<Ty> addmul (const std::complex<Ty>& c,
86 Ty v,
87 const std::complex<To>& c1)
88{
89 return std::complex <Ty> (
90 c.real() + v * c1.real(), c.imag() + v * c1.imag());
91}
92
93template <typename Ty>
94inline std::complex<Ty> recip (const std::complex<Ty>& c)
95{
96 Ty n = 1.0 / std::norm (c);
97
98 return std::complex<Ty> (n * c.real(), n * c.imag());
99}
100
101template <typename Ty>
102inline Ty asinh (Ty x)
103{
104 return log (x + std::sqrt (x * x + 1 ));
105}
106
107template <typename Ty>
108inline Ty acosh (Ty x)
109{
110 return log (x + std::sqrt (x * x - 1));
111}
112
113template <typename Ty>
114inline bool is_nan (Ty v)
115{
116 return !(v == v);
117}
118
119template <>
120inline bool is_nan<complex_t> (complex_t v)
121{
122 return Iir::is_nan (v.real()) || Iir::is_nan (v.imag());
123}
124
125}
126
127#endif
Definition: Biquad.cpp:40