cleanup using `hypot()'

This commit is contained in:
rlar 2014-12-05 20:08:02 +01:00
parent eafa0a9bed
commit c5e0bcde04
14 changed files with 29 additions and 29 deletions

View File

@ -186,7 +186,7 @@ TWOavalanche(TWOelem *pElem, TWOnode *pNode)
*/
/* now calculate the avalanche generation rate */
current = sqrt( jnx * jnx + jny * jny );
current = hypot(jnx, jny);
if ( current != 0.0 ) {
eField = (enx * jnx + eny * jny) / current;
if ( (eField > 0) && ( info->bii[ELEC] / eField <= 80.0) ) {
@ -194,7 +194,7 @@ TWOavalanche(TWOelem *pElem, TWOnode *pNode)
* exp( - info->bii[ELEC] / eField );
}
}
current = sqrt( jpx * jpx + jpy * jpy );
current = hypot(jpx, jpy);
if ( current != 0.0 ) {
eField = (epx * jpx + epy * jpy) / current;
if ( eField > eiip2 ) {

View File

@ -65,7 +65,7 @@ TWOdopingValue(DOPprofile *pProfile, DOPtable *pTable, double x,
argL = argY / pProfile->LAT_RATIO;
}
if ( pProfile->rotate ) {
argP = sqrt(argP*argP + argL*argL);
argP = hypot(argP, argL);
argL = 0.0;
}

View File

@ -125,13 +125,13 @@ get_value(
int idx /*in: index of vector value to be read out */
)
{
double ar, bi, tt;
double ar, bi;
ar = values->v_compdata[idx].cx_real;
bi = values->v_compdata[idx].cx_imag;
if ((meas->m_vectype == 'm') || (meas->m_vectype == 'M')) {
return sqrt(ar*ar + bi*bi); /* magnitude */
return hypot(ar, bi); /* magnitude */
} else if ((meas->m_vectype == 'r') || (meas->m_vectype == 'R')) {
return ar; /* real value */
} else if ((meas->m_vectype == 'i') || (meas->m_vectype == 'I')) {
@ -139,8 +139,7 @@ get_value(
} else if ((meas->m_vectype == 'p') || (meas->m_vectype == 'P')) {
return radtodeg(atan2(bi, ar)); /* phase (in degrees) */
} else if ((meas->m_vectype == 'd') || (meas->m_vectype == 'D')) {
tt = sqrt(ar*ar + bi*bi); /* dB of magnitude */
return 20.0 * log10(tt);
return 20.0 * log10(hypot(ar, bi)); /* dB of magnitude */
} else {
return ar; /* default: real value */
}

View File

@ -337,7 +337,7 @@ CKTfour(int ndata, /* number of entries in the Time and
tmp = Mag[i] * 2.0 / ndata;
Phase[i] *= 2.0 / ndata;
Freq[i] = i * FundFreq;
Mag[i] = sqrt(tmp*tmp + Phase[i]*Phase[i]);
Mag[i] = hypot(tmp, Phase[i]);
Phase[i] = atan2(Phase[i], tmp) * 180.0/M_PI;
nMag[i] = Mag[i] / Mag[1];
nPhase[i] = Phase[i] - Phase[1];

View File

@ -152,9 +152,9 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
}
/* Figure out the distances between the points */
a = sqrt((double) ((*x1 - cx) * (*x1 - cx) + (*y1 - cy) * (*y1 - cy)));
b = sqrt((double) ((*x2 - cx) * (*x2 - cx) + (*y2 - cy) * (*y2 - cy)));
c = sqrt((double) ((*x1 - *x2) * (*x1 - *x2) + (*y1 - *y2) * (*y1 - *y2)));
a = hypot(*x1 - cx, *y1 - cy);
b = hypot(*x2 - cx, *y2 - cy);
c = hypot(*x1 - *x2, *y1 - *y2);
/* We have three cases now -- either the midpoint of the line is
* closest to the origon, or point 1 or point 2 is. Actually the
@ -164,7 +164,7 @@ clip_to_circle(int *x1, int *y1, int *x2, int *y2, int cx, int cy, int rad)
*/
tx = (*x1 + *x2) / 2;
ty = (*y1 + *y2) / 2;
dt = sqrt((double) ((tx - cx) * (tx - cx) + (ty - cy) * (ty - cy)));
dt = hypot(tx - cx, ty - cy);
if ((dt < a) && (dt < b)) {
/* This is wierd -- round-off errors I guess. */
tt = (a * a + c * c - b * b) / (2 * a * c);

View File

@ -778,7 +778,7 @@ polargrid(GRAPH *graph)
/* Figure out the minimum and maximum radii we're dealing with. */
mx = (graph->data.xmin + graph->data.xmax) / 2;
my = (graph->data.ymin + graph->data.ymax) / 2;
d = sqrt(mx * mx + my * my);
d = hypot(mx, my);
maxrad = d + (graph->data.xmax - graph->data.xmin) / 2;
minrad = d - (graph->data.xmax - graph->data.xmin) / 2;
@ -862,7 +862,7 @@ drawpolargrid(GRAPH *graph)
/* The distance from the center of the plotting area to the center of
* the logical area.
*/
dist = (int)sqrt((double) (relcx * relcx + relcy * relcy));
dist = (int)hypot(relcx, relcy);
SetLinestyle(0);
DevDrawArc(graph->grid.xaxis.circular.center,
@ -987,7 +987,7 @@ adddeglabel(GRAPH *graph, int deg, int x, int y, int cx, int cy, int lx, int ly)
int d, w, h;
double angle;
if (sqrt((double) (x - cx) * (x - cx) + (y - cy) * (y - cy)) < MINDIST)
if (hypot(x - cx, y - cy) < MINDIST)
return;
(void) sprintf(buf, "%d", deg);
w = graph->fontwidth * (int) (strlen(buf) + 1);
@ -1124,7 +1124,7 @@ drawsmithgrid(GRAPH *graph)
/* Figure out the minimum and maximum radii we're dealing with. */
mx = (graph->datawindow.xmin + graph->datawindow.xmax) / 2;
my = (graph->datawindow.ymin + graph->datawindow.ymax) / 2;
d = sqrt(mx * mx + my * my);
d = hypot(mx, my);
maxrad = d + (graph->datawindow.xmax - graph->datawindow.xmin) / 2;
mag = (int)floor(mylog10(maxrad));
@ -1419,7 +1419,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
cliprad = (double) icliprad;
x = cx - clipx;
y = cy - clipy;
dist = sqrt((double) (x * x + y * y));
dist = hypot(x, y);
if (!rad || !cliprad)
return (-1);
@ -1469,7 +1469,7 @@ cliparc(double cx, double cy, double rad, double start, double end, int iclipx,
tx = cos(start) * rad + x;
ty = sin(start) * rad + y;
d = sqrt((double) tx * tx + ty * ty);
d = hypot(tx, ty);
in = (d > cliprad) ? FALSE : TRUE;
/* Now begin with start. If the point is in, draw to either end, a1,

View File

@ -876,7 +876,7 @@ plotit(wordlist *wl, char *hcopy, char *devname)
* is outside the drawing area so I'll stay as the maximum size of the hypotenuse of
* the complex value
*/
rad = sqrt(mx * mx + my * my);
rad = hypot(mx, my);
xlims[0] = - rad;
xlims[1] = rad;
ylims[0] = - rad;

View File

@ -726,7 +726,7 @@ slopelocation(GRAPH *graph, int x0, int y0)
{
angle = RAD_TO_DEG * atan2(fy0, fx0);
fprintf(stdout, "r0 = %g, a0 = %g\n",
sqrt(fx0*fx0 + fy0*fy0),
hypot(fx0, fy0),
(angle>0)?angle:360.0+angle);
}

View File

@ -434,7 +434,7 @@ LRESULT CALLBACK PlotWindowProc( HWND hwnd,
{
angle = RAD_TO_DEG * atan2( fy0, fx0 );
fprintf(stdout, "r0 = %g, a0 = %g\n",
sqrt( fx0*fx0 + fy0*fy0 ),
hypot(fx0, fy0),
(angle>0)?angle:360.0+angle);
}
} else {

View File

@ -71,7 +71,7 @@ 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 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 rcheck(cond, name) if (!(cond)) { \
@ -157,7 +157,7 @@ typedef struct {
(A).imag = 0.0; \
} \
} else { \
_mag = sqrt((A).real * (A).real + (A).imag * (A).imag); \
_mag = hypot((A).real, (A).imag); \
_a = (_mag - (A).real) / 2.0; \
if (_a <= 0.0) { \
(A).real = sqrt(_mag); \
@ -225,7 +225,7 @@ typedef struct {
* The magnitude of the complex number
*/
#define C_ABS(A) (sqrt((A).real * (A.real) + (A.imag * A.imag)))
#define C_ABS(A) (hypot((A).real, (A).imag))
/*
* Standard arithmetic between complex numbers
@ -334,7 +334,7 @@ typedef struct {
#define CMPLX_INF_NORM(a) (MAX (ABS((a).real),ABS((a).imag)))
/* Macro function that returns the magnitude (L-2 norm) of a complex number. */
#define CMPLX_2_NORM(a) (sqrt((a).real*(a).real + (a).imag*(a).imag))
#define CMPLX_2_NORM(a) (hypot((a).real, (a).imag))
/* Macro function that performs complex addition. */
#define CMPLX_ADD(to,from_a,from_b) \

View File

@ -170,6 +170,7 @@ extern double x_asinh(double);
extern double x_acosh(double);
#define atanh x_atanh
extern double x_atanh(double);
#define hypot _hypot
#endif
#define strdup _strdup
#define unlink _unlink

View File

@ -145,7 +145,7 @@ typedef struct
#define CMPLX_INF_NORM(a) (MAX (ABS((a).Real),ABS((a).Imag)))
/* Macro function that returns the magnitude (L-2 norm) of a complex number. */
#define CMPLX_2_NORM(a) (sqrt((a).Real*(a).Real + (a).Imag*(a).Imag))
#define CMPLX_2_NORM(a) (hypot((a).Real, (a).Imag))
/* Macro function that performs complex addition. */
#define CMPLX_ADD(to,from_a,from_b) \

View File

@ -1605,7 +1605,7 @@ DFT
tmp = Mag [i] * 2.0 / (double)ndata;
Phase [i] *= 2.0 / (double)ndata;
Freq [i] = i * FundFreq;
Mag [i] = sqrt (tmp * tmp + Phase [i] * Phase [i]);
Mag [i] = hypot (tmp, Phase [i]);
Phase [i] = atan2 (Phase [i], tmp) * 180.0 / M_PI;
nMag [i] = Mag [i] / Mag [1];
nPhase [i] = Phase [i] - Phase [1];

View File

@ -135,10 +135,10 @@ double mag_x, phase_x, mag_y, phase_y;
Mif_Complex_t out;
mag_x = sqrt( (x.real * x.real) + (x.imag * x.imag) );
mag_x = hypot(x.real, x.imag);
phase_x = atan2(x.imag, x.real);
mag_y = sqrt( (y.real * y.real) + (y.imag * y.imag) );
mag_y = hypot(y.real, y.imag);
phase_y = atan2(y.imag, y.real);
mag_x = mag_x/mag_y;