Added support for fpclassify in Eigen::Numext

This commit is contained in:
Benoit Steiner
2016-04-27 12:10:25 -07:00
parent 1f48f47ab7
commit 6744d776ba
2 changed files with 31 additions and 0 deletions

View File

@@ -407,6 +407,28 @@ static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isnan)(const Eigen::half& a)
static EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isfinite)(const Eigen::half& a) {
return !(Eigen::numext::isinf)(a) && !(Eigen::numext::isnan)(a);
}
template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC int (fpclassify)(const Eigen::half& a) {
const int exponent = a.x & 0x7c00;
const int mantissa = a.x & 0x03ff;
if (exponent == 0) {
if (mantissa == 0) {
// Positive or negative zero.
return FP_ZERO;
} else {
return FP_SUBNORMAL;
}
} else if (exponent == 0x7c00) {
// Maximum possible exponent signifies either NaN or +/- inf.
if (mantissa == 0) {
return FP_INFINITE;
} else {
return FP_NAN;
}
} else {
return FP_NORMAL;
}
}
template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half abs(const Eigen::half& a) {
Eigen::half result;
result.x = a.x & 0x7FFF;