use `SWAP' macro

This commit is contained in:
rlar 2016-03-22 13:04:13 +01:00
parent b36385e333
commit bd0bc3038b
21 changed files with 46 additions and 137 deletions

View File

@ -378,9 +378,7 @@ com_compose(wordlist *wl)
}
if (startgiven && stopgiven && (start > stop)) {
tt = start;
start = stop;
stop = tt;
SWAP(double, start, stop);
reverse = TRUE;
}

View File

@ -1232,9 +1232,7 @@ measure_parse_stdParams(
/* dc: make m_from always less than m_to */
if (cieq("dc", meas->m_analysis))
if (meas->m_to < meas->m_from) {
double tmp_val = meas->m_to;
meas->m_to = meas->m_from;
meas->m_from = tmp_val;
SWAP(double, meas->m_to, meas->m_from);
}
return 1;

View File

@ -597,9 +597,7 @@ op_range(struct pnode *arg1, struct pnode *arg2)
}
if (up < low) {
td = up;
up = low;
low = td;
SWAP(double, up, low);
rev = TRUE;
}
@ -727,9 +725,7 @@ op_ind(struct pnode *arg1, struct pnode *arg2)
up = (int)floor(imagpart(ind->v_compdata[0]) + 0.5);
}
if (up < down) {
i = up;
up = down;
down = i;
SWAP(int, up, down);
rev = TRUE;
}
if (up < 0) {

View File

@ -106,7 +106,6 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
double dtheta;
double theta1, theta2, tt, alpha, beta, gamma;
bool flip = FALSE;
int i;
/* Get the angles between the origin and the endpoints. */
if ((*x1-cx) || (*y1-cy))
@ -131,15 +130,9 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
/* Make sure that p1 is the first point */
if (dtheta < 0) {
tt = theta1;
theta1 = theta2;
theta2 = tt;
i = *x1;
*x1 = *x2;
*x2 = i;
i = *y1;
*y1 = *y2;
*y2 = i;
SWAP(double, theta1, theta2);
SWAP(int, *x1, *x2);
SWAP(int, *y1, *y2);
flip = TRUE;
dtheta = -dtheta;
}
@ -209,12 +202,8 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
}
if (flip) {
i = *x1;
*x1 = *x2;
*x2 = i;
i = *y1;
*y1 = *y2;
*y2 = i;
SWAP(int, *x1, *x2);
SWAP(int, *y1, *y2);
}
return (FALSE);

View File

@ -1491,10 +1491,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
if (in) {
if (start > d) {
double tmp;
tmp = start;
start = d;
d = tmp;
SWAP(double, start, d);
}
DevDrawArc((int)cx, (int)cy, (int)rad, start, d-start);
sclip = start;

View File

@ -219,7 +219,6 @@ plotit(wordlist *wl, char *hcopy, char *devname)
struct dvec *d = NULL, *vecs = NULL, *lv, *lastvs = NULL;
char *xn;
int i, y_type, xt;
double tt;
wordlist *wwl, *tail;
char *cline = NULL, buf[BSIZE_SP], *pname;
char *nxlabel = NULL, *nylabel = NULL, *ntitle = NULL;
@ -831,14 +830,10 @@ plotit(wordlist *wl, char *hcopy, char *devname)
ylims[1] = 1.0;
}
if (xlims[0] > xlims[1]) {
tt = xlims[1];
xlims[1] = xlims[0];
xlims[0] = tt;
SWAP(double, xlims[1], xlims[0]);
}
if (ylims[0] > ylims[1]) {
tt = ylims[1];
ylims[1] = ylims[0];
ylims[0] = tt;
SWAP(double, ylims[1], ylims[0]);
}
if (AlmostEqualUlps(xlims[0], xlims[1], 10)) {
xlims[0] *= (xlims[0] > 0) ? 0.9 : 1.1;

View File

@ -753,7 +753,7 @@ zoomin(GRAPH *graph)
/* note: need to add circular boxes XXX */
int x0, y0, x1, y1;
double fx0, fx1, fy0, fy1, ftemp;
double fx0, fx1, fy0, fy1;
char buf[BSIZE_SP];
char buf2[128];
char *t;
@ -811,14 +811,10 @@ zoomin(GRAPH *graph)
X_ScreentoData(graph, x1, y1, &fx1, &fy1);
if (fx0 > fx1) {
ftemp = fx0;
fx0 = fx1;
fx1 = ftemp;
SWAP(double, fx0, fx1);
}
if (fy0 > fy1) {
ftemp = fy0;
fy0 = fy1;
fy1 = ftemp;
SWAP(double, fy0, fy1);
}
strncpy(buf2, graph->plotname, sizeof(buf2));

View File

@ -600,7 +600,7 @@ Sf wk1 [WL], wk2 [WL]; /* Pools of variates. */
static void
regen(void)
{
Sw i, j, k, m;
Sw i, j, m;
Sf p, q, r, s, t;
Sw topv[6], ord[4], *top;
Sf *ppt[4], *ptn;
@ -626,10 +626,8 @@ reran1:
for (i = 2; i >= 0; i--)
for (j = 0; j <= i; j++)
if (top[j] < top[j+1]) {
k = top[j]; top[j] = top[j+1];
top[j+1] = k;
k = ord[j]; ord[j] = ord[j+1];
ord[j+1] = k;
SWAP(Sw, top[j], top[j+1]);
SWAP(Sw, ord[j], ord[j+1]);
}
/* Ensure all different */

View File

@ -197,10 +197,8 @@ reran1:
for (i = 2; i >= 0; i--)
for (j = 0; j <= i; j++)
if (top[j] < top[j+1]) {
k = top[j]; top[j] = top[j+1];
top[j+1] = k;
k = ord[j]; ord[j] = ord[j+1];
ord[j+1] = k;
SWAP(int, top[j], top[j+1]);
SWAP(int, ord[j], ord[j+1]);
}
/* Ensure all different */

View File

@ -25,7 +25,6 @@ NIacIter(CKTcircuit *ckt)
{
int error;
int ignore;
double *temp;
double startTime;
retry:
@ -77,13 +76,9 @@ retry:
*ckt->CKTirhsSpare = 0;
*ckt->CKTirhsOld = 0;
temp = ckt->CKTirhsOld;
ckt->CKTirhsOld = ckt->CKTirhs;
ckt->CKTirhs = temp;
SWAP(double *, ckt->CKTirhsOld, ckt->CKTirhs);
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
return(OK);
}

View File

@ -23,31 +23,22 @@ NIdIter(CKTcircuit *ckt)
{
int error;
int ignore;
double *temp;
ckt->CKTnoncon = 0;
goto skip;
retry:
ckt->CKTnoncon=0;
temp = ckt->CKTrhs;
ckt->CKTrhs = ckt->CKTrhsSpare;
ckt->CKTrhsSpare = temp;
SWAP(double *, ckt->CKTrhs, ckt->CKTrhsSpare);
temp = ckt->CKTirhs;
ckt->CKTirhs = ckt->CKTirhsSpare;
ckt->CKTirhsSpare = temp;
SWAP(double *, ckt->CKTirhs, ckt->CKTirhsSpare);
error = CKTacLoad(ckt);
if(error) return(error);
temp = ckt->CKTrhs;
ckt->CKTrhs = ckt->CKTrhsSpare;
ckt->CKTrhsSpare = temp;
SWAP(double *, ckt->CKTrhs, ckt->CKTrhsSpare);
temp = ckt->CKTirhs;
ckt->CKTirhs = ckt->CKTirhsSpare;
ckt->CKTirhsSpare = temp;
SWAP(double *, ckt->CKTirhs, ckt->CKTirhsSpare);
skip:
if(ckt->CKTniState & NIACSHOULDREORDER) {
@ -85,12 +76,8 @@ skip:
*ckt->CKTirhsSpare = 0;
*ckt->CKTirhsOld = 0;
temp = ckt->CKTirhsOld;
ckt->CKTirhsOld = ckt->CKTirhs;
ckt->CKTirhs = temp;
SWAP(double *, ckt->CKTirhsOld, ckt->CKTirhs);
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
return(OK);
}

View File

@ -29,7 +29,6 @@ NIiter(CKTcircuit *ckt, int maxIter)
int ipass;
int error;
int i,j; /* temporaries for finding error location */
double *temp;
double startTime;
static char *msg = "Too many iterations without convergence";
@ -43,9 +42,7 @@ NIiter(CKTcircuit *ckt, int maxIter)
if( (ckt->CKTmode & MODETRANOP) && (ckt->CKTmode & MODEUIC)) {
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
error = CKTload(ckt);
if(error) {
return(error);
@ -269,9 +266,7 @@ NIiter(CKTcircuit *ckt, int maxIter)
}
/* build up the lvnim1 array from the lvn array */
temp = ckt->CKTrhsOld;
ckt->CKTrhsOld = ckt->CKTrhs;
ckt->CKTrhs = temp;
SWAP(double *, ckt->CKTrhsOld, ckt->CKTrhs);
/*printf("after loading, after solving\n");*/
/*CKTdump(ckt);*/
}

View File

@ -53,13 +53,9 @@ ft_polyfit(double *xdata, double *ydata, double *result,
if (lindex != i) {
/* swap rows i and lindex */
for (k = 0; k < n; k++) {
d = mat1[i * n + k];
mat1[i * n + k] = mat1[lindex * n + k];
mat1[lindex * n + k] = d;
SWAP(double, mat1[i * n + k], mat1[lindex * n + k]);
}
d = mat2[i];
mat2[i] = mat2[lindex];
mat2[lindex] = d;
SWAP(double, mat2[i], mat2[lindex]);
}
/* Make sure we have a non-zero pivot. */
if (mat1[i * n + i] == 0.0) {

View File

@ -151,9 +151,7 @@ wl_reverse(wordlist *wl)
return (wl);
for (;;) {
wordlist *t = wl->wl_next;
wl->wl_next = wl->wl_prev;
wl->wl_prev = t;
SWAP(wordlist *, wl->wl_next, wl->wl_prev);
if (!wl->wl_prev)
return (wl);
wl = wl->wl_prev;
@ -231,14 +229,11 @@ wl_sort(wordlist *wl)
wordlist *
wl_range(wordlist *wl, int low, int up)
{
int i;
wordlist *tt;
bool rev = FALSE;
if (low > up) {
i = up;
up = low;
low = i;
SWAP(int, up, low);
rev = TRUE;
}
up -= low;

View File

@ -22,7 +22,7 @@ CKTpzSetup(CKTcircuit *ckt, int type)
SMPmatrix *matrix;
int error;
int i, temp, solution_col, balance_col;
int i, solution_col, balance_col;
int input_pos, input_neg, output_pos, output_neg;
NIdestroy(ckt);
@ -71,9 +71,7 @@ CKTpzSetup(CKTcircuit *ckt, int type)
balance_col = output_neg;
} else {
solution_col = output_neg;
temp = input_pos;
input_pos = input_neg;
input_neg = temp;
SWAP(int, input_pos, input_neg);
}
if (input_pos)

View File

@ -12,11 +12,7 @@ Author: 1988 Jaijeet S Roychowdhury
static void
DISswap(double **a, double **b)
{
double *c;
c = *a;
*a = *b;
*b = c;
SWAP(double *, *a, *b);
}
static void

View File

@ -769,9 +769,7 @@ Gaussian_Elimination2(int dims, int type)
}
if (imax != i)
for (k = i; k <= dim; k++) {
f = A[i][k];
A[i][k] = A[imax][k];
A[imax][k] = f;
SWAP(double, A[i][k], A[imax][k]);
}
f = 1.0 / A[i][i];
@ -1699,9 +1697,7 @@ Gaussian_Elimination(int dims)
}
if (imax != i)
for (k = i; k <= dim; k++) {
f = At[i][k];
At[i][k] = At[imax][k];
At[imax][k] = f;
SWAP(double, At[i][k], At[imax][k]);
}
f = 1.0 / At[i][i];

View File

@ -31,7 +31,6 @@ JFETdSetup(GENmodel *inModel, CKTcircuit *ckt)
double lcapgs1;
double cd;
double cdrain;
double temp;
double cg;
double cgd;
double csat;
@ -95,10 +94,8 @@ JFETdSetup(GENmodel *inModel, CKTcircuit *ckt)
if (vds < 0.0) {
vds = -vds;
temp = vgs;
vgs = vgd;
vgd = temp; /* so now these have become the
local variables */
SWAP(double, vgs, vgd);
/* so now these have become the local variables */
here->JFETmode = -1;
} else {
here->JFETmode = 1;

View File

@ -81,7 +81,6 @@ MESAload(GENmodel *inModel, CKTcircuit *ckt)
#ifndef PREDICTOR
double xfact;
#endif
double temp;
double vted;
double vtes;
double vtd;
@ -321,9 +320,7 @@ MESAload(GENmodel *inModel, CKTcircuit *ckt)
if(inverse) {
cdrain = -cdrain;
vds = -vds;
temp = capgs;
capgs = capgd;
capgd = temp;
SWAP(double, capgs, capgd);
}
/*
* compute equivalent drain current source

View File

@ -984,9 +984,7 @@ SOI3load(GENmodel *inModel, CKTcircuit *ckt)
/* Now we use a nasty trick - if device is A over T, must "swap" drain and source
potentials. we do a literal switch and change it back for the outside world. */
if (here->SOI3mode == -1) {
tmp = vsb;
vsb = vdb;
vdb = tmp;
SWAP(double, vsb, vdb);
}
/* Intrinsic Electrical Bit - has a bit of thermal due to TTC */
@ -1667,9 +1665,7 @@ SOI3load(GENmodel *inModel, CKTcircuit *ckt)
/* now end nasty trick - if vsb and vdb have been switched, reverse them back */
if (here->SOI3mode == -1)
{
tmp = vsb;
vsb = vdb;
vdb = tmp;
SWAP(double, vsb, vdb);
}
/*

View File

@ -550,9 +550,7 @@ Gaussian_Elimination1(int dims)
}
if (imax != i)
for (k = i; k <= dim; k++) {
f = A[i][k];
A[i][k] = A[imax][k];
A[imax][k] = f;
SWAP(double, A[i][k], A[imax][k]);
}
f = 1.0 / A[i][i];
@ -913,9 +911,7 @@ Gaussian_Elimination2(int dims)
}
if (imax != i)
for (k = i; k <= dim; k++) {
f = AA[i][k];
AA[i][k] = AA[imax][k];
AA[imax][k] = f;
SWAP(double, AA[i][k], AA[imax][k]);
}
f = 1.0 / AA[i][i];