diff options
author | Ian Hinder <ian.hinder@aei.mpg.de> | 2012-05-01 21:58:57 +0200 |
---|---|---|
committer | Ian Hinder <ian.hinder@aei.mpg.de> | 2012-05-02 09:25:32 +0200 |
commit | 90900d18be8a0b77eb736e622195eecaeaf93bbd (patch) | |
tree | 901a9c60d95301fbc45c48a53625271af2ca305d /Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h | |
parent | 3440bea2b6531a259bbc73d070d5bea69280b717 (diff) |
GenericFD: Correct implementation of Sign
Mathematica defines Sign(x) = Which[x>0, 1, x<0, -1, x==0, 0] whereas
the current implementation in terms of copysign gives Sign(0) != 0.
This causes problems when Sign is used to choose the finite
differencing operator in boundary conditions. This commit restores
the old definition in terms of the sgn function which we define now as
static inline in GenericFD.h.
Diffstat (limited to 'Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h')
-rw-r--r-- | Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h index 53e8035..217b931 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h @@ -54,7 +54,11 @@ extern "C" { #define KRANC_GFOFFSET3D(var,i,j,k) \ (*(CCTK_REAL const*)&((char const*)(var))[cdi*(i)+cdj*(j)+cdk*(k)]) -int sgn(CCTK_REAL x); +/* Implement the signum function, used for Mathematica's Sign function */ +static inline CCTK_REAL sgn(CCTK_REAL x) +{ + return x==(CCTK_REAL)0.0 ? (CCTK_REAL)0.0 : copysign((CCTK_REAL)1.0, x); +} int GenericFD_GetBoundaryWidth(cGH const * restrict const cctkGH); |