Treelite
math.h
Go to the documentation of this file.
1 
7 #ifndef TREELITE_MATH_H_
8 #define TREELITE_MATH_H_
9 
10 #include <algorithm>
11 #include <cfloat>
12 #include <cmath>
13 
14 namespace treelite {
15 namespace math {
16 
26 template <class Iter, class T>
27 Iter binary_search(Iter begin, Iter end, const T& val) {
28  Iter i = std::lower_bound(begin, end, val);
29  if (i != end && val == *i) {
30  return i; // found
31  } else {
32  return end; // not found
33  }
34 }
35 
42 template <typename T>
43 inline bool CheckNAN(T value) {
44 #ifdef _MSC_VER
45  return (_isnan(value) != 0);
46 #else
47  return std::isnan(value);
48 #endif
49 }
50 
51 } // namespace math
52 } // namespace treelite
53 
54 #endif // TREELITE_MATH_H_
bool CheckNAN(T value)
check for NaN (Not a Number)
Definition: math.h:43
Iter binary_search(Iter begin, Iter end, const T &val)
perform binary search on the range [begin, end).
Definition: math.h:27