diff --git a/complex.hh b/complex.hh index cc64a34..ae090cc 100644 --- a/complex.hh +++ b/complex.hh @@ -13,11 +13,11 @@ class Complex T re, im; public: typedef T value_type; - Complex() : re(0), im(0) {} - Complex(T r) : re(r), im(0) {} - Complex(T r, T i) : re(r), im(i) {} - inline T real() const { return re; } - inline T imag() const { return im; } + constexpr Complex() : re(0), im(0) {} + constexpr Complex(T r) : re(r), im(0) {} + constexpr Complex(T r, T i) : re(r), im(i) {} + constexpr T real() const { return re; } + constexpr T imag() const { return im; } inline void real(T r) { re = r; } inline void imag(T i) { im = i; } inline Complex operator = (T a) @@ -53,74 +53,74 @@ public: }; template -static inline Complex operator + (Complex a, Complex b) +static constexpr Complex operator + (Complex a, Complex b) { return Complex(a.real() + b.real(), a.imag() + b.imag()); } template -static inline Complex operator + (Complex a) +static constexpr Complex operator + (Complex a) { return a; } template -static inline Complex operator - (Complex a, Complex b) +static constexpr Complex operator - (Complex a, Complex b) { return Complex(a.real() - b.real(), a.imag() - b.imag()); } template -static inline Complex operator - (Complex a) +static constexpr Complex operator - (Complex a) { return Complex(-a.real(), -a.imag()); } template -static inline Complex operator * (T a, Complex b) +static constexpr Complex operator * (T a, Complex b) { return Complex(a * b.real(), a * b.imag()); } template -static inline Complex operator / (Complex a, T b) +static constexpr Complex operator / (Complex a, T b) { return Complex(a.real() / b, a.imag() / b); } template -static inline Complex operator * (Complex a, Complex b) +static constexpr Complex operator * (Complex a, Complex b) { return Complex(a.real() * b.real() - a.imag() * b.imag(), a.real() * b.imag() + a.imag() * b.real()); } template -static inline Complex operator / (Complex a, Complex b) +static constexpr Complex operator / (Complex a, Complex b) { return Complex((a.real() * b.real() + a.imag() * b.imag()) / (b.real() * b.real() + b.imag() * b.imag()), (a.imag() * b.real() - a.real() * b.imag()) / (b.real() * b.real() + b.imag() * b.imag())); } template -static inline Complex exp(Complex a) +static constexpr Complex exp(Complex a) { return Complex(exp(a.real()) * cos(a.imag()), exp(a.real()) * sin(a.imag())); } template -static inline T abs(Complex a) +static constexpr T abs(Complex a) { return hypot(a.real(), a.imag()); } template -static inline T arg(Complex a) +static constexpr T arg(Complex a) { return atan2(a.imag(), a.real()); } template -static inline T norm(Complex a) +static constexpr T norm(Complex a) { return a.real() * a.real() + a.imag() * a.imag(); }