int drand(); /* void exit(); */ /* int printf(); */
/* Provide inverses for square root and cube root: */ float complex
csquaref(float complex x)
{ return( x * x );
}
float complex
ccube(float complex x)
{ return( x * x * x );
}
/* lookup table for each function */ struct fundef
{ char *nam1; /* the function */ float complex (*name )(); char *nam2; /* its inverse */ float complex (*inv )(); int nargs; /* number of function arguments */ int tstyp; /* type code of the function */ long ctrl; /* relative error flag */ float arg1w; /* width of domain for 1st arg */ float arg1l; /* lower bound domain 1st arg */ long arg1f; /* flags, e.g. integer arg */ float arg2w; /* same info for args 2, 3, 4 */ float arg2l; long arg2f; /* doublearg3w; doublearg3l; longarg3f; doublearg4w; doublearg4l; longarg4f;
*/
};
int main()
{ float complex (*fun )(); float complex (*ifun )(); struct fundef *d; int i, k, itst; int m, ntr;
#if SETPREC
sprec(); /* set coprocessor precision */ #endif
ntr = NTRIALS;
printf( "Consistency test of complex math functions.\n" );
printf( "Max and rms relative errors for %d random arguments.\n",
ntr );
case GAMMA:
z = cgammaf(x);
y = cexpf(clgamf(x));
x = z; /* This breaks the printout of large errors. */ 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.0f, 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.0f/a );
} else
{
z = (*fun)( a, x );
y = (*ifun)( a, z );
}
} break;
switch( d->tstyp )
{ case WRONK1:
e = (y2*y3 - yy1*y4) - 2.0f/(PIF*x); /* Jn, Yn */ break;
case WRONK2:
e = (y2*y3 + yy1*y4) - 1.0f/x; /* In, Kn */ break;
case ELLIP:
e = (yy1-y3)*y4 + y3*y2 - PIO2F; break;
case SQRT: /* Square root could have either sign. */
de = cabsf ((y - x) / x); if (de > 1.5f)
{ /* Try -y. */
dr = cabsf ((-y - x) / x); if (dr < de)
{
y = -y;
de = dr;
}
} goto statistics;
default:
e = y - x; break;
}
if( d->ctrl & RELERR )
e /= x; else
{ if( cabsf(x) > 1.0f )
e /= x;
}
de = cabsf(e);
statistics:
ave +=de; /* absolute value of error */ if( de < 0 )
de = -de;
/* peak detect the error */ if( de > max )
{
max = de;
if( de > 1.0e-4f )
{
printf("x (%.9E,%.9E) z (%.9E,%.9E) y (%.9E,%.9E) max %.4E\n",
creal(xsave), cimag(xsave), creal(z), cimag(z),
creal(y), cimag(y), max); if( d->tstyp == POWER )
{
printf( "a (%.6E,%.6E)\n", creal(a), cimag(a) );
} if( d->tstyp == WRONK1 )
{
printf( "yy1 (%.4E,%.4E) y2 (%.4E,%.4E) y3 (%.4E,%.4E) y4 (%.4E,%.4E) k %d x (%.4E,%.4E)\n",
creal(yy1), cimag(yy1), creal(y2), cimag(y2),
creal(y3), cimag(y3), creal(y4), cimag(y4), k, creal(xsave), cimag(xsave) );
}
}
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.