CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/FWCore/Utilities/interface/isFinite.h

Go to the documentation of this file.
00001 #ifndef FWCORE_Utilities_isFinite_H
00002 #define FWCORE_Utilities_isFinite_H
00003 
00004 namespace edm {
00005   template <typename T>
00006   bool isFinite(T x);
00007 
00008   template <typename T>
00009   inline
00010   bool isNotFinite(T x) {
00011     return !isFinite(x);
00012   }
00013   
00014   template<>
00015   inline
00016   bool isFinite(float x) {
00017     const unsigned int mask =  0x7f800000;
00018     union { unsigned int l; float d;} v;
00019     v.d =x;
00020     return (v.l&mask)!=mask;
00021   }
00022   
00023   template<>
00024   inline
00025   bool isFinite(double x) {
00026     const unsigned long long mask = 0x7FF0000000000000LL;
00027     union { unsigned long long l; double d;} v;
00028     v.d =x;
00029     return (v.l&mask)!=mask;
00030   }
00031 
00032   template<>
00033   inline
00034   bool isFinite(long double x) {
00035     double xx=x;
00036     return isFinite(xx);
00037   }
00038 
00039 }
00040 
00041 #endif // FWCORE_Utilities_isFinite_H
00042