int drand(); /* void exit(); */ /* int printf(); */
/* Provide inverses for square root and cube root: */ double square(x) double x;
{ return( x * x );
}
double cube(x) double x;
{ return( x * x * x );
}
/* lookup table for each function */ struct fundef
{ char *nam1; /* the function */ double (*name )(); char *nam2; /* its inverse */ double (*inv )(); int nargs; /* number of function arguments */ int tstyp; /* type code of the function */ long ctrl; /* relative error flag */ double arg1w; /* width of domain for 1st arg */ double arg1l; /* lower bound domain 1st arg */ long arg1f; /* flags, e.g. integer arg */ double arg2w; /* same info for args 2, 3, 4 */ double arg2l; long arg2f; /* doublearg3w; doublearg3l; longarg3f; doublearg4w; doublearg4l; longarg4f;
*/
};
staticdouble yy1 = 0.0; staticdouble y2 = 0.0; staticdouble y3 = 0.0; staticdouble y4 = 0.0; staticdouble a = 0.0; staticdouble x = 0.0; staticdouble y = 0.0; staticdouble z = 0.0; staticdouble e = 0.0; staticdouble max = 0.0; staticdouble rmsa = 0.0; staticdouble rms = 0.0; staticdouble ave = 0.0;
int main()
{ double (*fun )(); double (*ifun )(); struct fundef *d; int i, k, itst; int m, ntr;
#if SETPREC
dprec(); /* set coprocessor precision */ #endif
ntr = NTRIALS;
printf( "Consistency test of math functions.\n" );
printf( "Max and rms relative errors for %d random arguments.\n",
ntr );
for( itst=STRTST; itst<NTESTS; itst++ )
{
d = &defs[itst];
k = 0;
m = 0;
max = 0.0;
rmsa = 0.0;
ave = 0.0;
fun = d->name;
ifun = d->inv;
/* Absolute error criterion starts with gamma function *(putallsuchatendoftable)
*/ #if0 if( d->tstyp == GAMMA )
printf( "Absolute error criterion (but relative if >1):\n" ); #endif
/* Smaller number of trials for Wronksians *(putthematendoflist)
*/ #if0 if( d->tstyp == WRONK1 )
{
ntr = WTRIALS;
printf( "Absolute error and only %d trials:\n", ntr );
} #endif if( d->tstyp == STDTR )
{
ntr = NTRIALS/10;
printf( "Relative error and only %d trials:\n", ntr );
}
printf( headrs[d->tstyp], d->nam2, d->nam1 );
for( i=0; i<ntr; i++ )
{
m++;
/* make random number(s) in desired range(s) */ switch( d->nargs )
{
default: goto illegn;
case2:
drand( &a );
a = d->arg2w * ( a - 1.0 ) + d->arg2l; if( d->arg2f & EXPSCAL )
{
a = exp(a);
drand( &y2 );
a -= 1.0e-13 * a * y2;
} if( d->arg2f & INT )
{
k = a + 0.25;
a = k;
}
case1:
drand( &x );
x = d->arg1w * ( x - 1.0 ) + d->arg1l; if( d->arg1f & EXPSCAL )
{
x = exp(x);
drand( &a );
x += 1.0e-13 * x * a;
}
}
/* compute function under test */ switch( d->nargs )
{ case1: switch( d->tstyp )
{ case ELLIP:
yy1 = ( *(fun) )(x);
y2 = ( *(fun) )(1.0-x);
y3 = ( *(ifun) )(x);
y4 = ( *(ifun) )(1.0-x); break;
case GAMMA: #if GLIBC2
y = lgamma(x);
x = log( tgamma(x) ); #else
y = lgam(x);
x = log( gamma(x) ); #endif break;
default:
z = ( *(fun) )(x);
y = ( *(ifun) )(z);
} break;
case2: if( d->arg2f & INT )
{ switch( d->tstyp )
{ case WRONK1:
yy1 = (*fun)( k, x ); /* jn */
y2 = (*fun)( k+1, x );
y3 = (*ifun)( k, x ); /* yn */
y4 = (*ifun)( k+1, x ); break;
case WRONK2:
yy1 = (*fun)( a, x ); /* iv */
y2 = (*fun)( a+1.0, x );
y3 = (*ifun)( k, x ); /* kn */
y4 = (*ifun)( k+1, x ); break;
default:
z = (*fun)( k, x );
y = (*ifun)( k, z );
}
} else
{ if( d->tstyp == POWER )
{
z = (*fun)( x, a );
y = (*ifun)( z, 1.0/a );
} else
{
z = (*fun)( a, x );
y = (*ifun)( a, z );
}
} break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.