-
Notifications
You must be signed in to change notification settings - Fork 0
/
compat.h
73 lines (63 loc) · 1.5 KB
/
compat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef ECELL_GREENS_FUNCTIONS_COMPAT_HPP
#define ECELL_GREENS_FUNCTIONS_COMPAT_HPP
#include <greens_functions/config.h>
#include <cmath>
#include <limits>
#ifndef ECELL_GREENS_FUNCTIONS_HAVE_SINCOS
namespace greens_functions
{
inline void sincos( double x, double* s, double* c )
{
*s = std::sin(x);
*c = std::cos(x);
}
} // greens_functions
#endif /* HAVE_SINCOS */
#if __cplusplus >= 201103L
// after C++11, std::isfinite is defined in <cmath> header.
namespace greens_functions
{
inline bool isfinite(float x)
{
return std::isfinite(x);
}
inline bool isfinite(double x)
{
return std::isfinite(x);
}
inline bool isfinite(long double x)
{
return std::isfinite(x);
}
} // greens_functions
#else
// it means that the compiler still does not compatible with C++11 or
// the user compiles this without -std=c++(11|14|17) flag.
namespace greens_functions
{
namespace detail
{
template<typename T>
inline bool isfinite_impl(T x)
{
// return (not nan && not +inf && not -inf);
// if x was nan, all the comparison including `x == x` would be false!
return (x == x) && (x != std::numeric_limits<T>::infinity()) &&
(x != -std::numeric_limits<T>::infinity());
}
} // detail
inline bool isfinite(float x)
{
return detail::isfinite_impl(x);
}
inline bool isfinite(double x)
{
return detail::isfinite_impl(x);
}
inline bool isfinite(long double x)
{
return detail::isfinite_impl(x);
}
} // greens_functions
#endif // ISFINITE
#endif // ECELL_GREENS_FUNCTIONS_COMPAT_HPP