aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/defs.hh
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2012-10-22 14:25:10 -0400
committerErik Schnetter <schnetter@gmail.com>2012-10-22 14:25:10 -0400
commit40b821811176d69f15942fc1a35bbd00cf6940a1 (patch)
treef8e30ae80a318f19d7b50ba9ff5fce724f1feaea /Carpet/CarpetLib/src/defs.hh
parent2d5752398c5844a24f3146792b2e93510552c19e (diff)
Remove Carpet's mechanisms to deal with how to call isnan
Remove Carpet's mechanisms to deal with how to call isnan. Instead, expect isnan in std::, and rely on Cactus to correct things if this is not the case.
Diffstat (limited to 'Carpet/CarpetLib/src/defs.hh')
-rw-r--r--Carpet/CarpetLib/src/defs.hh367
1 files changed, 33 insertions, 334 deletions
diff --git a/Carpet/CarpetLib/src/defs.hh b/Carpet/CarpetLib/src/defs.hh
index 373d6bb29..f41b19d86 100644
--- a/Carpet/CarpetLib/src/defs.hh
+++ b/Carpet/CarpetLib/src/defs.hh
@@ -191,349 +191,48 @@ inline const char * typestring (const CCTK_COMPLEX32&)
#endif
+
+// Provide implementations for some functions for complex numbers
+
+#define IMPLEMENT_FUNCTIONS(T) \
+ \
+ inline int good_isfinite(T const& x) \
+ { \
+ return isfinite(x.real()) and isfinite(x.imag()); \
+ } \
+ \
+ inline int good_isinf(T const& x) \
+ { \
+ return isinf(x.real()) or isinf(x.imag()); \
+ } \
+ \
+ inline int good_isnan(T const& x) \
+ { \
+ return isnan(x.real()) or isnan(x.imag()); \
+ } \
+ \
+ inline int good_isnormal(T const& x) \
+ { \
+ return isnormal(x.real()) or isnormal(x.imag()); \
+ }
-// Capture the system's fpclassify, isfinite, isinf, isnan, and
-// isnormal functions
-
-// #ifdef HAVE_CCTK_REAL4
-// inline int myfpclassify (CCTK_REAL4 const x)
-// { return fpclassify (x); }
-// #endif
-// #ifdef HAVE_CCTK_REAL8
-// inline int myfpclassify (CCTK_REAL8 const x)
-// { return fpclassify (x); }
-// #endif
-// #ifdef HAVE_CCTK_REAL16
-// inline int myfpclassify (CCTK_REAL16 const x)
-// { return fpclassify (x); }
-// #endif
-//
-// #undef fpclassify
-
-#ifdef HAVE_CCTK_REAL4
-inline int myisfinite (CCTK_REAL4 const x)
-{ return isfinite (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
-inline int myisfinite (CCTK_REAL8 const x)
-{ return isfinite (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
-inline int myisfinite (CCTK_REAL16 const x)
-{ return isfinite (x); }
-#endif
-
-#undef isfinite
-
-#ifdef HAVE_CCTK_REAL4
-inline int myisinf (CCTK_REAL4 const x)
-{ return isinf (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
-inline int myisinf (CCTK_REAL8 const x)
-{ return isinf (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
-inline int myisinf (CCTK_REAL16 const x)
-{ return isinf (x); }
-#endif
-
-#undef isinf
-
-#ifdef HAVE_CCTK_REAL4
-inline int myisnan (CCTK_REAL4 const x)
-{ return isnan (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
-inline int myisnan (CCTK_REAL8 const x)
-{ return isnan (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
-inline int myisnan (CCTK_REAL16 const x)
-{ return isnan (x); }
-#endif
-
-#undef isnan
-
-#ifdef HAVE_CCTK_REAL4
-inline int myisnormal (CCTK_REAL4 const x)
-{ return isnormal (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
-inline int myisnormal (CCTK_REAL8 const x)
-{ return isnormal (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
-inline int myisnormal (CCTK_REAL16 const x)
-{ return isnormal (x); }
-#endif
-
-#undef isnormal
-
-
-
-namespace CarpetLib {
- namespace good {
-
- // Explicitly overload some functions for all types in the same
- // namespace CarpetLib::good, to circumvent confusion among some
- // compilers
-
- //
- // abs
- //
-
- template <typename T>
- inline typename typeprops<T>::real abs (T const x)
- { return std::abs (x); }
-
-// // This does not work on Linux with Intel compilers, which do not
-// // always have long long llabs (long long)
-// template<> inline signed char abs<signed char> (signed char const x) { return ::abs (x); }
-// template<> inline unsigned char abs<unsigned char> (unsigned char const x) CCTK_ATTRIBUTE_CONST { return ::abs (x); }
-// template<> inline short abs<short> (short const x) { return ::abs (x); }
-// template<> inline int abs<int> (int const x) { return ::abs (x); }
-// template<> inline long abs<long> (long const x) { return ::labs (x); }
-// #ifdef SIZEOF_LONG_LONG
-// inline long long abs<long long> (long long const x) { return ::llabs (x); }
-// #endif
-
-// // This template does not work on AIX, which does not have long
-// // long abs (long long)
-// #ifdef HAVE_CCTK_INT1
-// template<> inline CCTK_INT1 abs<CCTK_INT1> (CCTK_INT1 const x) { return x < 0 ? - x : x; }
-// #endif
-// #ifdef HAVE_CCTK_INT2
-// template<> inline CCTK_INT2 abs<CCTK_INT2> (CCTK_INT2 const x) { return x < 0 ? - x : x; }
-// #endif
-// #ifdef HAVE_CCTK_INT4
-// template<> inline CCTK_INT4 abs<CCTK_INT4> (CCTK_INT4 const x) { return x < 0 ? - x : x; }
-// #endif
-// #ifdef HAVE_CCTK_INT8
-// template<> inline CCTK_INT8 abs<CCTK_INT8> (CCTK_INT8 const x) { return x < 0 ? - x : x; }
-// #endif
-
-#ifdef HAVE_CCTK_COMPLEX8
- template<> inline CCTK_REAL4 abs<CCTK_COMPLEX8> (CCTK_COMPLEX8 const x)
- { return CCTK_Cmplx8Abs (x); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX16
- template<> inline CCTK_REAL8 abs<CCTK_COMPLEX16> (CCTK_COMPLEX16 const x)
- { return CCTK_Cmplx16Abs (x); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX32
- template<> inline CCTK_REAL16 abs<CCTK_COMPLEX32> (CCTK_COMPLEX32 const x)
- { return CCTK_Cmplx32Abs (x); }
-#endif
-
-// //
-// // fpclassify
-// //
-//
-// // Default implementation, only good for integers
-// template <typename T>
-// inline int fpclassify (T const x)
-// { return x ? FP_NORMAL : FP_ZERO; }
-//
-// #ifdef HAVE_CCTK_REAL4
-// template<> inline int fpclassify (CCTK_REAL4 const x)
-// { return myfpclassify (x); }
-// #endif
-// #ifdef HAVE_CCTK_REAL8
-// template<> inline int fpclassify (CCTK_REAL8 const x)
-// { return myfpclassify (x); }
-// #endif
-// #ifdef HAVE_CCTK_REAL16
-// template<> inline int fpclassify (CCTK_REAL16 const x)
-// { return myfpclassify (x); }
-// #endif
-//
-// #ifdef HAVE_CCTK_COMPLEX8
-// template<> inline int fpclassify (CCTK_COMPLEX8 const x)
-// { assert(0); }
-// #endif
-// #ifdef HAVE_CCTK_COMPLEX16
-// template<> inline int fpclassify (CCTK_COMPLEX16 const x)
-// { assert(0); }
-// #endif
-// #ifdef HAVE_CCTK_COMPLEX32
-// template<> inline int fpclassify (CCTK_COMPLEX32 const x)
-// { assert(0); }
-// #endif
-
- //
- // isfinite
- //
-
- // Default implementation, only good for integers
- template <typename T>
- inline int isfinite (T const x)
- { return 1; }
-
-#ifdef HAVE_CCTK_REAL4
- template<> inline int isfinite (CCTK_REAL4 const x)
- { return myisfinite (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
- template<> inline int isfinite (CCTK_REAL8 const x)
- { return myisfinite (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
- template<> inline int isfinite (CCTK_REAL16 const x)
- { return myisfinite (x); }
-#endif
-
-#ifdef HAVE_CCTK_COMPLEX8
- template<> inline int isfinite (CCTK_COMPLEX8 const x)
- { return myisfinite (CCTK_Cmplx8Real (x)) and myisfinite (CCTK_Cmplx8Imag (x)); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX16
- template<> inline int isfinite (CCTK_COMPLEX16 const x)
- { return myisfinite (CCTK_Cmplx16Real (x)) and myisfinite (CCTK_Cmplx16Imag (x)); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX32
- template<> inline int isfinite (CCTK_COMPLEX32 const x)
- { return myisfinite (CCTK_Cmplx32Real (x)) and myisfinite (CCTK_Cmplx32Imag (x)); }
-#endif
-
- //
- // isinf
- //
-
- // Default implementation, only good for integers
- template <typename T>
- inline int isinf (T const x)
- { return 0; }
-
-#ifdef HAVE_CCTK_REAL4
- template<> inline int isinf (CCTK_REAL4 const x)
- { return myisinf (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
- template<> inline int isinf (CCTK_REAL8 const x)
- { return myisinf (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
- template<> inline int isinf (CCTK_REAL16 const x)
- { return myisinf (x); }
-#endif
-
-#ifdef HAVE_CCTK_COMPLEX8
- template<> inline int isinf (CCTK_COMPLEX8 const x)
- { return myisinf (CCTK_Cmplx8Real (x)) or myisinf (CCTK_Cmplx8Imag (x)); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX16
- template<> inline int isinf (CCTK_COMPLEX16 const x)
- { return myisinf (CCTK_Cmplx16Real (x)) or myisinf (CCTK_Cmplx16Imag (x)); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX32
- template<> inline int isinf (CCTK_COMPLEX32 const x)
- { return myisinf (CCTK_Cmplx32Real (x)) or myisinf (CCTK_Cmplx32Imag (x)); }
-#endif
-
- //
- // isnan
- //
-
- // Default implementation, only good for integers
- template <typename T>
- inline int isnan (T const x)
- { return 0; }
-
-#ifdef HAVE_CCTK_REAL4
- template<> inline int isnan (CCTK_REAL4 const x)
- { return myisnan (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
- template<> inline int isnan (CCTK_REAL8 const x)
- { return myisnan (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
- template<> inline int isnan (CCTK_REAL16 const x)
- { return myisnan (x); }
-#endif
-
-#ifdef HAVE_CCTK_COMPLEX8
- template<> inline int isnan (CCTK_COMPLEX8 const x)
- { return myisnan (CCTK_Cmplx8Real (x)) or myisnan (CCTK_Cmplx8Imag (x)); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX16
- template<> inline int isnan (CCTK_COMPLEX16 const x)
- { return myisnan (CCTK_Cmplx16Real (x)) or myisnan (CCTK_Cmplx16Imag (x)); }
-#endif
-#ifdef HAVE_CCTK_COMPLEX32
- template<> inline int isnan (CCTK_COMPLEX32 const x)
- { return myisnan (CCTK_Cmplx32Real (x)) or myisnan (CCTK_Cmplx32Imag (x)); }
-#endif
-
- //
- // isnormal
- //
-
- // Default implementation, only good for integers
- template <typename T>
- inline int isnormal (T const x)
- { return 1; }
-
-#ifdef HAVE_CCTK_REAL4
- template<> inline int isnormal (CCTK_REAL4 const x)
- { return myisnormal (x); }
-#endif
-#ifdef HAVE_CCTK_REAL8
- template<> inline int isnormal (CCTK_REAL8 const x)
- { return myisnormal (x); }
-#endif
-#ifdef HAVE_CCTK_REAL16
- template<> inline int isnormal (CCTK_REAL16 const x)
- { return myisnormal (x); }
-#endif
-
+namespace std {
+ namespace Cactus {
+
#ifdef HAVE_CCTK_COMPLEX8
- template<> inline int isnormal (CCTK_COMPLEX8 const x)
- { return myisnormal (CCTK_Cmplx8Real (x)) and myisnormal (CCTK_Cmplx8Imag (x)); }
+ IMPLEMENT_FUNCTIONS(CCTK_COMPLEX8)
#endif
#ifdef HAVE_CCTK_COMPLEX16
- template<> inline int isnormal (CCTK_COMPLEX16 const x)
- { return myisnormal (CCTK_Cmplx16Real (x)) and myisnormal (CCTK_Cmplx16Imag (x)); }
+ IMPLEMENT_FUNCTIONS(CCTK_COMPLEX16)
#endif
#ifdef HAVE_CCTK_COMPLEX32
- template<> inline int isnormal (CCTK_COMPLEX32 const x)
- { return myisnormal (CCTK_Cmplx32Real (x)) and myisnormal (CCTK_Cmplx32Imag (x)); }
+ IMPLEMENT_FUNCTIONS(CCTK_COMPLEX32)
#endif
- } // namespace good
-} // namespace CarpetLib
-
-
-
-// Use #defines to access the CarpetLib::good functions from the
-// global namespace. Because macros are not scoped, this makes the
-// corresponding functions in CarpetLib::good inaccessible, so we
-// rename them by adding an underscore.
-
-namespace CarpetLib {
- namespace good {
-
-#define ALIAS_GOOD_FUNCTION(typ,func) \
- template <typename T> \
- inline typ func##_ (T const x) \
- { return func (x); }
-
- // ALIAS_GOOD_FUNCTION(int,fpclassify)
- ALIAS_GOOD_FUNCTION(int,isfinite)
- ALIAS_GOOD_FUNCTION(int,isinf)
- ALIAS_GOOD_FUNCTION(int,isnan)
- ALIAS_GOOD_FUNCTION(int,isnormal)
-
-#undef ALIAS_GOOD_FUNCTION
-
- } // namespace good
-} // namespace CarpetLib
+ }
+}
-#define isfinite (::CarpetLib::good::isfinite_)
-#define isinf (::CarpetLib::good::isinf_)
-#define isnan (::CarpetLib::good::isnan_)
-#define isnormal (::CarpetLib::good::isnormal_)
+#undef IMPLEMENT_FUNCTIONS