Index: include/cctk_Complex.h =================================================================== --- include/cctk_Complex.h (revision 5076) +++ include/cctk_Complex.h (working copy) @@ -11,36 +11,108 @@ #ifndef _CCTK_COMPLEX_H_ #define _CCTK_COMPLEX_H_ +#include "cctk_Config.h" + #ifdef __cplusplus -extern "C" { -#endif +#include +/* Macro to declare a set of complex functions for a given precision */ +/* Note: We do not declare these as extern "C" since that they are + different from their C counterparts */ +#define DECLARE_CMPLX_FUNCTIONS(CCTK_Cmplx, cctk_real, cctk_complex) \ +static inline cctk_complex CCTK_Cmplx(cctk_real Re, cctk_real Im) { \ + return cctk_complex(Re,Im); \ +} \ +static inline cctk_real CCTK_Cmplx##Real(cctk_complex a) { \ + return std::real(a); \ +} \ +static inline cctk_real CCTK_Cmplx##Imag(cctk_complex a) { \ + return std::imag(a); \ +} \ +static inline cctk_complex CCTK_Cmplx##Neg(cctk_complex a) { \ + return -a; \ +} \ +static inline cctk_complex CCTK_Cmplx##Conjg(cctk_complex a) { \ + return std::conj(a); \ +} \ +static inline cctk_real CCTK_Cmplx##Abs(cctk_complex a) { \ + return std::abs(a); \ +} \ +static inline cctk_real CCTK_Cmplx##Arg(cctk_complex a) { \ + return std::arg(a); \ +} \ +static inline cctk_real CCTK_Cmplx##Norm(cctk_complex a) { \ + return std::norm(a); \ +} \ +static inline cctk_complex CCTK_Cmplx##Add(cctk_complex a, cctk_complex b) { \ + return a+b; \ +} \ +static inline cctk_complex CCTK_Cmplx##Sub(cctk_complex a, cctk_complex b) { \ + return a-b; \ +} \ +static inline cctk_complex CCTK_Cmplx##Mul(cctk_complex a, cctk_complex b) { \ + return a*b; \ +} \ +static inline cctk_complex CCTK_Cmplx##Div(cctk_complex a, cctk_complex b) { \ + return a/b; \ +} \ +static inline cctk_complex CCTK_Cmplx##CPow(cctk_complex a, cctk_complex b) { \ + return pow(a,b); \ +} \ +static inline cctk_complex CCTK_Cmplx##Sin(cctk_complex a) { \ + return std::sin(a); \ +} \ +static inline cctk_complex CCTK_Cmplx##Cos(cctk_complex a) { \ + return std::cos(a); \ +} \ +static inline cctk_complex CCTK_Cmplx##Exp(cctk_complex a) { \ + return std::exp(a); \ +} \ +static inline cctk_complex CCTK_Cmplx##Log(cctk_complex a) { \ + return std::log(a); \ +} \ +static inline cctk_complex CCTK_Cmplx##Sqrt(cctk_complex a) { \ + return std::sqrt(a); \ +} \ +static inline cctk_complex CCTK_Cmplx##Pow(cctk_complex a, cctk_real b) { \ + return std::pow(a,b); \ +} \ +static inline cctk_complex CCTK_Cmplx##IPow(cctk_complex a, int b) { \ + return std::pow(a,(cctk_real)b); \ +} -/* macro to declare a set of complex functions for a given precision */ +#else + +/* Macro to declare a set of complex functions for a given precision */ +/* Note: We do not provide inline implementations here, since this + would require including , which pushes the identifier + "I" into the global namespace. */ #define DECLARE_CMPLX_FUNCTIONS(CCTK_Cmplx, cctk_real, cctk_complex) \ -cctk_complex CCTK_Cmplx (cctk_real Re, cctk_real Im); \ -cctk_real CCTK_Cmplx##Real (cctk_complex a); \ -cctk_real CCTK_Cmplx##Imag (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Neg (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Conjg (cctk_complex a); \ -cctk_real CCTK_Cmplx##Abs (cctk_complex a); \ -cctk_real CCTK_Cmplx##Arg (cctk_complex a); \ -cctk_real CCTK_Cmplx##Norm (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Add (cctk_complex a, cctk_complex b); \ -cctk_complex CCTK_Cmplx##Sub (cctk_complex a, cctk_complex b); \ -cctk_complex CCTK_Cmplx##Mul (cctk_complex a, cctk_complex b); \ -cctk_complex CCTK_Cmplx##Div (cctk_complex a, cctk_complex b); \ -cctk_complex CCTK_Cmplx##CPow (cctk_complex a, cctk_complex b); \ -cctk_complex CCTK_Cmplx##Sin (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Cos (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Exp (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Log (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Sqrt (cctk_complex a); \ -cctk_complex CCTK_Cmplx##Pow (cctk_complex a, cctk_real b); \ -cctk_complex CCTK_Cmplx##IPow (cctk_complex a, int b); +cctk_complex CCTK_Cmplx(cctk_real Re, cctk_real Im); \ +cctk_real CCTK_Cmplx##Real(cctk_complex a); \ +cctk_real CCTK_Cmplx##Imag(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Neg(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Conjg(cctk_complex a); \ +cctk_real CCTK_Cmplx##Abs(cctk_complex a); \ +cctk_real CCTK_Cmplx##Arg(cctk_complex a); \ +cctk_real CCTK_Cmplx##Norm(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Add(cctk_complex a, cctk_complex b); \ +cctk_complex CCTK_Cmplx##Sub(cctk_complex a, cctk_complex b); \ +cctk_complex CCTK_Cmplx##Mul(cctk_complex a, cctk_complex b); \ +cctk_complex CCTK_Cmplx##Div(cctk_complex a, cctk_complex b); \ +cctk_complex CCTK_Cmplx##CPow(cctk_complex a, cctk_complex b); \ +cctk_complex CCTK_Cmplx##Sin(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Cos(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Exp(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Log(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Sqrt(cctk_complex a); \ +cctk_complex CCTK_Cmplx##Pow(cctk_complex a, cctk_real b); \ +cctk_complex CCTK_Cmplx##IPow(cctk_complex a, int b); +#endif -/* declare complex functions for all available precisions */ + +/* Declare complex functions for all available precisions */ #ifdef HAVE_CCTK_REAL4 DECLARE_CMPLX_FUNCTIONS (CCTK_Cmplx8, CCTK_REAL4, CCTK_COMPLEX8) #endif @@ -54,74 +126,70 @@ #endif -/* declare the default precision complex functions as #define'd macros */ +/* Declare the default precision complex functions as #define'd macros */ #ifdef CCTK_REAL_PRECISION_4 -#define CCTK_Cmplx CCTK_Cmplx8 -#define CCTK_CmplxReal CCTK_Cmplx8Real -#define CCTK_CmplxImag CCTK_Cmplx8Imag -#define CCTK_CmplxNeg CCTK_Cmplx8Neg -#define CCTK_CmplxConjg CCTK_Cmplx8Conjg -#define CCTK_CmplxAbs CCTK_Cmplx8Abs -#define CCTK_CmplxArg CCTK_Cmplx8Arg -#define CCTK_CmplxNorm CCTK_Cmplx8Norm -#define CCTK_CmplxAdd CCTK_Cmplx8Add -#define CCTK_CmplxSub CCTK_Cmplx8Sub -#define CCTK_CmplxMul CCTK_Cmplx8Mul -#define CCTK_CmplxDiv CCTK_Cmplx8Div -#define CCTK_CmplxCPow CCTK_Cmplx8CPow -#define CCTK_CmplxSin CCTK_Cmplx8Sin -#define CCTK_CmplxCos CCTK_Cmplx8Cos -#define CCTK_CmplxExp CCTK_Cmplx8Exp -#define CCTK_CmplxLog CCTK_Cmplx8Log -#define CCTK_CmplxSqrt CCTK_Cmplx8Sqrt -#define CCTK_CmplxPow CCTK_Cmplx8Pow -#define CCTK_CmplxIPow CCTK_Cmplx8IPow +# define CCTK_Cmplx CCTK_Cmplx8 +# define CCTK_CmplxReal CCTK_Cmplx8Real +# define CCTK_CmplxImag CCTK_Cmplx8Imag +# define CCTK_CmplxNeg CCTK_Cmplx8Neg +# define CCTK_CmplxConjg CCTK_Cmplx8Conjg +# define CCTK_CmplxAbs CCTK_Cmplx8Abs +# define CCTK_CmplxArg CCTK_Cmplx8Arg +# define CCTK_CmplxNorm CCTK_Cmplx8Norm +# define CCTK_CmplxAdd CCTK_Cmplx8Add +# define CCTK_CmplxSub CCTK_Cmplx8Sub +# define CCTK_CmplxMul CCTK_Cmplx8Mul +# define CCTK_CmplxDiv CCTK_Cmplx8Div +# define CCTK_CmplxCPow CCTK_Cmplx8CPow +# define CCTK_CmplxSin CCTK_Cmplx8Sin +# define CCTK_CmplxCos CCTK_Cmplx8Cos +# define CCTK_CmplxExp CCTK_Cmplx8Exp +# define CCTK_CmplxLog CCTK_Cmplx8Log +# define CCTK_CmplxSqrt CCTK_Cmplx8Sqrt +# define CCTK_CmplxPow CCTK_Cmplx8Pow +# define CCTK_CmplxIPow CCTK_Cmplx8IPow #elif CCTK_REAL_PRECISION_8 -#define CCTK_Cmplx CCTK_Cmplx16 -#define CCTK_CmplxReal CCTK_Cmplx16Real -#define CCTK_CmplxImag CCTK_Cmplx16Imag -#define CCTK_CmplxNeg CCTK_Cmplx16Neg -#define CCTK_CmplxConjg CCTK_Cmplx16Conjg -#define CCTK_CmplxAbs CCTK_Cmplx16Abs -#define CCTK_CmplxArg CCTK_Cmplx16Arg -#define CCTK_CmplxNorm CCTK_Cmplx16Norm -#define CCTK_CmplxAdd CCTK_Cmplx16Add -#define CCTK_CmplxSub CCTK_Cmplx16Sub -#define CCTK_CmplxMul CCTK_Cmplx16Mul -#define CCTK_CmplxDiv CCTK_Cmplx16Div -#define CCTK_CmplxCPow CCTK_Cmplx16CPow -#define CCTK_CmplxSin CCTK_Cmplx16Sin -#define CCTK_CmplxCos CCTK_Cmplx16Cos -#define CCTK_CmplxExp CCTK_Cmplx16Exp -#define CCTK_CmplxLog CCTK_Cmplx16Log -#define CCTK_CmplxSqrt CCTK_Cmplx16Sqrt -#define CCTK_CmplxPow CCTK_Cmplx16Pow -#define CCTK_CmplxIPow CCTK_Cmplx16IPow +# define CCTK_Cmplx CCTK_Cmplx16 +# define CCTK_CmplxReal CCTK_Cmplx16Real +# define CCTK_CmplxImag CCTK_Cmplx16Imag +# define CCTK_CmplxNeg CCTK_Cmplx16Neg +# define CCTK_CmplxConjg CCTK_Cmplx16Conjg +# define CCTK_CmplxAbs CCTK_Cmplx16Abs +# define CCTK_CmplxArg CCTK_Cmplx16Arg +# define CCTK_CmplxNorm CCTK_Cmplx16Norm +# define CCTK_CmplxAdd CCTK_Cmplx16Add +# define CCTK_CmplxSub CCTK_Cmplx16Sub +# define CCTK_CmplxMul CCTK_Cmplx16Mul +# define CCTK_CmplxDiv CCTK_Cmplx16Div +# define CCTK_CmplxCPow CCTK_Cmplx16CPow +# define CCTK_CmplxSin CCTK_Cmplx16Sin +# define CCTK_CmplxCos CCTK_Cmplx16Cos +# define CCTK_CmplxExp CCTK_Cmplx16Exp +# define CCTK_CmplxLog CCTK_Cmplx16Log +# define CCTK_CmplxSqrt CCTK_Cmplx16Sqrt +# define CCTK_CmplxPow CCTK_Cmplx16Pow +# define CCTK_CmplxIPow CCTK_Cmplx16IPow #elif CCTK_REAL_PRECISION_16 -#define CCTK_Cmplx CCTK_Cmplx32 -#define CCTK_CmplxReal CCTK_Cmplx32Real -#define CCTK_CmplxImag CCTK_Cmplx32Imag -#define CCTK_CmplxNeg CCTK_Cmplx32Neg -#define CCTK_CmplxConjg CCTK_Cmplx32Conjg -#define CCTK_CmplxAbs CCTK_Cmplx32Abs -#define CCTK_CmplxArg CCTK_Cmplx32Arg -#define CCTK_CmplxNorm CCTK_Cmplx32Norm -#define CCTK_CmplxAdd CCTK_Cmplx32Add -#define CCTK_CmplxSub CCTK_Cmplx32Sub -#define CCTK_CmplxMul CCTK_Cmplx32Mul -#define CCTK_CmplxDiv CCTK_Cmplx32Div -#define CCTK_CmplxCPow CCTK_Cmplx32CPow -#define CCTK_CmplxSin CCTK_Cmplx32Sin -#define CCTK_CmplxCos CCTK_Cmplx32Cos -#define CCTK_CmplxExp CCTK_Cmplx32Exp -#define CCTK_CmplxLog CCTK_Cmplx32Log -#define CCTK_CmplxSqrt CCTK_Cmplx32Sqrt -#define CCTK_CmplxPow CCTK_Cmplx32Pow -#define CCTK_CmplxIPow CCTK_Cmplx32IPow +# define CCTK_Cmplx CCTK_Cmplx32 +# define CCTK_CmplxReal CCTK_Cmplx32Real +# define CCTK_CmplxImag CCTK_Cmplx32Imag +# define CCTK_CmplxNeg CCTK_Cmplx32Neg +# define CCTK_CmplxConjg CCTK_Cmplx32Conjg +# define CCTK_CmplxAbs CCTK_Cmplx32Abs +# define CCTK_CmplxArg CCTK_Cmplx32Arg +# define CCTK_CmplxNorm CCTK_Cmplx32Norm +# define CCTK_CmplxAdd CCTK_Cmplx32Add +# define CCTK_CmplxSub CCTK_Cmplx32Sub +# define CCTK_CmplxMul CCTK_Cmplx32Mul +# define CCTK_CmplxDiv CCTK_Cmplx32Div +# define CCTK_CmplxCPow CCTK_Cmplx32CPow +# define CCTK_CmplxSin CCTK_Cmplx32Sin +# define CCTK_CmplxCos CCTK_Cmplx32Cos +# define CCTK_CmplxExp CCTK_Cmplx32Exp +# define CCTK_CmplxLog CCTK_Cmplx32Log +# define CCTK_CmplxSqrt CCTK_Cmplx32Sqrt +# define CCTK_CmplxPow CCTK_Cmplx32Pow +# define CCTK_CmplxIPow CCTK_Cmplx32IPow #endif -#ifdef __cplusplus -} -#endif - #endif /* _CCTK_COMPLEX_H_ */ Index: main/Complex.c =================================================================== --- main/Complex.c (revision 5076) +++ main/Complex.c (working copy) @@ -1,669 +1,94 @@ /*@@ @file Complex.c - @date Tue Dec 14 12:09:43 1999 - @author Tom Goodale + @date 2014-02-07 + @author Erik Schnetter @desc Complex variable stuff @enddesc - @version $Id$ @@*/ +#include "cctk_Complex.h" + #include #include -#include "cctk_Flesh.h" -#ifndef DEFINE_CCTK_COMPLEX_INLINE_FUNCTIONS -# define DEFINE_CCTK_COMPLEX_EXTERN_FUNCTIONS -# include "cctk_Complex.h" -# undef DEFINE_CCTK_COMPLEX_EXTERN_FUNCTIONS -#endif - -#ifndef DEFINE_CCTK_COMPLEX_INLINE_FUNCTIONS - -static const char *rcsid = "$Header$"; - -CCTK_FILEVERSION(main_Complex_c); - -#endif - - -/******************************************************************** - ********************* Local Data Types *********************** - ********************************************************************/ - -/******************************************************************** - ********************* Local Routine Prototypes ********************* - ********************************************************************/ - -/******************************************************************** - ********************* Other Routine Prototypes ********************* - ********************************************************************/ - -/******************************************************************** - ********************* Local Data ***************************** - ********************************************************************/ - -/******************************************************************** - ********************* External Routines ********************** - ********************************************************************/ - - /*@@ - @routine CCTK_Cmplx - @date Tue Dec 14 12:16:01 1999 - @author Tom Goodale - @desc - Turns two reals into a complex number - @enddesc - - @var Re - @vdesc Real part - @vtype CCTK_REAL - @vio in - @endvar - @var Im - @vdesc Imaginary part - @vtype CCTK_REAL - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The complex number - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx (cctk_real Re, cctk_real Im) \ -{ \ - return Re + _Complex_I * Im; \ -} - - - /*@@ - @routine CCTK_CmplxReal - @date Tue Dec 14 12:22:41 1999 - @author Tom Goodale - @desc - Returns the real part of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_REAL - @returndesc - The real part - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_REAL(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_real CCTK_Cmplx##Real (cctk_complex x) \ -{ \ - return creal##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxImag - @date Tue Dec 14 12:22:41 1999 - @author Tom Goodale - @desc - Returns the imaginary part of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_REAL - @returndesc - The imaginary part - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_IMAG(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_real CCTK_Cmplx##Imag (cctk_complex x) \ -{ \ - return cimag##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxNeg - @date 2006-06-07 - @author Erik Schnetter - @desc - Returns the negative of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The negative - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_NEG(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Neg (cctk_complex x) \ -{ \ - return -x; \ -} - - - /*@@ - @routine CCTK_CmplxConjg - @date Tue Dec 14 12:22:41 1999 - @author Tom Goodale - @desc - Returns the complex conjugate of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The complex conjugate - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_CONJG(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Conjg (cctk_complex x) \ -{ \ - return conj##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxAbs - @date Tue Dec 14 12:26:33 1999 - @author Tom Goodale - @desc - Return the absolute value of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_REAL - @returndesc - The absolute value of the complex number - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_ABS(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_real CCTK_Cmplx##Abs (cctk_complex x) \ -{ \ - return cabs##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxNorm - @date 2006-07-06 - @author Erik Schnetter - @desc - Return the absolute value squared of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_REAL - @returndesc - The absolute value squared of the complex number - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_NORM(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_real CCTK_Cmplx##Norm (cctk_complex x) \ -{ \ - return creal##type(x)*creal##type(x) + cimag##type(x)*cimag##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxArg - @date 2005-11-17 - @author Erik Schnetter - @desc - Return the argument of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_REAL - @returndesc - The argument of the complex number - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_ARG(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_real CCTK_Cmplx##Arg (cctk_complex x) \ -{ \ - return carg##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxAdd - @date Sat Dec 4 12:11:04 1999 - @author Gabrielle Allen - @desc - Adds two complex numbers - @enddesc - - @var a - @vdesc First summand - @vtype CCTK_COMPLEX - @vio in - @endvar - @var b - @vdesc Second summand - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The sum of a and b - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_ADD(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Add (cctk_complex a, cctk_complex b) \ -{ \ +/* Macro to define a set of complex functions for a given precision */ +#define DEFINE_CMPLX_FUNCTIONS(CCTK_Cmplx, cctk_real, cctk_complex, suffix) \ +cctk_complex CCTK_Cmplx(cctk_real Re, cctk_real Im) { \ + return Re + I*Im; \ +} \ +cctk_real CCTK_Cmplx##Real(cctk_complex a) { \ + return creal##suffix(a); \ +} \ +cctk_real CCTK_Cmplx##Imag(cctk_complex a) { \ + return cimag##suffix(a); \ +} \ +cctk_complex CCTK_Cmplx##Neg(cctk_complex a) { \ + return -a; \ +} \ +cctk_complex CCTK_Cmplx##Conjg(cctk_complex a) { \ + return conj##suffix(a); \ +} \ +cctk_real CCTK_Cmplx##Abs(cctk_complex a) { \ + return (creal##suffix(a)*creal##suffix(a) + \ + cimag##suffix(a)*cimag##suffix(a)); \ +} \ +cctk_real CCTK_Cmplx##Arg(cctk_complex a) { \ + return carg##suffix(a); \ +} \ +cctk_real CCTK_Cmplx##Norm(cctk_complex a) { \ + return cabs##suffix(a); \ +} \ +cctk_complex CCTK_Cmplx##Add(cctk_complex a, cctk_complex b) { \ return a+b; \ -} - - - /*@@ - @routine CCTK_CmplxSub - @date Sat Dec 4 12:11:04 1999 - @author Gabrielle Allen - @desc - Subtracts two complex numbers - @enddesc - - @var a - @vdesc First operand - @vtype CCTK_COMPLEX - @vio in - @endvar - @var b - @vdesc Second operand - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The difference - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_SUB(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Sub (cctk_complex a, cctk_complex b) \ -{ \ +} \ +cctk_complex CCTK_Cmplx##Sub(cctk_complex a, cctk_complex b) { \ return a-b; \ -} - - - /*@@ - @routine CCTK_CmplxMul - @date Sat Dec 4 12:11:04 1999 - @author Gabrielle Allen - @desc - Multiplies two complex numbers - @enddesc - - @var a - @vdesc First operand - @vtype CCTK_COMPLEX - @vio in - @endvar - @var b - @vdesc Second operand - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The product - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_MUL(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Mul (cctk_complex a, cctk_complex b) \ -{ \ +} \ +cctk_complex CCTK_Cmplx##Mul(cctk_complex a, cctk_complex b) { \ return a*b; \ -} - - - /*@@ - @routine CCTK_CmplxDiv - @date Sat Dec 4 12:11:04 1999 - @author Gabrielle Allen - @desc - Divide two complex numbers. - @enddesc - - @var a - @vdesc First operand - @vtype CCTK_COMPLEX - @vio in - @endvar - @var b - @vdesc Second operand - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The quotient - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_DIV(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Div (cctk_complex a, cctk_complex b) \ -{ \ +} \ +cctk_complex CCTK_Cmplx##Div(cctk_complex a, cctk_complex b) { \ return a/b; \ +} \ +cctk_complex CCTK_Cmplx##CPow(cctk_complex a, cctk_complex b) { \ + return cpow##suffix(a,b); \ +} \ +cctk_complex CCTK_Cmplx##Sin(cctk_complex a) { \ + return csin##suffix(a); \ +} \ +cctk_complex CCTK_Cmplx##Cos(cctk_complex a) { \ + return ccos##suffix(a); \ +} \ +cctk_complex CCTK_Cmplx##Exp(cctk_complex a) { \ + return cexp##suffix(a); \ +} \ +cctk_complex CCTK_Cmplx##Log(cctk_complex a) { \ + return clog##suffix(a); \ +} \ +cctk_complex CCTK_Cmplx##Sqrt(cctk_complex a) { \ + return csqrt##suffix(a); \ +} \ +cctk_complex CCTK_Cmplx##Pow(cctk_complex a, cctk_real b) { \ + return cpow##suffix(a,b); \ +} \ +cctk_complex CCTK_Cmplx##IPow(cctk_complex a, int b) { \ + return cpow##suffix(a,(cctk_real)b); \ } - /*@@ - @routine CCTK_CmplxCPow - @date 2005-11-17 - @author Erik Schnetter - @desc - Raises a complex number to a given power - @enddesc - - @var a - @vdesc The base - @vtype CCTK_COMPLEX - @vio in - @endvar - @var b - @vdesc The exponent - @vtype CCTK_COMPLEX - @vio in - @endvar - @returntype CCTK_COMPLEX - @returndesc - a to the power of b - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_CPOW(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##CPow (cctk_complex a, cctk_complex b) \ -{ \ - return cpow##type(a, b); \ -} - - - /*@@ - @routine CCTK_CmplxSin - @date Wed 12 Dec 2001 - @author Thomas Radke - @desc - Returns the sine of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The sine - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_SIN(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Sin (cctk_complex x) \ -{ \ - return csin##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxCos - @date Wed 12 Dec 2001 - @author Thomas Radke - @desc - Returns the cosine of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The cosine - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_COS(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Cos (cctk_complex x) \ -{ \ - return ccos##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxExp - @date Wed 12 Dec 2001 - @author Thomas Radke - @desc - Returns the exponential of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The exponential - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_EXP(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Exp (cctk_complex x) \ -{ \ - return cexp##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxLog - @date 2005-11-17 - @author Erik Schnetter - @desc - Returns the logarithm of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The logarithm - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_LOG(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Log (cctk_complex x) \ -{ \ - return clog##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxSqrt - @date Wed 12 Dec 2001 - @author Thomas Radke - @desc - Returns the square root of a complex number. - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The square root - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_SQRT(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Sqrt (cctk_complex x) \ -{ \ - return csqrt##type(x); \ -} - - - /*@@ - @routine CCTK_CmplxPow - @date - @author Yaakoub Y El Khamra - @desc - Raises a complex number to a given power - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - @var w - @vdesc The exponent - @vtype CCTK_REAL - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The power of the complex number - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_POW(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##Pow (cctk_complex x, cctk_real w) \ -{ \ - return cpow##type(x, w); \ -} - - - /*@@ - @routine CCTK_CmplxIPow - @date - @author Erik Schnetter - @desc - Raises a complex number to a given power - @enddesc - - @var x - @vdesc The complex number - @vtype CCTK_COMPLEX - @vio in - @endvar - @var w - @vdesc The exponent - @vtype int - @vio in - @endvar - - @returntype CCTK_COMPLEX - @returndesc - The power of the complex number - @endreturndesc -@@*/ -#define DEFINE_CCTK_CMPLX_IPOW(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -cctk_complex CCTK_Cmplx##IPow (cctk_complex x, int w) \ -{ \ - int w0 = w; \ - cctk_complex result = 1; \ - while (w) \ - { \ - if (w % 2) \ - { \ - result *= x; \ - } \ - w /= 2; \ - x *= x; \ - } \ - if (w0 < 0) \ - { \ - result = 1 / result; \ - } \ - return result; \ -} - - - -/* macro to define a set of complex functions for a given precision */ -#define DEFINE_CMPLX_FUNCTIONS(CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_REAL (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_IMAG (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_NEG (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_CONJG (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_ABS (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_NORM (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_ARG (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_ADD (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_SUB (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_MUL (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_DIV (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_CPOW (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_SIN (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_COS (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_EXP (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_LOG (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_SQRT (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_POW (CCTK_Cmplx, cctk_real, cctk_complex, type) \ -DEFINE_CCTK_CMPLX_IPOW (CCTK_Cmplx, cctk_real, cctk_complex, type) - - -/* define complex functions for all available precisions */ +/* Define complex functions for all available precisions */ #ifdef HAVE_CCTK_REAL4 - #define KIND_SUFFIX f - DEFINE_CMPLX_FUNCTIONS (CCTK_Cmplx8, CCTK_REAL4, CCTK_COMPLEX8, KIND_SUFFIX) - #undef KIND_SUFFIX +DEFINE_CMPLX_FUNCTIONS (CCTK_Cmplx8, CCTK_REAL4, CCTK_COMPLEX8, f) #endif #ifdef HAVE_CCTK_REAL8 - #define KIND_SUFFIX - DEFINE_CMPLX_FUNCTIONS (CCTK_Cmplx16, CCTK_REAL8, CCTK_COMPLEX16, KIND_SUFFIX) - #undef KIND_SUFFIX +DEFINE_CMPLX_FUNCTIONS (CCTK_Cmplx16, CCTK_REAL8, CCTK_COMPLEX16, ) #endif #ifdef HAVE_CCTK_REAL16 - #define KIND_SUFFIX l - DEFINE_CMPLX_FUNCTIONS (CCTK_Cmplx32, CCTK_REAL16, CCTK_COMPLEX32, KIND_SUFFIX) - #undef KIND_SUFFIX +DEFINE_CMPLX_FUNCTIONS (CCTK_Cmplx32, CCTK_REAL16, CCTK_COMPLEX32, l) #endif