From 94e3abd847eb657a66d53efb4a6982604eb10e79 Mon Sep 17 00:00:00 2001 From: rlar Date: Tue, 7 Feb 2012 19:49:31 +0000 Subject: [PATCH] #2/4 switch cph() and cmag() args from ngcomplex* to ngcomplex --- ChangeLog | 9 +++++++++ src/frontend/diff.c | 6 +++--- src/include/ngspice/complex.h | 4 ++-- src/maths/cmaths/cmath1.c | 22 +++++++++++----------- src/maths/cmaths/cmath2.c | 8 ++++---- src/maths/cmaths/cmath3.c | 4 ++-- src/maths/cmaths/cmath4.c | 2 +- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6df378ea8..0d04b9030 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-02-07 Robert Larice + * src/frontend/diff.c , + * src/include/ngspice/complex.h , + * src/maths/cmaths/cmath1.c , + * src/maths/cmaths/cmath2.c , + * src/maths/cmaths/cmath3.c , + * src/maths/cmaths/cmath4.c : + #2/4 switch cph() and cmag() args from ngcomplex* to ngcomplex + 2012-02-07 Robert Larice * src/include/ngspice/complex.h : #1/4 drop cast (enable compiler type check) diff --git a/src/frontend/diff.c b/src/frontend/diff.c index 7f0deb15a..dc2ded5e9 100644 --- a/src/frontend/diff.c +++ b/src/frontend/diff.c @@ -243,11 +243,11 @@ com_diff(wordlist *wl) realpart(&c3) = realpart(&c1) - realpart(&c2); imagpart(&c3) = imagpart(&c1) - imagpart(&c2); /* Stupid evil PC compilers */ - cm1 = cmag(&c1); - cm2 = cmag(&c2); + cm1 = cmag(c1); + cm2 = cmag(c2); cmax = MAX(cm1, cm2); if (cmax * reltol + - tol < cmag(&c3)) { + tol < cmag(c3)) { printnum(numbuf, realpart(&c1)); printnum(numbuf2, imagpart(&c1)); diff --git a/src/include/ngspice/complex.h b/src/include/ngspice/complex.h index 35ad12d61..6c3c5de5d 100644 --- a/src/include/ngspice/complex.h +++ b/src/include/ngspice/complex.h @@ -70,8 +70,8 @@ typedef struct { /* Some defines used mainly in cmath.c. */ #define FTEcabs(d) (((d) < 0.0) ? - (d) : (d)) -#define cph(c) (atan2(imagpart(c), (realpart(c)))) -#define cmag(c) (sqrt(imagpart(c) * imagpart(c) + realpart(c) * realpart(c))) +#define cph(c) (atan2(imagpart(&(c)), (realpart(&(c))))) +#define cmag(c) (sqrt(imagpart(&(c)) * imagpart(&(c)) + realpart(&(c)) * realpart(&(c)))) #define radtodeg(c) (cx_degrees ? ((c) / 3.14159265358979323846 * 180) : (c)) #define degtorad(c) (cx_degrees ? ((c) * 3.14159265358979323846 / 180) : (c)) #define rcheck(cond, name) if (!(cond)) { \ diff --git a/src/maths/cmaths/cmath1.c b/src/maths/cmaths/cmath1.c index c720c45d0..66b98b097 100644 --- a/src/maths/cmaths/cmath1.c +++ b/src/maths/cmaths/cmath1.c @@ -49,7 +49,7 @@ cx_mag(void *data, short int type, int length, int *newlength, short int *newtyp d[i] = FTEcabs(dd[i]); else for (i = 0; i < length; i++) - d[i] = cmag(&cc[i]); + d[i] = cmag(cc[i]); return ((void *) d); } @@ -64,7 +64,7 @@ cx_ph(void *data, short int type, int length, int *newlength, short int *newtype *newtype = VF_REAL; if (type == VF_COMPLEX) for (i = 0; i < length; i++) { - d[i] = radtodeg(cph(&cc[i])); + d[i] = radtodeg(cph(cc[i])); } /* Otherwise it is 0, but tmalloc zeros the stuff already. */ return ((void *) d); @@ -81,10 +81,10 @@ cx_cph(void *data, short int type, int length, int *newlength, short int *newtyp *newlength = length; *newtype = VF_REAL; if (type == VF_COMPLEX) { - double last_ph = cph(&cc[0]); + double last_ph = cph(cc[0]); d[0] = radtodeg(last_ph); for (i = 1; i < length; i++) { - double ph = cph(&cc[i]); + double ph = cph(cc[i]); last_ph = ph - (2*M_PI) * floor((ph - last_ph)/(2*M_PI) + 0.5); d[i] = radtodeg(last_ph); } @@ -190,7 +190,7 @@ cx_db(void *data, short int type, int length, int *newlength, short int *newtype *newtype = VF_REAL; if (type == VF_COMPLEX) for (i = 0; i < length; i++) { - tt = cmag(&cc[i]); + tt = cmag(cc[i]); rcheck(tt > 0, "db"); /* if (tt == 0.0) @@ -226,7 +226,7 @@ cx_log(void *data, short int type, int length, int *newlength, short int *newtyp for (i = 0; i < length; i++) { double td; - td = cmag(&cc[i]); + td = cmag(cc[i]); /* Perhaps we should trap when td = 0.0, but Ken wants * this to be possible... */ @@ -273,7 +273,7 @@ cx_ln(void *data, short int type, int length, int *newlength, short int *newtype for (i = 0; i < length; i++) { double td; - td = cmag(&cc[i]); + td = cmag(cc[i]); rcheck(td >= 0, "ln"); if (td == 0.0) { realpart(&c[i]) = - log(HUGE); @@ -378,10 +378,10 @@ cx_sqrt(void *data, short int type, int length, int *newlength, short int *newty imagpart(&c[i]) = 0.0; } else if (imagpart(&cc[i]) < 0.0) { realpart(&c[i]) = -sqrt(0.5 * - (cmag(&cc[i]) + realpart(&cc[i]))); + (cmag(cc[i]) + realpart(&cc[i]))); } else { realpart(&c[i]) = sqrt(0.5 * - (cmag(&cc[i]) + realpart(&cc[i]))); + (cmag(cc[i]) + realpart(&cc[i]))); } imagpart(&c[i]) = imagpart(&cc[i]) / (2.0 * realpart(&c[i])); @@ -393,11 +393,11 @@ cx_sqrt(void *data, short int type, int length, int *newlength, short int *newty } else { if (imagpart(&cc[i]) < 0.0) imagpart(&c[i]) = - sqrt(0.5 * - (cmag(&cc[i]) - + (cmag(cc[i]) - realpart(&cc[i]))); else imagpart(&c[i]) = sqrt(0.5 * - (cmag(&cc[i]) - + (cmag(cc[i]) - realpart(&cc[i]))); realpart(&c[i]) = imagpart(&cc[i]) / (2.0 * imagpart(&c[i])); diff --git a/src/maths/cmaths/cmath2.c b/src/maths/cmaths/cmath2.c index 2b4c175b8..bfe2a8b36 100644 --- a/src/maths/cmaths/cmath2.c +++ b/src/maths/cmaths/cmath2.c @@ -46,8 +46,8 @@ cx_max_local(void *data, short int type, int length) int i; for (i = 0; i < length; i++) - if (cmag(&cc[i]) > largest) - largest = cmag(&cc[i]); + if (cmag(cc[i]) > largest) + largest = cmag(cc[i]); } else { double *dd = (double *) data; int i; @@ -434,7 +434,7 @@ cx_vector(void *data, short int type, int length, int *newlength, short int *new if (type == VF_REAL) len = (int)FTEcabs(*dd); else - len = (int)cmag(cc); + len = (int)cmag(*cc); if (len == 0) len = 1; d = alloc_d(len); @@ -461,7 +461,7 @@ cx_unitvec(void *data, short int type, int length, int *newlength, short int *ne if (type == VF_REAL) len = (int)FTEcabs(*dd); else - len = (int)cmag(cc); + len = (int)cmag(*cc); if (len == 0) len = 1; d = alloc_d(len); diff --git a/src/maths/cmaths/cmath3.c b/src/maths/cmaths/cmath3.c index d032bcfe2..cf41f1fed 100644 --- a/src/maths/cmaths/cmath3.c +++ b/src/maths/cmaths/cmath3.c @@ -187,8 +187,8 @@ cln(ngcomplex_t *c) { static ngcomplex_t r; - rcheck(cmag(c) != 0, "ln"); - realpart(&r) = log(cmag(c)); + rcheck(cmag(*c) != 0, "ln"); + realpart(&r) = log(cmag(*c)); if (imagpart(c) != 0.0) imagpart(&r) = atan2(imagpart(c), realpart(c)); else diff --git a/src/maths/cmaths/cmath4.c b/src/maths/cmaths/cmath4.c index f57939e02..b5731d135 100644 --- a/src/maths/cmaths/cmath4.c +++ b/src/maths/cmaths/cmath4.c @@ -441,7 +441,7 @@ cx_group_delay(void *data, short int type, int length, int *newlength, short int if (type == VF_COMPLEX) for (i = 0; i < length; i++) { - v_phase[i] = radtodeg(cph(&cc[i])); + v_phase[i] = radtodeg(cph(cc[i])); } else {