pimathfloatnullcompare

This commit is contained in:
2020-09-26 19:46:34 +03:00
parent a42e5a7756
commit c971550535
2 changed files with 31 additions and 30 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