diff options
Diffstat (limited to 'include/ceres/fpclassify.h')
-rw-r--r-- | include/ceres/fpclassify.h | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/include/ceres/fpclassify.h b/include/ceres/fpclassify.h index b730832..da8a4d0 100644 --- a/include/ceres/fpclassify.h +++ b/include/ceres/fpclassify.h @@ -46,25 +46,24 @@ namespace ceres { #if defined(_MSC_VER) -inline bool IsFinite (double x) { return _finite(x); } -inline bool IsInfinite(double x) { return !_finite(x) && !_isnan(x); } -inline bool IsNaN (double x) { return _isnan(x); } + +inline bool IsFinite (double x) { return _finite(x) != 0; } +inline bool IsInfinite(double x) { return _finite(x) == 0 && _isnan(x) == 0; } +inline bool IsNaN (double x) { return _isnan(x) != 0; } inline bool IsNormal (double x) { int classification = _fpclass(x); return classification == _FPCLASS_NN || classification == _FPCLASS_PN; } -#elif defined(ANDROID) -// On Android when using the GNU STL, the C++ fpclassify functions are not -// available. Strictly speaking, the std functions are are not standard until -// C++11. Instead use the C99 macros on Android. +#elif defined(ANDROID) && defined(_STLPORT_VERSION) + +// On Android, when using the STLPort, the C++ isnan and isnormal functions +// are defined as macros. inline bool IsNaN (double x) { return isnan(x); } inline bool IsNormal (double x) { return isnormal(x); } - // On Android NDK r6, when using STLPort, the isinf and isfinite functions are // not available, so reimplement them. -# if defined(_STLPORT_VERSION) inline bool IsInfinite(double x) { return x == std::numeric_limits<double>::infinity() || x == -std::numeric_limits<double>::infinity(); @@ -72,17 +71,15 @@ inline bool IsInfinite(double x) { inline bool IsFinite(double x) { return !isnan(x) && !IsInfinite(x); } -# else -inline bool IsFinite (double x) { return isfinite(x); } -inline bool IsInfinite(double x) { return isinf(x); } -# endif // defined(_STLPORT_VERSION) -#else + +# else + // These definitions are for the normal Unix suspects. -// TODO(keir): Test the "else" with more platforms. inline bool IsFinite (double x) { return std::isfinite(x); } inline bool IsInfinite(double x) { return std::isinf(x); } inline bool IsNaN (double x) { return std::isnan(x); } inline bool IsNormal (double x) { return std::isnormal(x); } + #endif } // namespace ceres |