/* C--------------------------------------------------------------------- CProgramtotestCSIN/CCOS C CAccuracytestsarebasedontheidentities C Csin(z)=sin(z-w)*cos(w)+cos(z-w)*sin(w) Cand Ccos(z)=cos(z-w)*cos(w)-sin(z-w)*sin(w) C CDatarequired: C CNone C CSubprogramsrequiredfromthispackage: C CMACHAR-Anenvironmentalinquiryprogramproviding Cinformationonthefloatingpointarithmetic Csystem.NotethatthecalltoMACHARcan Cbedeletedprovidedthefollowingfive Cparametersareassignedthevaluesindicated: C CIBETA-theradixofthefloatingpointsystem; CIT-thenumberofbase-IBETAdigitsinthe Csignificandofafloating-pointnumber; CXMAX-thelargestfinitefloating-pointno. C CREN(K)-afunctionsubprogramreturningrandomreal Cnumbersuniformlydistributedover(0,1) C CRESET,TABLAT,REPORT-programstoreportresults. C C CGenericFortransubprogramsrequired: C CABS,AIMAG(orDIMAG),CMPLX(orDCMPLX),COS, C CLOG,MAX,REAL(orDBLE),SIN C C CLatestrevision-October31,1990 C CAuthor-W.J.Cody CArgonneNationalLaboratory C C---------------------------------------------------------------------- CDeclarenamedcommon C----------------------------------------------------------------------
*/
/* C---------------------------------------------------------------------- CStatementfunctionsforconversionbetweenintegerorcomplex Candfloat C----------------------------------------------------------------------
*/ /* C----------------------------------------------------------------------
*/ int
main ()
{ /* CALLMACHAR(IBETA,IT,IRND,NGRD,MACHEP,NEGEP,IEXP,MINEXP, 1MAXEXP,EPS,EPSNEG,XMIN,XMAX)
*/
IBETA = 2;
IT = IT_VAL;
XMIN = XMIN_VAL;
XMAX = XMAX_VAL;
BETA = CONV (IBETA);
ALBETA = LOG (BETA);
AIT = CONV (IT);
AX = ONE / SIXTEN;
BX = ONE;
AY = ZERO;
BY = ONE;
N = 2000;
XN = CONV (N);
I1 = 0;
IFLAG = FALSE;
RFLAG = TRUE;
PFLAG = FALSE; /* C----------------------------------------------------------------- CRandomargumentaccuracytests C-----------------------------------------------------------------
*/ /* DO 300 J = 1, 3 */ for (J = 1; J <= 3; J++)
{
RESET ();
DELX = (BX - AX) / XN;
DELY = (BY - AY);
XL = AX; /* DO 200 I = 1, N */ for (I = 1; I <= N; I++)
{
X = DELX * REN (I1) + XL;
Y = DELY * REN (I1) + AY;
CX = CONVC (X, Y); /* C---------------------------------------------------------------- CCarefullypurifyargumentsandevaluateidentities C----------------------------------------------------------------
*/
CY = CX - CDEL;
CS = FSIN (CY);
CC = FCOS (CY); if (J != 3)
{
CZ = FSIN (CX);
CZZ = CS + (CS * COSDEL + CC * SINDEL);
} else
{
CZ = FCOS (CX);
CZZ = CC + (CC * COSDEL - CS * SINDEL);
} /* C----------------------------------------------------------------- CAccumulateresults C-----------------------------------------------------------------
*/
TABLAT ();
XL = XL + DELX; /* 200 CONTINUE*/
} /* C--------------------------------------------------------------------- CProcessandoutputstatistics C---------------------------------------------------------------------
*/ if (J != 3)
printf (" Test of SIN(X) vs SIN(W+D), W = X-D, D = (1/16,1/16)\n"); else
printf (" Test of COS(X) vs COS(W+D), W = X-D, D = (1/16,1/16)\n");
REPORT (IOUT); if (J == 1)
{
AX = SIXTEN;
BX = AX + ONE;
}
AY = AX;
BY = BX;
IFLAG = TRUE; /* 300 CONTINUE*/
} /* C----------------------------------------------------------------- CSpecialtests C-----------------------------------------------------------------
*/
printf (" Special Tests\n"); /* C = ONE / BETA ** (IT/2) */ #ifdef TDOUBLE
C = ONE / POW (BETA, (double) (IT / 2)); #endif #ifdef TSINGLE
C = ONE / POW (BETA, (float) (IT / 2)); #endif
X = ELEVEN;
Y = X + ONE + HALF;
X = X + X;
CX = CONVC (X + C, Y);
CY = CONVC (X - C, Y);
CZ = (FSIN (CX) - FSIN (CY)) / (C + C);
printf (" If (%9.1f,%7.1f) is not almost (-134163,1188),\n",
creal (CZ), cimag (CZ));
printf (" SIN has the wrong period.\n");
printf (" The identity SIN(-Z) = -SIN(Z) will be tested.\n");
printf (" X F(Z) + F(-Z)\n"); /* DO 320 I = 1, 5 */ for (I = 1; I <= 5; I++)
{
X = REN (I1) * TEN;
Y = REN (I1) * TEN;
CX = CONVC (X, Y);
CZ = FSIN (CX) + FSIN (-CX);
printf ("(%15.7E,%15.7E) (%15.7E,%15.7E)\n",
creal (CX), cimag (CX), creal (CZ), cimag (CZ)); /* 320 CONTINUE */
}
printf (" Test the significance in the real or imaginary\n");
printf (" components near\n");
printf (" the zeros of the real sin or cos.\n");
X = ELEVEN;
Y = X + ONE + HALF;
CX = CONVC (X, Y);
CZ = FSIN (CX);
CS = (CZ - SIN11A) - SIN11B;
C = CONVI (CS) / CONVI (CZ); if (C != ZERO)
W = LOG (ABS (C)) / ALBETA + AIT; else
W = ZERO;
W = MAX (W, ZERO);
printf (" SIN(%15.7E,%15.7E) = (%15.7E,%15.7E)\n",
creal (CX), cimag (CX), creal (CZ), cimag (CZ));
printf (" The estimated loss of base %4d digits in the\n", IBETA);
printf (" imaginary component is %7.2f\n", W);
if (W < ONE)
printf (" This is acceptable\n"); else
printf (" This is too large\n");
X = X + X;
CX = CONVC (X, Y);
CZ = FSIN (CX);
CS = (CZ - SIN22A) - SIN22B;
C = CONVR (CS) / CONVR (CZ); if (C != ZERO)
W = LOG (ABS (C)) / ALBETA + AIT; else
W = ZERO;
W = MAX (W, ZERO);
printf (" SIN(%15.7E,%15.7E) = (%15.7E,%15.7E)\n",
creal (CX), cimag (CX), creal (CZ), cimag (CZ));
printf (" The estimated loss of base %4d digits in the\n", IBETA);
printf (" real component is %7.2f\n", W); if (W < ONE)
printf (" This is acceptable\n"); else
printf (" This is too large\n"); /* C----------------------------------------------------------------- CTestoferrorreturns C-----------------------------------------------------------------
*/
printf (" Test of error returns\n");
ALXMAX = LOG (XMAX) - HALF;
CX = CONVC (ONE, ALXMAX);
printf (" SIN will be called with the argument (%15.4E,%15.4E)\n",
creal (CX), cimag (CX));
printf (" This should not trigger an error message\n");
CY = FSIN (CX);
printf (" SIN returned the value (%15.4E,%15.4E)\n", creal (CY), cimag (CY)); /*BETAP = BETA ** IT */ #ifdef TDOUBLE
BETAP = POW (BETA, (double) IT); #endif #ifdef TSINGLE
BETAP = POW (BETA, (float) IT); #endif
CX = CONVC (BETAP, ONE);
printf (" SIN will be called with the argument (%15.4E,%15.4E)\n",
creal (CX), cimag (CX));
printf (" This should trigger an error message\n");
CY = FSIN (CX);
printf (" SIN returned the value (%15.4E,%15.4E)\n", creal (CY), cimag (CY));
CX = CONVC (ONE, BETAP);
printf (" SIN will be called with the argument (%15.4E,%15.4E)\n",
creal (CX), cimag (CX));
printf (" This should trigger an error message\n");
CY = FSIN (CX);
printf (" SIN returned the value (%15.4E,%15.4E)\n", creal (CY), cimag (CY));
printf (" This concludes the tests\n"); exit (0);
}
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.