From fa0675289ce237b9f47529f953c5138394a3066d Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 26 Nov 2013 16:43:38 -0500 Subject: Improve auto-detecting of math functions provided by STL --- floattypes.h | 73 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/floattypes.h b/floattypes.h index cfa9136..1830d1d 100644 --- a/floattypes.h +++ b/floattypes.h @@ -33,39 +33,19 @@ namespace vml_std { #else // C++11 is not supported, work around the missing pieces -// does not work witha all compilers; e.g. IBM's xlC on a Blue +// does not work with all compilers; e.g. IBM's xlC on a Blue // Gene/Q then does not provide macros for isnan, but provides // functions instead. #include #include -#define static_assert(cond, msg) +#ifndef static_assert +# define static_assert(cond, msg) +#endif -namespace vml_std { - - // Make some type definitions from stdint.h available in std - typedef ::uint8_t uint8_t; - typedef ::int8_t int8_t; - typedef ::uint16_t uint16_t; - typedef ::int16_t int16_t; - typedef ::uint32_t uint32_t; - typedef ::int32_t int32_t; -#if __SIZEOF_LONG__ == 8 - // Even if both "long" and "long long" have the same size, they are - // still different types. In many cases, it is then preferable to - // use "long" instead of "long long" in this case. - typedef unsigned long uint64_t; - typedef long int64_t; -#else - typedef ::uint64_t uint64_t; - typedef ::int64_t int64_t; -#endif - - - - // Capture macros into functions, then undefine the macros +// Capture libc macros, then undefine them #ifndef isfinite # error "isfinite is not a macro" #endif @@ -81,18 +61,45 @@ namespace vml_std { #ifndef signbit # error "signbit is not a macro" #endif - namespace { - template inline int libc_isfinite(T x) { return isfinite(x); } - template inline int libc_isinf(T x) { return isinf(x); } - template inline int libc_isnan(T x) { return isnan(x); } - template inline int libc_isnormal(T x) { return isnormal(x); } - template inline int libc_signbit(T x) { return signbit(x); } - } + +namespace { + template inline int libc_isfinite(T x) { return isfinite(x); } + template inline int libc_isinf(T x) { return isinf(x); } + template inline int libc_isnan(T x) { return isnan(x); } + template inline int libc_isnormal(T x) { return isnormal(x); } + template inline int libc_signbit(T x) { return signbit(x); } +} + +// Include this before undefining the macros below +#include + #undef isfinite #undef isinf -#undef isnan +#undef isnon #undef isnormal #undef signbit + + + +namespace vml_std { + + // Make some type definitions from stdint.h available in std + typedef ::uint8_t uint8_t; + typedef ::int8_t int8_t; + typedef ::uint16_t uint16_t; + typedef ::int16_t int16_t; + typedef ::uint32_t uint32_t; + typedef ::int32_t int32_t; +#if __SIZEOF_LONG__ == 8 + // Even if both "long" and "long long" have the same size, they are + // still different types. In many cases, it is then preferable to + // use "long" instead of "long long". + typedef unsigned long uint64_t; + typedef long int64_t; +#else + typedef ::uint64_t uint64_t; + typedef ::int64_t int64_t; +#endif -- cgit v1.1