eDSP  0.0.1
A cross-platform DSP library written in C++.
complex.hpp
Go to the documentation of this file.
1 /*
2  * eDSP, A cross-platform Digital Signal Processing library written in modern C++.
3  * Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi, All rights reserved.
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation, either version 3 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along width
16  * this program. If not, see <http://www.gnu.org/licenses/>
17  *
18  * File: complex.hpp
19  * Author: Mohammed Boujemaoui
20  * Date: 2018-07-29
21  */
22 
23 #ifndef EDSP_COMPLEX_H
24 #define EDSP_COMPLEX_H
25 
26 #include <edsp/meta/unused.hpp>
27 #include <edsp/math/numeric.hpp>
28 #include <limits>
29 #include <complex>
30 #include <cmath>
31 
32 namespace edsp { inline namespace math {
33 
39  template <typename T>
40  constexpr T magnitude(const std::complex<T>& z) {
41  return std::abs(z);
42  }
43 
49  template <typename T>
50  constexpr T phase(const std::complex<T>& z) {
51  return std::arg(z);
52  }
53 
59  template <typename T>
60  constexpr T real(const std::complex<T>& z) {
61  return std::real(z);
62  }
63 
69  template <typename T>
70  constexpr T imag(const std::complex<T>& z) {
71  return std::imag(z);
72  }
73 
79  template <typename T>
80  constexpr std::complex<T> conj(const std::complex<T>& z) {
81  return std::conj(z);
82  }
83 
89  template <typename T>
90  constexpr auto is_nan(const std::complex<T>& z) noexcept {
91  return std::isnan(z.real()) || std::isnan(z.imag());
92  }
93 
99  template <typename T>
100  constexpr auto is_inf(const std::complex<T>& z) noexcept {
101  return std::isinf(z.real()) || std::isinf(z.imag());
102  }
103 
108  template <typename T>
109  constexpr std::complex<T> infinity() noexcept {
111  }
112 
113 }} // namespace edsp::math
114 
115 #endif
constexpr auto is_inf(const std::complex< T > &z) noexcept
Determines if the given real or imaginary part of the complex number is .
Definition: complex.hpp:100
constexpr T real(const std::complex< T > &z)
Computes the real component of the complex number z.
Definition: complex.hpp:60
constexpr T imag(const std::complex< T > &z)
Computes the imaginary component of the complex number z.
Definition: complex.hpp:70
constexpr T phase(const std::complex< T > &z)
Computes the phase of the complex number z.
Definition: complex.hpp:50
constexpr T magnitude(const std::complex< T > &z)
Computes the magnitude of the complex number z.
Definition: complex.hpp:40
constexpr std::complex< T > conj(const std::complex< T > &z)
Computes the complex conjugate of the complex number z.
Definition: complex.hpp:80
constexpr auto is_nan(const std::complex< T > &z) noexcept
Determines if the given real or imaginary part of the complex number is a not-a-number (NaN) value...
Definition: complex.hpp:90
Definition: amplifier.hpp:29
constexpr std::complex< T > infinity() noexcept
Computes an complex number.
Definition: complex.hpp:109