main()
{ char s[40]; double a, n, t, x, y, z; int lflg;
x = TPI/4.0;
t = 1.0;
loop:
t = 2.0 * t;
/* Stop testing at a point beyond which the integer part of *x/2picannotberepresentedexactlybyadoubleprecisionnumber. *Thelibrarytrigonometryfunctionswillprobablygiveuplongbefore *thispointisreached.
*/ if( t > 1.0e16 ) exit(0);
/* Adjust the following to choose a nontrivial x *wheretestfunction(x)hasaslopeofabout1ormore.
*/
x = TPI * t + 0.5;
z = x;
lflg = 0;
inlup:
/* floor() returns the largest integer less than its argument. *Ifyoudonothavethis,orAINT(),thenyoumayconvertx/TPI *toalongintegerandthenbacktodouble;butinthatcase *xwillbelimitedtothelargestvaluethatwillfitintoa *longinteger.
*/
n = floor( z/TPI );
/* Carefully subtract 2 pi n from x. *Thisisdonebysubtractingn*2**kinsuchawaythatthere *isnoarithmeticcancellationerroratanystep.Thekarethe *bitsinthenumber2pi. * *Ifyoudonothaveldexp(),thenyoumaymultiplyor *dividenbyanappropriatepowerof2aftereachstep. *Forexample: *a=z-4*n; *a-=2*n; *n/=4; *a-=n;n/4 *n/=8; *a-=n;n/32 *etc. *Thiswillonlyworkifdivisionbyapowerof2isexact.
*/
a = z - ldexp(n, 2); /* 4n */
a -= ldexp( n, 1); /* 2n */
a -= ldexp( n, -2 ); /* n/4 */
a -= ldexp( n, -5 ); /* n/32 */
a -= ldexp( n, -9 ); /* n/512 */
a += ldexp( n, -15 ); /* add n/32768 */
a -= ldexp( n, -17 ); /* n/131072 */
a -= ldexp( n, -18 );
a -= ldexp( n, -20 );
a -= ldexp( n, -22 );
a -= ldexp( n, -24 );
a -= ldexp( n, -28 );
a -= ldexp( n, -32 );
a -= ldexp( n, -37 );
a -= ldexp( n, -39 );
a -= ldexp( n, -40 );
a -= ldexp( n, -42 );
a -= ldexp( n, -46 );
a -= ldexp( n, -47 );
/* Subtract what is left of 2 pi n after all the above reductions.
*/
a -= 2.44929359829470635445e-16 * n;
/* If the test is extended too far, it is possible *tohavechosenthewrongvalueofn.Thefollowing *willfixthat,butatsomereductioninaccuracy.
*/ if( (a > TPI) || (a < -1e-11) )
{
z = a;
lflg += 1;
printf( "Warning! Reduction failed on first try.\n" ); goto inlup;
} if( a < 0.0 )
{
printf( "Warning! Reduced value < 0\n" );
a += TPI;
}
/* Compute the test function at x and at a = x mod 2 pi.
*/
y = sin(x);
z = sin(a);
printf( "sin(%.15e) error = %.3e\n", x, y-z ); goto loop;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-27)
¤
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.