Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:19

0001 #ifndef FWCORE_Utilities_isFinite_H
0002 #define FWCORE_Utilities_isFinite_H
0003 
0004 namespace edm {
0005   template <typename T>
0006   constexpr bool isFinite(T x);
0007 
0008   template <typename T>
0009   constexpr bool isNotFinite(T x) {
0010     return !isFinite(x);
0011   }
0012 
0013   template <>
0014   constexpr bool isFinite(float x) {
0015     const unsigned int mask = 0x7f800000;
0016     union {
0017       unsigned int l;
0018       float d;
0019     } v = {.d = x};
0020     return (v.l & mask) != mask;
0021   }
0022 
0023   template <>
0024   constexpr bool isFinite(double x) {
0025     const unsigned long long mask = 0x7FF0000000000000LL;
0026     union {
0027       unsigned long long l;
0028       double d;
0029     } v = {.d = x};
0030     return (v.l & mask) != mask;
0031   }
0032 
0033   template <>
0034   constexpr bool isFinite(long double x) {
0035     double xx = x;
0036     return isFinite(xx);
0037   }
0038 
0039 }  // namespace edm
0040 
0041 #endif  // FWCORE_Utilities_isFinite_H