EgtNumKernel 1.9h1 :

- Complex sostituiti con std::complex<double>
- controllo versione chiave 19.
This commit is contained in:
Dario Sassi
2018-08-08 10:59:56 +00:00
parent b3c1e76176
commit df74709c40
8 changed files with 98 additions and 464 deletions
+35 -38
View File
@@ -107,7 +107,7 @@ Rpoly::Calculate( const double* op, int degree, double* zeror, double* zeroi)
max = 0.0 ;
min = infin ;
for ( i = 0 ; i <= n ; i++) {
x = fabs( p[i]) ;
x = abs( p[i]) ;
if ( x > max)
max = x ;
if ( x != 0.0 && x < min)
@@ -140,7 +140,7 @@ Rpoly::Calculate( const double* op, int degree, double* zeror, double* zeroi)
// Compute lower bound on moduli of roots.
for ( i = 0 ; i <= n ; i++) {
pt[i] = fabs( p[i]) ;
pt[i] = abs( p[i]) ;
}
pt[n] = - pt[n] ;
// Compute upper estimate of bound.
@@ -165,7 +165,7 @@ Rpoly::Calculate( const double* op, int degree, double* zeror, double* zeroi)
// Do Newton iteration until x converges to two decimal places.
dx = x ;
while ( fabs( dx / x) > 0.005) {
while ( abs( dx / x) > 0.005) {
ff = pt[0] ;
df = ff ;
for ( i = 1 ; i < n ; i++) {
@@ -198,7 +198,7 @@ Rpoly::Calculate( const double* op, int degree, double* zeror, double* zeroi)
k[j] = t * k[j-1] + p[j] ;
}
k[0] = p[0] ;
bZerOk = ( fabs( k[n-1]) <= fabs( bb) * eta * 10.0) ;
bZerOk = ( abs( k[n-1]) <= abs( bb) * eta * 10.0) ;
}
else {
// Use unscaled form of recurrence.
@@ -317,9 +317,9 @@ Rpoly::fxshfr( int l2, int* nz)
// Compute relative measures of convergence of s and v sequences.
if ( vv != 0.0)
tv = fabs( ( vv - ovv) / vv) ;
tv = abs( ( vv - ovv) / vv) ;
if ( ss != 0.0)
ts = fabs( ( ss - oss) / ss) ;
ts = abs( ( ss - oss) / ss) ;
/* If decreasing, multiply two most recent convergence measures. */
tvv = 1.0 ;
if ( tv < otv)
@@ -436,23 +436,23 @@ Rpoly::quadit( double *uu, double *vv, int *nz)
// Return if roots of the quadratic are real and not
// close to multiple or nearly equal and of opposite sign.
if ( fabs( fabs( szr) - fabs( lzr)) > 0.01 * fabs( lzr))
if ( abs( abs( szr) - abs( lzr)) > 0.01 * abs( lzr))
return ;
// Evaluate polynomial by quadratic synthetic division.
quadsd( n, &u, &v, p, qp, &a, &b) ;
mp = fabs( a - szr * b) + fabs( szi * b) ;
mp = abs( a - szr * b) + abs( szi * b) ;
// Compute a rigorous bound on the rounding error in evaluating p.
zm = sqrt( fabs( v)) ;
ee = 2.0 * fabs( qp[0]) ;
zm = sqrt( abs( v)) ;
ee = 2.0 * abs( qp[0]) ;
t = -szr * b ;
for ( i = 1 ; i < n ; i ++) {
ee = ee * zm + fabs( qp[i]) ;
ee = ee * zm + abs( qp[i]) ;
}
ee = ee * zm + fabs( a + t) ;
ee = ee * zm + abs( a + t) ;
ee *= (5.0 * mre + 4.0 * are) ;
ee = ee - ( 5.0 * mre + 2.0 * are) * ( fabs( a + t) + fabs( b) * zm) ;
ee = ee + 2.0 * are * fabs( t) ;
ee = ee - ( 5.0 * mre + 2.0 * are) * ( abs( a + t) + abs( b) * zm) ;
ee = ee + 2.0 * are * abs( t) ;
// Iteration has converged sufficiently if the polynomial value is less than 20 times this bound.
if ( mp <= 20.0 * ee) {
*nz = 2 ;
@@ -493,7 +493,7 @@ Rpoly::quadit( double *uu, double *vv, int *nz)
// If vi is zero the iteration is not converging.
if ( vi == 0.0)
return ;
relstp = fabs( ( vi - v) / vi) ;
relstp = abs( ( vi - v) / vi) ;
u = ui ;
v = vi ;
}
@@ -529,12 +529,12 @@ Rpoly::realit( double sss, int* nz, bool* pbIflag)
pv = pv * s + p[i] ;
qp[i] = pv ;
}
mp = fabs( pv) ;
mp = abs( pv) ;
// Compute a rigorous bound on the error in evaluating p.
ms = fabs( s) ;
ee = ( mre / ( are + mre)) * fabs( qp[0]) ;
ms = abs( s) ;
ee = ( mre / ( are + mre)) * abs( qp[0]) ;
for ( i = 1 ; i <= n ; i ++) {
ee = ee * ms + fabs( qp[i]) ;
ee = ee * ms + abs( qp[i]) ;
}
// Iteration has converged sufficiently if the polynomial value is less than 20 times this bound.
if ( mp <= 20.0 * (( are + mre) * ee - mre * mp)) {
@@ -549,7 +549,7 @@ Rpoly::realit( double sss, int* nz, bool* pbIflag)
return ;
// A cluster of zeros near the real axis has been encountered.
if ( j >= 2 &&
! ( fabs( t) > 0.001 * fabs( s-t) || mp < omp)) {
! ( abs( t) > 0.001 * abs( s-t) || mp < omp)) {
// Return with iflag set to initiate a quadratic iteration.
*pbIflag = true ;
return ;
@@ -565,7 +565,7 @@ Rpoly::realit( double sss, int* nz, bool* pbIflag)
kv = kv*s + k[i] ;
qk[i] = kv;
}
if ( fabs( kv) <= fabs( k[n-1]) * 10.0 * eta) {
if ( abs( kv) <= abs( k[n-1]) * 10.0 * eta) {
// Use unscaled form.
k[0] = 0.0 ;
for ( i = 1 ; i < n ; i ++) {
@@ -585,7 +585,7 @@ Rpoly::realit( double sss, int* nz, bool* pbIflag)
kv = kv * s + k[i] ;
}
t = 0.0 ;
if ( fabs( kv) > ( fabs( k[n-1] * 10.0 * eta)))
if ( abs( kv) > ( abs( k[n-1] * 10.0 * eta)))
t = - pv / kv ;
s += t ;
}
@@ -605,14 +605,14 @@ Rpoly::calcsc( int *type)
quadsd( n-1, &u, &v, k, qk, &c, &d) ;
// Type=3 indicates the quadratic is almost a factor of k.
if ( fabs( c) <= fabs( k[n-1] * 100.0 * eta) &&
fabs( d) <= fabs( k[n-2] * 100.0 * eta)) {
if ( abs( c) <= abs( k[n-1] * 100.0 * eta) &&
abs( d) <= abs( k[n-2] * 100.0 * eta)) {
*type = 3 ;
return ;
}
// Type=1 indicates that all formulas are divided by c.
if ( fabs( d) < fabs( c)) {
if ( abs( d) < abs( c)) {
*type = 1 ;
e = a / c ;
f = d / c ;
@@ -657,7 +657,7 @@ Rpoly::nextk( int* type)
temp = a ;
if ( *type == 1)
temp = b ;
if ( fabs( a1) <= fabs( temp) * eta * 10.0) {
if ( abs( a1) <= abs( temp) * eta * 10.0) {
// If a1 is nearly zero then use a special form of the recurrence.
k[0] = 0.0;
k[1] = -a7*qp[0] ;
@@ -774,22 +774,22 @@ Rpoly::quad( double a, double b1, double c,
}
/* Compute discriminant avoiding overflow. */
b = b1 / 2.0 ;
if ( fabs( b) < fabs( c)) {
if ( abs( b) < abs( c)) {
if ( c < 0.0)
e = - a ;
else
e = a ;
e = b * ( b / fabs( c)) - e ;
d = sqrt( fabs( e)) * sqrt( fabs( c)) ;
e = b * ( b / abs( c)) - e ;
d = sqrt( abs( e)) * sqrt( abs( c)) ;
}
else {
e = 1.0 - ( a / b) *( c / b) ;
d = sqrt( fabs( e)) * fabs( b) ;
d = sqrt( abs( e)) * abs( b) ;
}
if ( e < 0.0) { /* complex conjugate zeros */
*sr = - b / a ;
*lr = *sr ;
*si = fabs( d / a) ;
*si = abs( d / a) ;
*li = - ( *si) ;
}
else {
@@ -1266,7 +1266,7 @@ Cpoly::cauchy( const int nn, double pt[], double q[], double* fn_val)
dx = x ;
// Do Newton iteration until x converges to two decimal places
while ( fabs( dx / x ) > 0.005) {
while ( abs( dx / x ) > 0.005) {
q[0] = pt[0] ;
for ( i = 1 ; i <= nn ; i++)
q[i] = q[i - 1] * x + pt[i] ;
@@ -1346,7 +1346,7 @@ Cpoly::cdivid( const double ar, const double ai, const double br, const double b
return ;
}
if ( fabs( br) < fabs( bi)) {
if ( abs( br) < abs( bi)) {
r = br / bi ;
dinv = 1.0 / ( bi + r * br) ;
*cr = ( ar * r + ai) * dinv ;
@@ -1366,11 +1366,8 @@ Cpoly::cdivid( const double ar, const double ai, const double br, const double b
double
Cpoly::cmod( const double r, const double i)
{
double ar, ai ;
ar = fabs( r) ;
ai = fabs( i) ;
double ar = abs( r) ;
double ai = abs( i) ;
if ( ar < ai)
return ( ai * sqrt( 1.0 + ( ar * ar) / ( ai * ai))) ;