00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_TRAITS_H
00045 #define LASS_GUARDIAN_OF_INCLUSION_NUM_TRAITS_H
00046
00047 #include "num_common.h"
00048
00049 #ifdef LASS_NUM_NUM_TRAITS_HAVE_MSVC_FLOAT_H
00050 # include <float.h>
00051 #endif
00052
00053 namespace lass
00054 {
00055 namespace num
00056 {
00057
00058 template<class C>
00059 struct LASS_DLL NumTraits
00060 {
00061 typedef C selfType;
00062 typedef C baseType;
00063 typedef C intervalType;
00064
00065 enum
00066 {
00067 isDistribution = 0,
00068 isIntegral = 0,
00069 isNative = 0,
00070 isSigned = 0,
00071 hasInfinity = 0,
00072 hasNaN = 0,
00073 isFloatingPoint = 0
00074 };
00075
00076 static const size_t memorySize;
00077 static const size_t mantisseSize;
00078 static const std::string name() { return "unknown"; }
00079
00080 static const C one;
00081 static const C zero;
00082
00083
00084 static const C sNaN;
00085 static const C qNaN;
00086 static const C epsilon;
00087 static const C infinity;
00088 static const C min;
00089 static const C max;
00090 static const C minStrictPositive;
00091 static const C pi;
00092 static const C e;
00093 static const C sqrt2;
00094 static const C sqrtPi;
00095 };
00096
00097 template<class C> inline
00098 bool isNaN( const C& iV )
00099 {
00100 #ifdef LASS_NUM_NUM_TRAITS_HAVE_MSVC_FLOAT_H
00101 return NumTraits<C>::hasNaN && _isnan(static_cast<double>(iV)) != 0;
00102 #else
00103 return iV != iV;
00104 #endif
00105 }
00106
00107
00108
00109 template<class C>
00110 bool isInf( const C& iV )
00111 {
00112 return NumTraits<C>::hasInfinity &&
00113 (iV == NumTraits<C>::infinity || iV == -NumTraits<C>::infinity);
00114 }
00115
00116 #define LASS_NUM_DECLARE_FLOATING_TRAITS( ttype, tname ) \
00117 template<> \
00118 struct LASS_DLL NumTraits<ttype>\
00119 {\
00120 typedef ttype selfType;\
00121 typedef ttype baseType;\
00122 typedef ttype intervalType;\
00123 enum\
00124 {\
00125 isDistribution = false,\
00126 isIntegral = false,\
00127 isNative = true,\
00128 isSigned = true,\
00129 hasInfinity = true,\
00130 hasNaN = true,\
00131 isFloatingPoint = true\
00132 };\
00133 static const size_t memorySize;\
00134 static const size_t mantisseSize;\
00135 static const std::string name() { return tname ; }\
00136 static const ttype one;\
00137 static const ttype zero;\
00138 static const ttype infinity;\
00139 static const ttype qNaN;\
00140 static const ttype sNaN;\
00141 static const ttype epsilon;\
00142 static const ttype min;\
00143 static const ttype max;\
00144 static const ttype minStrictPositive;\
00145 static const ttype pi;\
00146 static const ttype e;\
00147 static const ttype sqrt2;\
00148 static const ttype sqrtPi;\
00149 };
00150
00151 #define LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( ttype, tname ) \
00152 template<> \
00153 struct LASS_DLL NumTraits< ttype >\
00154 {\
00155 typedef ttype selfType;\
00156 typedef ttype::value_type baseType;\
00157 typedef ttype intervalType;\
00158 enum\
00159 {\
00160 isDistribution = false,\
00161 isIntegral = false,\
00162 isNative = false,\
00163 isSigned = true,\
00164 hasInfinity = false,\
00165 hasNaN = false,\
00166 isFloatingPoint = NumTraits< baseType >::isFloatingPoint\
00167 };\
00168 static const size_t memorySize;\
00169 static const size_t mantisseSize;\
00170 static const std::string name() { return tname ; }\
00171 static const ttype one;\
00172 static const ttype zero;\
00173 static const ttype pi;\
00174 static const ttype e;\
00175 static const ttype sqrt2;\
00176 static const ttype sqrtPi;\
00177 };
00178
00179 LASS_NUM_DECLARE_FLOATING_TRAITS( float, "float" )
00180 LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( std::complex< float > , "complex<float>" )
00181
00182 LASS_NUM_DECLARE_FLOATING_TRAITS( double , "double" )
00183 LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( std::complex< double > , "complex<double>" )
00184
00185 LASS_NUM_DECLARE_FLOATING_TRAITS( long double, "long double" )
00186 LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( std::complex< long double > , "complex<long double>" )
00187
00188 template<>
00189 struct LASS_DLL NumTraits<char>
00190 {
00191 typedef char selfType;
00192 typedef char baseType;
00193 typedef float intervalType;
00194 typedef signed char signedType;
00195 typedef unsigned char unsignedType;
00196 enum
00197 {
00198 isDistribution = 0,
00199 isIntegral = 1,
00200 isNative = 1,
00201 #ifdef LASS_CHAR_IS_SIGNED
00202 isSigned = 1,
00203 #else
00204 isSigned = 0,
00205 #endif
00206 hasInfinity = 0,
00207 hasNaN = 0,
00208 isFloatingPoint = 0
00209 };
00210 static const size_t memorySize;
00211 static const size_t mantisseSize;
00212 static const std::string name() { return LASS_STRINGIFY(char); }
00213 static const selfType one;
00214 static const selfType zero;
00215 static const selfType epsilon;
00216 static const selfType min;
00217 static const selfType max;
00218 static const selfType minStrictPositive;
00219 };
00220
00221 #define LASS_NUM_DECLARE_INTEGRAL_TRAITS( sign, type, is_signed ) \
00222 template<> \
00223 struct LASS_DLL NumTraits<sign type> \
00224 {\
00225 typedef sign type selfType;\
00226 typedef sign type baseType;\
00227 typedef float intervalType;\
00228 typedef signed type signedType;\
00229 typedef unsigned type unsignedType;\
00230 enum\
00231 {\
00232 isDistribution = 0,\
00233 isIntegral = 1,\
00234 isNative = 1,\
00235 isSigned = is_signed,\
00236 hasInfinity = 0,\
00237 hasNaN = 0,\
00238 isFloatingPoint = 0\
00239 };\
00240 static const size_t memorySize;\
00241 static const size_t mantisseSize;\
00242 static const std::string name() { return LASS_STRINGIFY(sign type); }\
00243 static const selfType one;\
00244 static const selfType zero;\
00245 static const selfType epsilon;\
00246 static const selfType min;\
00247 static const selfType max;\
00248 static const selfType minStrictPositive;\
00249 };
00250
00251 LASS_NUM_DECLARE_INTEGRAL_TRAITS( signed, char, 1 )
00252 LASS_NUM_DECLARE_INTEGRAL_TRAITS( unsigned, char, 0 )
00253 LASS_NUM_DECLARE_INTEGRAL_TRAITS( signed, short, 1 )
00254 LASS_NUM_DECLARE_INTEGRAL_TRAITS( unsigned, short, 0 )
00255 LASS_NUM_DECLARE_INTEGRAL_TRAITS( signed, int, 1 )
00256 LASS_NUM_DECLARE_INTEGRAL_TRAITS( unsigned, int, 0 )
00257 LASS_NUM_DECLARE_INTEGRAL_TRAITS( signed, long, 1 )
00258 LASS_NUM_DECLARE_INTEGRAL_TRAITS( unsigned, long, 0 )
00259 #if LASS_PLATFORM_TYPE == LASS_PLATFORM_TYPE_WIN32
00260 LASS_NUM_DECLARE_INTEGRAL_TRAITS( signed, __int64, 1 )
00261 LASS_NUM_DECLARE_INTEGRAL_TRAITS( unsigned, __int64, 0 )
00262 #endif
00263
00264 }
00265
00266 }
00267
00268
00269
00270
00271
00272 #include "basic_ops.h"
00273
00274 #endif