Compare commits

2 Commits

Author SHA1 Message Date
c971550535 pimathfloatnullcompare 2020-09-26 19:46:34 +03:00
a42e5a7756 template experiment, PIMutex recursive in all systems 2020-09-25 14:34:07 +03:00
3 changed files with 32 additions and 37 deletions

View File

@@ -117,4 +117,33 @@ inline PIVector2D<double> abs(const PIVector2D<complexd> & v) {
return result;
}
/**
* @brief Inline funtion of compare with zero different types
*
* @param v is input parameter of type T
* @return true if zero, false if not zero
*/
template<typename T, typename std::enable_if<std::is_floating_point<T>::value, int>::type = 0>
inline bool PIMathFloatNullCompare(const T v) {
static_assert(std::is_floating_point<T>::value, "Type must be floating point");
return (piAbs(v) < T(1E-200));
}
/**
* @brief Inline funtion of compare with zero colmplexf type
*
* @param v is input parameter of type colmplexf
* @return true if zero, false if not zero
*/
template<typename T,typename std::enable_if<
std::is_floating_point<decltype(T::real)>::value ||
std::is_floating_point<decltype(T::imag)>::value
, int>::type = 0>
inline bool PIMathFloatNullCompare(const T v) {
static_assert(std::is_floating_point<decltype(v.real)>::value, "Type must be floating point");
static_assert(std::is_floating_point<decltype(v.imag)>::value, "Type must be floating point");
return (abs(v) < float(1E-200));
}
#endif // PIMATHCOMPLEX_H

View File

@@ -28,40 +28,6 @@
#include "pimathvector.h"
#include "pimathcomplex.h"
/**
* @brief Inline funtion of compare with zero different types
*
* @param v is input parameter of type T
* @return true if zero, false if not zero
*/
template<typename T>
inline bool _PIMathMatrixNullCompare(const T v) {
static_assert(std::is_floating_point<T>::value, "Type must be floating point");
return (piAbs(v) < T(1E-200));
}
/**
* @brief Inline funtion of compare with zero colmplexf type
*
* @param v is input parameter of type colmplexf
* @return true if zero, false if not zero
*/
template<>
inline bool _PIMathMatrixNullCompare<complexf>(const complexf v) {
return (abs(v) < float(1E-200));
}
/**
* @brief Inline funtion of compare with zero complexd type
*
* @param v is input parameter of type colmplexd
* @return true if zero, false if not zero
*/
template<>
inline bool _PIMathMatrixNullCompare<complexd>(const complexd v) {
return (abs(v) < double(1E-200));
}
/// Matrix templated
@@ -1225,7 +1191,7 @@ public:
for (uint k = i; k < _V2D::cols_; ++k) smat.element(k, j) -= mul * smat.element(k, i);
}
if (i < _V2D::cols_ - 1) {
if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) {
if (PIMathFloatNullCompare(smat.element(i + 1, i + 1))) {
if (ok != 0) *ok = false;
return *this;
}
@@ -1275,7 +1241,7 @@ public:
if (sv != 0) (*sv)[j] -= mul * (*sv)[i];
}
if (i < _V2D::cols_ - 1) {
if (_PIMathMatrixNullCompare(smat.element(i + 1, i + 1))) {
if (PIMathFloatNullCompare(smat.element(i + 1, i + 1))) {
if (ok != 0) *ok = false;
return *this;
}

View File

@@ -105,7 +105,7 @@ void PIMutex::init() {
pthread_mutexattr_t attr;
memset(&attr, 0, sizeof(attr));
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
memset(&(PRIVATE->mutex), 0, sizeof(PRIVATE->mutex));
pthread_mutex_init(&(PRIVATE->mutex), &attr);
pthread_mutexattr_destroy(&attr);