diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2005-11-19 21:31:00 +0000 |
---|---|---|
committer | Erik Schnetter <schnetter@cct.lsu.edu> | 2005-11-19 21:31:00 +0000 |
commit | bc8af8c5c72ca251dcc65efbb8a5141c75fc50b6 (patch) | |
tree | fe7244a1a261f52e33c4575c31dda6e0fee072ab /Carpet/CarpetReduce | |
parent | faf30568e71db786158020927e94aaf47feea259 (diff) |
CarpetReduce: Handle sqrt() of integer values in a more C++ like fashion
Use static_cast<> instead of C style casts.
Do not use the STL's sqrt() function for integer variables because
e.g. Intel 7 does not support this.
darcs-hash:20051119213126-dae7b-5d33bbb6cfc786b980dd93332289528af6e5977f.gz
Diffstat (limited to 'Carpet/CarpetReduce')
-rw-r--r-- | Carpet/CarpetReduce/src/reduce.cc | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/Carpet/CarpetReduce/src/reduce.cc b/Carpet/CarpetReduce/src/reduce.cc index 710398649..c641a2f7a 100644 --- a/Carpet/CarpetReduce/src/reduce.cc +++ b/Carpet/CarpetReduce/src/reduce.cc @@ -47,7 +47,6 @@ namespace CarpetReduce { return max(x, y); } - // Square root template<typename T> inline T mysqrt (const T x) { @@ -86,6 +85,46 @@ namespace CarpetReduce { + // Overload the above helper functions and types for integer values + // The C++ compiler should supply these, but some old ones do not, + // e.g. our beloved workhorse Intel 7.1. Self is the man. +#ifdef HAVE_CCTK_BYTE + template<> inline CCTK_BYTE mysqrt (CCTK_BYTE const x) + { + return static_cast<CCTK_BYTE> (sqrt (static_cast<CCTK_REAL> (x))); + } +#endif + +#ifdef HAVE_CCTK_INT1 + template<> inline CCTK_INT1 mysqrt (CCTK_INT1 const x) + { + return static_cast<CCTK_INT1> (sqrt (static_cast<CCTK_REAL> (x))); + } +#endif + +#ifdef HAVE_CCTK_INT2 + template<> inline CCTK_INT2 mysqrt (CCTK_INT2 const x) + { + return static_cast<CCTK_INT2> (sqrt (static_cast<CCTK_REAL> (x))); + } +#endif + +#ifdef HAVE_CCTK_INT4 + template<> inline CCTK_INT4 mysqrt (CCTK_INT4 const x) + { + return static_cast<CCTK_INT4> (sqrt (static_cast<CCTK_REAL> (x))); + } +#endif + +#ifdef HAVE_CCTK_INT8 + template<> inline CCTK_INT8 mysqrt (CCTK_INT8 const x) + { + return static_cast<CCTK_INT8> (sqrt (static_cast<CCTK_REAL> (x))); + } +#endif + + + // Overload the above helper functions and types for complex values #ifdef CCTK_REAL4 @@ -204,41 +243,6 @@ namespace CarpetReduce { - // Provide a square root function for integer values - -#ifdef CCTK_INT1 - template<> inline CCTK_INT1 - mysqrt (const CCTK_INT1 x) - { - return sqrt((CCTK_REAL)x); - } -#endif - -#ifdef CCTK_INT2 - template<> inline CCTK_INT2 - mysqrt (const CCTK_INT2 x) - { - return sqrt((CCTK_REAL)x); - } -#endif - -#ifdef CCTK_INT4 - template<> inline CCTK_INT4 - mysqrt (const CCTK_INT4 x) - { - return sqrt((CCTK_REAL)x); - } -#endif - -#ifdef CCTK_INT8 - template<> inline CCTK_INT8 - mysqrt (const CCTK_INT8 x) - { - return sqrt((CCTK_REAL)x); - } -#endif - - // Poor man's RTTI enum ared { do_count, do_minimum, do_maximum, do_product, do_sum, |