int drand(); /* void exit(); */ /* int printf(); */
/* Provide inverses for square root and cube root: */ longdouble complex
csquarel(longdouble complex x)
{ return( x * x );
}
longdouble complex
ccubel(longdouble complex x)
{ return( x * x * x );
}
/* lookup table for each function */ struct fundef
{ char *nam1; /* the function */ longdouble complex (*name )(); char *nam2; /* its inverse */ longdouble complex (*inv )(); int nargs; /* number of function arguments */ int tstyp; /* type code of the function */ long ctrl; /* relative error flag */ longdouble arg1w; /* width of domain for 1st arg */ longdouble arg1l; /* lower bound domain 1st arg */ long arg1f; /* flags, e.g. integer arg */ longdouble arg2w; /* same info for args 2, 3, 4 */ longdouble arg2l; long arg2f; /* doublearg3w; doublearg3l; longarg3f; doublearg4w; doublearg4l; longarg4f;
*/
};
int main()
{ longdouble complex (*fun )(); longdouble complex (*ifun )(); struct fundef *d; int i, k, itst; int m, ntr;
#if SETPREC
ldprec(); /* 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 = cgammal(x);
y = cexpl(clgaml(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.0L, 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.0L/a );
} else
{
z = (*fun)( a, x );
y = (*ifun)( a, z );
}
} break;
switch( d->tstyp )
{ case WRONK1:
e = (y2*y3 - yy1*y4) - 2.0L/(PIL*x); /* Jn, Yn */ break;
case WRONK2:
e = (y2*y3 + yy1*y4) - 1.0L/x; /* In, Kn */ break;
case ELLIP:
e = (yy1-y3)*y4 + y3*y2 - PIO2L; break;
case SQRT: /* Square root could have either sign. */
de = cabsl ((y - x) / x); if (de > 1.5L)
{ /* Try -y. */
dr = cabsl ((-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( cabsl(x) > 1.0L )
e /= x;
}
de = cabsl(e);
statistics:
ave +=de; /* absolute value of error */ if( de < 0 )
de = -de;
/* peak detect the error */ if( de > max )
{
max = de;
if( de > 4.0e-16L )
{ #if0
printf( "x (%.6Le,%.6Le) z (%.6Le,%.6Le) y (%.6Le,%.6Le) max %.4Le\n",
creall(xsave), cimagl(xsave), creall(z), cimagl(z),
creall(y), cimagl(y), max); #else
printf( "x (%.6e,%.6e) z (%.6e,%.6e) y (%.6e,%.6e) max %.4e\n",
(double) creall(xsave), (double) cimagl(xsave),
(double) creall(z), (double) cimagl(z),
(double) creall(y), (double) cimagl(y),
(double) max); #endif if( d->tstyp == POWER )
{
printf( "a (%.6Le,%.6Le)\n", creall(a), cimagl(a) );
} if( d->tstyp >= WRONK1 )
{
printf( "yy1 (%.4Le,%.4Le) y2 (%.4Le,%.4Le) y3 (%.4Le,%.4Le) y4 (%.4Le,%.4Le) k %d x (%.4Le,%.4Le)\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.