IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
math.h
Go to the documentation of this file.
1/**
2 * \file IMP/math.h
3 * \brief Helper functions to check for NaN or infinity
4 *
5 * Copyright 2007-2022 IMP Inventors. All rights reserved.
6 */
7
8#ifndef IMPKERNEL_BASE_MATH_H
9#define IMPKERNEL_BASE_MATH_H
10
11#include <IMP/kernel_config.h>
12#include <boost/version.hpp>
13#include <cmath>
14#if !defined(_GLIBCXX_USE_C99_MATH)
15#include <boost/math/special_functions/fpclassify.hpp>
16#endif
17
18IMPKERNEL_BEGIN_NAMESPACE
19//! Return true if a number is NaN
20/** With certain compiler settings the compiler can optimize
21 out a!=a (and certain Intel chips had issues with it too).
22 */
23template <class T>
24inline bool isnan(const T& a) {
25#if defined(_GLIBCXX_USE_C99_MATH)
26 // Not all gcc versions include C99 math
27 return (std::isnan)(a);
28#else
29 return (boost::math::isnan)(a);
30#endif
31}
32
33//! Return true if a number is infinite
34template <class T>
35inline bool isinf(const T& a) {
36#if defined(_GLIBCXX_USE_C99_MATH)
37 // Not all gcc versions include C99 math
38 return (std::isinf)(a);
39#else
40 return (boost::math::isinf)(a);
41#endif
42}
43
44IMPKERNEL_END_NAMESPACE
45
46#endif /* IMPKERNEL_BASE_MATH_H */
bool isinf(const T &a)
Return true if a number is infinite.
Definition math.h:35
bool isnan(const T &a)
Return true if a number is NaN.
Definition math.h:24