From 15f2c6796862e442efa0dce4ba656eda0e9b3eb6 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 4 Sep 2016 20:04:30 +0200 Subject: [PATCH] use M_PI --- src/include/ngspice/cm.h | 13 +++++++++++++ src/include/ngspice/complex.h | 4 ++-- src/maths/misc/erfc.c | 3 +-- src/spicelib/devices/cpl/cplsetup.c | 2 +- src/xspice/icm/analog/sine/cfunc.mod | 4 +--- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/include/ngspice/cm.h b/src/include/ngspice/cm.h index d05cbf673..3b13d15be 100644 --- a/src/include/ngspice/cm.h +++ b/src/include/ngspice/cm.h @@ -47,6 +47,19 @@ NON-STANDARD FEATURES #include +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif +#ifndef M_E +# define M_E 2.7182818284590452354 +#endif +#ifndef M_LOG2E +# define M_LOG2E 1.4426950408889634074 +#endif +#ifndef M_LOG10E +# define M_LOG10E 0.43429448190325182765 +#endif + #if !defined(NAN) #if defined(_MSC_VER) /* NAN is not defined in VS 2012 or older */ diff --git a/src/include/ngspice/complex.h b/src/include/ngspice/complex.h index 307663d34..f8d8c334e 100644 --- a/src/include/ngspice/complex.h +++ b/src/include/ngspice/complex.h @@ -72,8 +72,8 @@ typedef struct { #define FTEcabs(d) (((d) < 0.0) ? - (d) : (d)) #define cph(c) (atan2(imagpart(c), (realpart(c)))) #define cmag(c) (hypot(realpart(c), imagpart(c))) -#define radtodeg(c) (cx_degrees ? ((c) / 3.14159265358979323846 * 180) : (c)) -#define degtorad(c) (cx_degrees ? ((c) * 3.14159265358979323846 / 180) : (c)) +#define radtodeg(c) (cx_degrees ? ((c) * (180 / M_PI)) : (c)) +#define degtorad(c) (cx_degrees ? ((c) * (M_PI / 180)) : (c)) #define rcheck(cond, name) if (!(cond)) { \ fprintf(cp_err, "Error: argument out of range for %s\n", name); \ return (NULL); } diff --git a/src/maths/misc/erfc.c b/src/maths/misc/erfc.c index d335b26ef..015bae3c7 100644 --- a/src/maths/misc/erfc.c +++ b/src/maths/misc/erfc.c @@ -4,7 +4,6 @@ Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group **********/ #include "ngspice/ngspice.h" -#include "ngspice/numconst.h" #ifndef HAVE_ERFC @@ -12,7 +11,7 @@ Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group double erfc (double x) { double sqrtPi, n, temp1, xSq, sum1, sum2; - sqrtPi = sqrt( PI ); + sqrtPi = sqrt( M_PI ); x = ABS( x ); n = 1.0; xSq = 2.0 * x * x; diff --git a/src/spicelib/devices/cpl/cplsetup.c b/src/spicelib/devices/cpl/cplsetup.c index 0ad24d9ab..cdaa01eb3 100644 --- a/src/spicelib/devices/cpl/cplsetup.c +++ b/src/spicelib/devices/cpl/cplsetup.c @@ -1760,7 +1760,7 @@ find_roots(double a1, double a2, double a3, double *x1, double *x2, double *x3) if (q != 0.0) { t = atan(sqrt((double)-t)/q); if (t < 0.0) - t += 3.141592654; + t += M_PI; t /= 3.0; x = 2.0 * pow(p, 0.16666667) * cos(t) - a1 / 3.0; } else { diff --git a/src/xspice/icm/analog/sine/cfunc.mod b/src/xspice/icm/analog/sine/cfunc.mod index 139dacd84..1e4c0b7ed 100644 --- a/src/xspice/icm/analog/sine/cfunc.mod +++ b/src/xspice/icm/analog/sine/cfunc.mod @@ -57,8 +57,6 @@ NON-STANDARD FEATURES /*=== CONSTANTS ========================*/ -#define PI 3.14159265358979323846 - #define INT1 1 char *allocation_error = "\n**** Error ****\nSINE: Error allocating sine block storage \n"; @@ -216,7 +214,7 @@ cm_sine(ARGS) center = (output_hi + output_low) / 2; *phase = *phase1 + freq*(TIME - T(1)); - radian = *phase * 2.0 * PI; + radian = *phase * 2.0 * M_PI; OUTPUT(out) = peak * sin(radian) + center; PARTIAL(out, cntl_in) = 0;