trig functions (which "fail" on the Sun as well)

David R. Blythe drb at eecg.toronto.edu
Sat Nov 17 14:14:12 AEST 1990


In article <43209 at mips.mips.COM> mark at mips.COM (Mark G. Johnson) writes:
>
>Conclusion: don't be irate about noise-in-the-LSB when the argument
>is 0*PI; there's inaccuracy elsewhere too.
>
>----------------------------------------------------------------------------
>#include <stdio.h>
>#include <math.h>
>main()
>{
>  double w, x, y, z ;
>  w = 0.5 * acos(0.0) ;      /* generate PI / 4                      */
>  x = sin(w);                /* the sine of (PI/4) is sqrt(1/2)      */
>  y = 0.5 - (x * x) ;        /* how far is it off?                   */
>  z = sqrt(0.5) - x ;        /* compute the delta by another method  */
>  printf("approx PI/4:  w = %le\n", w);
>  printf("    sine of that:  x = %le\n", x);
>  printf("        delta between x and sqrt(1/2):  y = %le\n", y);
>  printf("        delta between x and sqrt(1/2):  z = %le (method 2)\n", z);
>}
>----------------------------------------------------------------------------
>
>$ a.out
>approx PI/4:  w = 7.853982e-01
>    sine of that:  x = 7.071068e-01
>        delta between x and sqrt(1/2):  y = 1.110223e-16
>        delta between x and sqrt(1/2):  z = 1.110223e-16 (method 2)

Trying to judge the accuracy of sin() using equally inaccurate (or worse)
acos() and sqrt() routines isn't very effective or convincing.
	-drb
	drb at clsc.utoronto.ca



More information about the Comp.sys.sgi mailing list