template math functions in pimathmatrix.h and pimathvector.h and pimathbase.h

add PIMathMatrixT::rotate for matrix 2x2
This commit is contained in:
2020-10-22 17:29:58 +03:00
parent f5652efc32
commit fbe850abf0
4 changed files with 34 additions and 20 deletions

View File

@@ -98,9 +98,6 @@ const double rad2deg = M_180_PI;
inline int sign(const float & x) {return (x < 0.) ? -1 : (x > 0. ? 1 : 0);}
inline int sign(const double & x) {return (x < 0.) ? -1 : (x > 0. ? 1 : 0);}
inline int pow2(const int p) {return 1 << p;}
inline int sqr(const int v) {return v * v;}
inline float sqr(const float & v) {return v * v;}
inline double sqr(const double & v) {return v * v;}
inline double sinc(const double & v) {if (v == 0.) return 1.; double t = M_PI * v; return sin(t) / t;}
PIP_EXPORT double piJ0(const double & v);
@@ -109,22 +106,23 @@ PIP_EXPORT double piJn(int n, const double & v);
PIP_EXPORT double piY0(const double & v);
PIP_EXPORT double piY1(const double & v);
PIP_EXPORT double piYn(int n, const double & v);
inline double toDb(double val) {return 10. * log10(val);}
inline double fromDb(double val) {return pow(10., val / 10.);}
inline double toRad(double deg) {return deg * M_PI_180;}
inline double toDeg(double rad) {return rad * M_180_PI;}
template <typename T> inline constexpr T toDb(T val) {return T(10.) * std::log10(val);}
template <typename T> inline constexpr T fromDb(T val) {return std::pow(T(10.), val / T(10.));}
template <typename T> inline constexpr T toRad(T deg) {return deg * T(M_PI_180);}
template <typename T> inline constexpr T toDeg(T rad) {return rad * T(M_180_PI);}
template <typename T> inline constexpr T sqr(const T & v) {return v * v;}
// [-1 ; 1]
PIP_EXPORT double randomd();
// [-1 ; 1] normal
PIP_EXPORT double randomn(double dv = 0., double sv = 1.);
inline PIVector<double> abs(const PIVector<double> & v) {
PIVector<double> result;
template<typename T> inline PIVector<T> piAbs(const PIVector<T> & v) {
PIVector<T> result;
result.resize(v.size());
for (uint i = 0; i < v.size(); i++)
result[i] = fabs(v[i]);
result[i] = piAbs<T>(v[i]);
return result;
}