Path: utzoo!utgpu!news-server.csri.toronto.edu!eecg.toronto.edu!drb Newsgroups: comp.sys.sgi From: drb@eecg.toronto.edu (David R. Blythe) Subject: Re: trig functions (which "fail" on the Sun as well) Message-ID: <1990Nov16.221411.22602@jarvis.csri.toronto.edu> Organization: EECG, University of Toronto References: <9011131959.AA11389@> <43209@mips.mips.COM> Date: 17 Nov 90 03:14:12 GMT Lines: 32 In article <43209@mips.mips.COM> mark@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 >#include >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@clsc.utoronto.ca