aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetLib/src/defs.hh
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2007-02-28 02:24:00 +0000
committerErik Schnetter <schnetter@cct.lsu.edu>2007-02-28 02:24:00 +0000
commitb5a21f4e4df143a4174b52429539c73257d32f94 (patch)
treeeae6de0591b2c925cf67b28ea26c26e831f78f1a /Carpet/CarpetLib/src/defs.hh
parentc86b8e1b4d124a852c2078f18219c3e5adf4820d (diff)
CarpetLib: Define overloaded abs functions for all Cactus datatypes
Add namespace CarpetLib::good containing overloaded abs functions for all Cactus datatypes. Some C++ compilers do not have long long support for abs, i.e., either std::abs or llabs does not exist. This circumvents this problem. darcs-hash:20070228022422-dae7b-a4cafbbad3f8b9cf9ae56edcc2f30c72c0d8de05.gz
Diffstat (limited to 'Carpet/CarpetLib/src/defs.hh')
-rw-r--r--Carpet/CarpetLib/src/defs.hh84
1 files changed, 84 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/defs.hh b/Carpet/CarpetLib/src/defs.hh
index 7f417800a..e22c45df6 100644
--- a/Carpet/CarpetLib/src/defs.hh
+++ b/Carpet/CarpetLib/src/defs.hh
@@ -7,6 +7,8 @@
#include <algorithm>
#include <cassert>
+#include <cmath>
+#include <cstdlib>
#include <iostream>
#include <list>
#include <set>
@@ -150,6 +152,88 @@ inline const char * typestring (const CCTK_COMPLEX32& dummy)
+namespace CarpetLib {
+ namespace good {
+
+ // Explicitly overload abs for all types in the same namespace, to
+ // circumvent confusion among some compilers
+
+ // CCTK_BYTE is unsigned
+ inline CCTK_BYTE abs (CCTK_BYTE const & x) { return x; }
+
+#if 0
+ // This does not work on AIX, which does not have long long abs
+ // (long long)
+# ifdef HAVE_CCTK_INT1
+ inline CCTK_INT1 abs (CCTK_INT1 const & x) { return std::abs (x); }
+# endif
+# ifdef HAVE_CCTK_INT2
+ inline CCTK_INT2 abs (CCTK_INT2 const & x) { return std::abs (x); }
+# endif
+# ifdef HAVE_CCTK_INT4
+ inline CCTK_INT4 abs (CCTK_INT4 const & x) { return std::abs (x); }
+# endif
+# ifdef HAVE_CCTK_INT8
+ inline CCTK_INT8 abs (CCTK_INT8 const & x) { return std::abs (x); }
+# endif
+#endif
+
+#if 0
+ // This does not work on Linux with Intel compilers, which do not
+ // always have long long llabs (long long)
+ inline signed char abs (signed char const & x) { return ::abs (x); }
+ inline unsigned char abs (unsigned char const & x) { return ::abs (x); }
+ inline short abs (short const & x) { return ::abs (x); }
+ inline int abs (int const & x) { return ::abs (x); }
+ inline long abs (long const & x) { return ::labs (x); }
+# ifdef SIZEOF_LONG_LONG
+ inline long long abs (long long const & x) { return ::llabs (x); }
+# endif
+#endif
+
+#if 1
+# ifdef HAVE_CCTK_INT1
+ inline CCTK_INT1 abs (CCTK_INT1 const & x) { return x < 0 ? - x : x; }
+# endif
+# ifdef HAVE_CCTK_INT2
+ inline CCTK_INT2 abs (CCTK_INT2 const & x) { return x < 0 ? - x : x; }
+# endif
+# ifdef HAVE_CCTK_INT4
+ inline CCTK_INT4 abs (CCTK_INT4 const & x) { return x < 0 ? - x : x; }
+# endif
+# ifdef HAVE_CCTK_INT8
+ inline CCTK_INT8 abs (CCTK_INT8 const & x) { return x < 0 ? - x : x; }
+# endif
+#endif
+
+#ifdef HAVE_CCTK_REAL4
+ inline CCTK_REAL4 abs (CCTK_REAL4 const & x) { return std::abs (x); }
+#endif
+#ifdef HAVE_CCTK_REAL8
+ inline CCTK_REAL8 abs (CCTK_REAL8 const & x) { return std::abs (x); }
+#endif
+#ifdef HAVE_CCTK_REAL16
+ inline CCTK_REAL16 abs (CCTK_REAL16 const & x) { return std::abs (x); }
+#endif
+
+#ifdef HAVE_CCTK_COMPLEX8
+ inline CCTK_REAL4 abs (CCTK_COMPLEX8 const & x)
+ { return CCTK_Cmplx8Abs (x); }
+#endif
+#ifdef HAVE_CCTK_COMPLEX16
+ inline CCTK_REAL8 abs (CCTK_COMPLEX16 const & x)
+ { return CCTK_Cmplx16Abs (x); }
+#endif
+#ifdef HAVE_CCTK_COMPLEX32
+ inline CCTK_REAL16 abs (CCTK_COMPLEX32 const & x)
+ { return CCTK_Cmplx32Abs (x); }
+#endif
+
+ } // namespace good
+} // namespace CarpetLib
+
+
+
// Container input
template<class T> istream& input (istream& is, vector<T>& v);