44#ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_TRAITS_H
45#define LASS_GUARDIAN_OF_INCLUSION_NUM_TRAITS_H
49#if LASS_HAVE_STD_ISNAN
51#elif LASS_NUM_NUM_TRAITS_HAVE_MSVC_FLOAT_H
102template<
class C>
inline
108#if LASS_HAVE_STD_ISNAN
109inline bool isNaN(
float iV ) {
return std::isnan(iV); }
110inline bool isNaN(
double iV ) {
return std::isnan(iV); }
111inline bool isNaN(
long double iV ) {
return std::isnan(iV); }
112#elif LASS_NUM_NUM_TRAITS_HAVE_MSVC_FLOAT_H
113inline bool isNaN(
float iV ) {
return _isnan(
static_cast<double>(iV)) != 0; }
114inline bool isNaN(
double iV ) {
return _isnan(iV) != 0; }
115inline bool isNaN(
long double iV ) {
return _isnan(
static_cast<double>(iV)) != 0; }
117inline bool isNaN(
float iV ) {
return isnan(iV) != 0; }
118inline bool isNaN(
double iV ) {
return isnan(iV) != 0; }
119inline bool isNaN(
long double iV ) {
return isnan(
static_cast<double>(iV)) != 0; }
122template<
class C>
inline
123bool isNaN( std::complex<C> iV )
125 return isNaN(iV.real()) || isNaN(iV.imag());
134 return NumTraits<C>::hasInfinity &&
135 (iV == NumTraits<C>::infinity || iV == -NumTraits<C>::infinity);
138inline bool isInf(
float iV) {
return std::isinf(iV); }
139inline bool isInf(
double iV) {
return std::isinf(iV); }
140inline bool isInf(
long double iV) {
return std::isinf(iV); }
142#define LASS_NUM_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
143#define LASS_NUM_E 2.718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427
144#define LASS_NUM_SQRT_2 1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641572
145#define LASS_NUM_SQRT_PI 1.772453850905516027298167483341145
147#define LASS_NUM_DECLARE_FLOATING_TRAITS( ttype, tname ) \
149struct LASS_DLL NumTraits<ttype>\
151 typedef ttype selfType;\
152 typedef ttype baseType;\
153 typedef ttype intervalType;\
156 isDistribution = false,\
162 isFloatingPoint = true\
164 static constexpr size_t memorySize = sizeof(ttype);\
165 static constexpr size_t mantisseSize = std::numeric_limits<ttype>::digits;\
166 static const std::string name() { return tname ; }\
167 static constexpr ttype one = static_cast<ttype>(1);\
168 static constexpr ttype zero = static_cast<ttype>(0);\
169 static constexpr ttype infinity = std::numeric_limits<ttype>::infinity();\
170 static constexpr ttype qNaN = std::numeric_limits<ttype>::quiet_NaN();\
171 static constexpr ttype sNaN = std::numeric_limits<ttype>::signaling_NaN();\
172 static constexpr ttype epsilon= std::numeric_limits<ttype>::epsilon();\
173 static constexpr ttype min = -std::numeric_limits<ttype>::max();\
174 static constexpr ttype max = std::numeric_limits<ttype>::max();\
175 static constexpr ttype minStrictPositive = std::numeric_limits<ttype>::min();\
176 static constexpr ttype pi = static_cast<ttype>(LASS_NUM_PI);\
177 static constexpr ttype e = static_cast<ttype>(LASS_NUM_E);\
178 static constexpr ttype sqrt2 = static_cast<ttype>(LASS_NUM_SQRT_2);\
179 static constexpr ttype sqrtPi = static_cast<ttype>(LASS_NUM_SQRT_PI);\
181 static constexpr ttype gamma(unsigned n) { return (static_cast<ttype>(n) * epsilon) / (2 - static_cast<ttype>(n) * epsilon); }\
184#define LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( ttype, tname ) \
186struct LASS_DLL NumTraits< ttype >\
188 typedef ttype selfType;\
189 typedef ttype::value_type baseType;\
190 typedef ttype intervalType;\
193 isDistribution = false,\
197 hasInfinity = false,\
199 isFloatingPoint = NumTraits< baseType >::isFloatingPoint\
201 static constexpr size_t memorySize = sizeof(ttype);\
202 static constexpr size_t mantisseSize = NumTraits< baseType >::mantisseSize;\
203 static const std::string name() { return tname ; }\
204 static constexpr ttype one = ttype( NumTraits< baseType >::one );\
205 static constexpr ttype zero = ttype( NumTraits< baseType >::zero );\
206 static constexpr ttype pi = ttype( NumTraits< baseType >::pi );\
207 static constexpr ttype e = ttype( NumTraits< baseType >::e );\
208 static constexpr ttype sqrt2 = ttype( NumTraits< baseType >::sqrt2 );\
209 static constexpr ttype sqrtPi = ttype( NumTraits< baseType >::sqrtPi );\
212LASS_NUM_DECLARE_FLOATING_TRAITS(
float,
"float" )
213LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( std::complex<
float > ,
"complex<float>" )
215LASS_NUM_DECLARE_FLOATING_TRAITS(
double ,
"double" )
216LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( std::complex<
double > ,
"complex<double>" )
218LASS_NUM_DECLARE_FLOATING_TRAITS(
long double,
"long double" )
219LASS_NUM_DECLARE_COMPLEX_FLOATING_TRAITS( std::complex<
long double > ,
"complex<long double>" )
224 typedef char selfType;
225 typedef char baseType;
226 typedef float intervalType;
227 typedef signed char signedType;
228 typedef unsigned char unsignedType;
234#ifdef LASS_CHAR_IS_SIGNED
243 static constexpr size_t memorySize =
sizeof(char);
244 static constexpr size_t mantisseSize = 0;
245 static const std::string name() {
return LASS_STRINGIFY(
char); }
246 static constexpr selfType one = 1;
247 static constexpr selfType zero = 0;
248 static constexpr selfType epsilon = 1;
249 static constexpr selfType min = std::numeric_limits<char>::min();
250 static constexpr selfType max = std::numeric_limits<char>::max();
251 static constexpr selfType minStrictPositive = 1;
254#define LASS_NUM_DECLARE_INTEGRAL_TRAITS( sign, type, is_signed ) \
256struct LASS_DLL NumTraits<sign type> \
258 typedef sign type selfType;\
259 typedef sign type baseType;\
260 typedef float intervalType;\
261 typedef signed type signedType;\
262 typedef unsigned type unsignedType;\
268 isSigned = is_signed,\
273 static constexpr size_t memorySize = sizeof(sign type);\
274 static constexpr size_t mantisseSize = 0;\
275 static const std::string name() { return LASS_STRINGIFY(sign type); }\
276 static constexpr selfType one = 1;\
277 static constexpr selfType zero = 0;\
278 static constexpr selfType epsilon = 1;\
279 static constexpr selfType min = std::numeric_limits<sign type>::min();\
280 static constexpr selfType max = std::numeric_limits<sign type>::max();\
281 static constexpr selfType minStrictPositive = 1;\
284LASS_NUM_DECLARE_INTEGRAL_TRAITS(
signed,
char, 1 )
285LASS_NUM_DECLARE_INTEGRAL_TRAITS(
unsigned,
char, 0 )
286LASS_NUM_DECLARE_INTEGRAL_TRAITS(
signed,
short, 1 )
287LASS_NUM_DECLARE_INTEGRAL_TRAITS(
unsigned,
short, 0 )
288LASS_NUM_DECLARE_INTEGRAL_TRAITS(
signed,
int, 1 )
289LASS_NUM_DECLARE_INTEGRAL_TRAITS(
unsigned,
int, 0 )
290LASS_NUM_DECLARE_INTEGRAL_TRAITS(
signed,
long, 1 )
291LASS_NUM_DECLARE_INTEGRAL_TRAITS(
unsigned,
long, 0 )
292#if LASS_HAVE_LONG_LONG
293 LASS_NUM_DECLARE_INTEGRAL_TRAITS(
signed,
long long, 1 )
294 LASS_NUM_DECLARE_INTEGRAL_TRAITS(
unsigned,
long long, 0 )
295#elif LASS_PLATFORM_TYPE == LASS_PLATFORM_TYPE_WIN32
296 LASS_NUM_DECLARE_INTEGRAL_TRAITS(
signed, __int64, 1 )
297 LASS_NUM_DECLARE_INTEGRAL_TRAITS(
unsigned, __int64, 0 )
#define LASS_DLL
DLL interface: import or export symbols?
numeric types and traits.
bool isInf(const C &iV)
return true if iV equals minus or plus Infinity
Library for Assembled Shared Sources.