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

Mark G. Johnson mark at mips.COM
Thu Nov 15 04:24:47 AEST 1990


In article <9011131959.AA11389@> lmo at lsr-vax.UUCP ("Lance M. Optican - LMO") writes:
    >>   printf("%g\n", 1.0-cos(0.0));
    >>$ cc a.c -lm
    >>$ a.out
    >>1.11022e-16
    >>$ cc a.c -lm43
    >>$ a.out
    >>0
    >
    >It is reasonable to expect the maht library to perform well!  I
    >tried Allan Wilks program on both Sun/3 and Sun/4 machines, and
    >they both gave "0" as the difference between 1.0 and cos(0.0).
    >Who at SGI is responsible for the math library?  What standards
    >of compatibility are enforced with other machine architectures?
    >


How about the accuracy in the vicinity of PI/4 (45 degrees)??

Here's a little program that uses trig functions to take the sine of
PI/4.  The correct answer is, of course, sqrt(1/2).  But none of
the machines (DEC-3100, Sun SPARCstation, SGI Iris) get this.

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);
}
----------------------------------------------------------------------------

SunOS Release 4.0.3c (GENERIC) #1: Thu May 25 17:17:12 PDT 1989

$ 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)
-- 
 -- Mark Johnson	
 	MIPS Computer Systems, 930 E. Arques M/S 2-02, Sunnyvale, CA 94086
	(408) 524-8308    mark at mips.com  {or ...!decwrl!mips!mark}



More information about the Comp.sys.sgi mailing list