From db07cbed6b6ef1c926e276a961ff8e9264ba9281 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 6 May 2017 09:44:06 +0200 Subject: [PATCH] use correct type for PI (double). promote defines to platform-header. --- src/platform.h | 6 ++++++ src/util/rand.c | 6 ++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/platform.h b/src/platform.h index fba2078bb..97d254e2d 100644 --- a/src/platform.h +++ b/src/platform.h @@ -48,4 +48,10 @@ char * strdup(const char *s); int mkdir(const char *pathname, int mode); #endif +/* do not use M_PI, use one of these instead: */ +#define PI_F 3.1415926535897932384626433832795F +#define PI_D 3.1415926535897932384626433832795 +#define PI_L 3.1415926535897932384626433832795L + + #endif diff --git a/src/util/rand.c b/src/util/rand.c index bd8543b9e..441461068 100644 --- a/src/util/rand.c +++ b/src/util/rand.c @@ -28,8 +28,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -#define PI_L 3.1415926535897932384626433832795L - int lovar(double xpct_x2) { int n = (int)(xpct_x2 * 500) + 1; @@ -51,10 +49,10 @@ double normalvariate(double mu, double sigma) if (phase == 0) { U = (rng_int() + 1.) / (RNG_RAND_MAX + 2.); V = rng_int() / (RNG_RAND_MAX + 1.); - Z = sqrt(-2 * log(U)) * sin(2 * PI_L * V); + Z = sqrt(-2 * log(U)) * sin(2 * PI_D * V); } else { - Z = sqrt(-2 * log(U)) * cos(2 * PI_L * V); + Z = sqrt(-2 * log(U)) * cos(2 * PI_D * V); } phase = 1 - phase;