summaryrefslogtreecommitdiff
path: root/src/include/cctk_Types.h
diff options
context:
space:
mode:
authorschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2007-04-27 19:41:24 +0000
committerschnetter <schnetter@17b73243-c579-4c4c-a9d2-2d5706c11dac>2007-04-27 19:41:24 +0000
commit934ebfc5904fec1cd74181849e0c1964dcb60d07 (patch)
tree283215c1e056dad7c07015a2085150978fd407f0 /src/include/cctk_Types.h
parentf4093eb1aeacd91454abd938a021b64409878d45 (diff)
This patch makes complex arithmetic in C and C++ more efficient, and
makes it much more convenient for C++, expecially when templates are used. The flesh functions for complex arithmetic are defined (not only declared) by including Complex.c from the header file cctk_Complex.h. They are declared "static inline", so the the compiler can inline them, but does not have to create an out-of-line copy for every source file. Complex.c is also compiled stand-alone without the "static inline" prefix, so that out-of-line copies exist as well. Add some new complex arithmetic functions, e.g. ComplexNeg to change the sign. Make some complex arithmetic functions more efficient by using algorithms from glibc. These algorithms are LGPL. They should be faster and/or more accurate than the existing implementations. For C++, define the usual arithmetic operators (+-*/ etc.) as inline functions calling the corresponding complex arithmetic functions. This makes it possible to use complex numbers in the same way as real numbers, which makes it possible to instantiate templates for both CCTK_REAL and CCTK_COMPLEX. This leads to much code reduction in Carpet. The patch also appends a type postfix to the names of math functions called in the inlined routines: 'f' for HAVE_CCTK_REAL4, nothing for HAVE_CCTK_REAL8, and 'l' for HAVE_CCTK_REAL16. This avoids compiler warnings about conversions from "double" to "float" which may lose significant bits. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4418 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/include/cctk_Types.h')
-rw-r--r--src/include/cctk_Types.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/include/cctk_Types.h b/src/include/cctk_Types.h
index b6d20771..734a0c17 100644
--- a/src/include/cctk_Types.h
+++ b/src/include/cctk_Types.h
@@ -38,28 +38,40 @@ typedef const char * CCTK_STRING;
#ifdef HAVE_CCTK_REAL16
#define HAVE_CCTK_COMPLEX32 1
-typedef struct
+typedef struct CCTK_COMPLEX32
{
CCTK_REAL16 Re;
CCTK_REAL16 Im;
+#ifdef __cplusplus
+ CCTK_REAL16 real() const { return Re; }
+ CCTK_REAL16 imag() const { return Im; }
+#endif
} CCTK_COMPLEX32;
#endif
#ifdef HAVE_CCTK_REAL8
#define HAVE_CCTK_COMPLEX16 1
-typedef struct
+typedef struct CCTK_COMPLEX16
{
CCTK_REAL8 Re;
CCTK_REAL8 Im;
+#ifdef __cplusplus
+ CCTK_REAL8 real() const { return Re; }
+ CCTK_REAL8 imag() const { return Im; }
+#endif
} CCTK_COMPLEX16;
#endif
#ifdef HAVE_CCTK_REAL4
#define HAVE_CCTK_COMPLEX8 1
-typedef struct
+typedef struct CCTK_COMPLEX8
{
CCTK_REAL4 Re;
CCTK_REAL4 Im;
+#ifdef __cplusplus
+ CCTK_REAL4 real() const { return Re; }
+ CCTK_REAL4 imag() const { return Im; }
+#endif
} CCTK_COMPLEX8;
#endif