making error handling consistent in support.c by calling
authorZhishun Alex Liu <zliu@ucbvax.Berkeley.EDU>
Sun, 12 Jul 1987 04:39:55 +0000 (20:39 -0800)
committerZhishun Alex Liu <zliu@ucbvax.Berkeley.EDU>
Sun, 12 Jul 1987 04:39:55 +0000 (20:39 -0800)
infnan() in sqrt() and drem(); ifdef out those finite and (x!=x)'s.

SCCS-vsn: lib/libm/common/atan2.c 1.5
SCCS-vsn: lib/libm/ieee/cabs.c 1.5
SCCS-vsn: lib/libm/common/trig.c 1.5
SCCS-vsn: lib/libm/ieee/support.c 1.9

usr/src/lib/libm/common/atan2.c
usr/src/lib/libm/common/trig.c
usr/src/lib/libm/ieee/cabs.c
usr/src/lib/libm/ieee/support.c

index 5fc041b..228bf2d 100644 (file)
@@ -13,7 +13,7 @@
 
 #ifndef lint
 static char sccsid[] =
 
 #ifndef lint
 static char sccsid[] =
-"@(#)atan2.c   1.3 (Berkeley) 8/21/85; 1.4 (ucb.elefunt) %G%";
+"@(#)atan2.c   1.3 (Berkeley) 8/21/85; 1.5 (ucb.elefunt) %G%";
 #endif not lint
 
 /* ATAN2(Y,X)
 #endif not lint
 
 /* ATAN2(Y,X)
@@ -183,8 +183,10 @@ double  y,x;
        double copysign(),logb(),scalb(),t,z,signy,signx,hi,lo;
        int finite(), k,m;
 
        double copysign(),logb(),scalb(),t,z,signy,signx,hi,lo;
        int finite(), k,m;
 
+#if (!defined(VAX)&&!defined(TAHOE))
     /* if x or y is NAN */
        if(x!=x) return(x); if(y!=y) return(y);
     /* if x or y is NAN */
        if(x!=x) return(x); if(y!=y) return(y);
+#endif
 
     /* copy down the sign of y and x */
        signy = copysign(one,y) ;  
 
     /* copy down the sign of y and x */
        signy = copysign(one,y) ;  
@@ -199,6 +201,7 @@ double  y,x;
     /* when x = 0 */
        if(x==zero) return(copysign(PIo2,signy));
            
     /* when x = 0 */
        if(x==zero) return(copysign(PIo2,signy));
            
+#if (!defined(VAX)&&!defined(TAHOE))
     /* when x is INF */
        if(!finite(x))
            if(!finite(y)) 
     /* when x is INF */
        if(!finite(x))
            if(!finite(y)) 
@@ -208,7 +211,7 @@ double  y,x;
 
     /* when y is INF */
        if(!finite(y)) return(copysign(PIo2,signy));
 
     /* when y is INF */
        if(!finite(y)) return(copysign(PIo2,signy));
-
+#endif
 
     /* compute y/x */
        x=copysign(x,one); 
 
     /* compute y/x */
        x=copysign(x,one); 
index af20b27..c6cc569 100644 (file)
@@ -13,7 +13,7 @@
 
 #ifndef lint
 static char sccsid[] =
 
 #ifndef lint
 static char sccsid[] =
-"@(#)trig.c    1.2 (Berkeley) 8/22/85; 1.4 (ucb.elefunt) %G%";
+"@(#)trig.c    1.2 (Berkeley) 8/22/85; 1.5 (ucb.elefunt) %G%";
 #endif not lint
 
 /* SIN(X), COS(X), TAN(X)
 #endif not lint
 
 /* SIN(X), COS(X), TAN(X)
@@ -156,10 +156,12 @@ double tan(x)
 double x;
 {
         double copysign(),drem(),cos__C(),sin__S(),a,z,ss,cc,c;
 double x;
 {
         double copysign(),drem(),cos__C(),sin__S(),a,z,ss,cc,c;
-        int finite(),k;
-
+       int k;
+#if (!defined(VAX)&&!defined(TAHOE))
+        extern int finite();
         /* tan(NaN) and tan(INF) must be NaN */
             if(!finite(x))  return(x-x);
         /* tan(NaN) and tan(INF) must be NaN */
             if(!finite(x))  return(x-x);
+#endif
         x=drem(x,PI);        /* reduce x into [-PI/2, PI/2] */
         a=copysign(x,one);   /* ... = abs(x) */
        if ( a >= PIo4 ) {k=1; x = copysign( PIo2 - a , x ); }
         x=drem(x,PI);        /* reduce x into [-PI/2, PI/2] */
         a=copysign(x,one);   /* ... = abs(x) */
        if ( a >= PIo4 ) {k=1; x = copysign( PIo2 - a , x ); }
@@ -179,10 +181,11 @@ double sin(x)
 double x;
 {
         double copysign(),drem(),sin__S(),cos__C(),a,c,z;
 double x;
 {
         double copysign(),drem(),sin__S(),cos__C(),a,c,z;
-        int finite();
-
+#if (!defined(VAX)&&!defined(TAHOE))
+        extern int finite();
         /* sin(NaN) and sin(INF) must be NaN */
             if(!finite(x))  return(x-x);
         /* sin(NaN) and sin(INF) must be NaN */
             if(!finite(x))  return(x-x);
+#endif
        x=drem(x,PI2);         /*    reduce x into [-PI, PI] */
         a=copysign(x,one);
        if( a >= PIo4 ) {
        x=drem(x,PI2);         /*    reduce x into [-PI, PI] */
         a=copysign(x,one);
        if( a >= PIo4 ) {
@@ -208,10 +211,11 @@ double cos(x)
 double x;
 {
         double copysign(),drem(),sin__S(),cos__C(),a,c,z,s=1.0;
 double x;
 {
         double copysign(),drem(),sin__S(),cos__C(),a,c,z,s=1.0;
-        int finite();
-
+#if (!defined(VAX)&&!defined(TAHOE))
+        extern int finite();
         /* cos(NaN) and cos(INF) must be NaN */
             if(!finite(x))  return(x-x);
         /* cos(NaN) and cos(INF) must be NaN */
             if(!finite(x))  return(x-x);
+#endif
        x=drem(x,PI2);         /*    reduce x into [-PI, PI] */
         a=copysign(x,one);
        if ( a >= PIo4 ) {
        x=drem(x,PI2);         /*    reduce x into [-PI, PI] */
         a=copysign(x,one);
        if ( a >= PIo4 ) {
index ba040ef..ceb6b3e 100644 (file)
@@ -13,7 +13,7 @@
 
 #ifndef lint
 static char sccsid[] =
 
 #ifndef lint
 static char sccsid[] =
-"@(#)cabs.c    1.2 (Berkeley) 8/21/85; 1.4 (ucb.elefunt) %G%";
+"@(#)cabs.c    1.2 (Berkeley) 8/21/85; 1.5 (ucb.elefunt) %G%";
 #endif not lint
 
 /* CABS(Z)
 #endif not lint
 
 /* CABS(Z)
@@ -122,9 +122,11 @@ double x, y;
        double copysign(),scalb(),logb(),sqrt(),t,r;
        int finite(), exp;
 
        double copysign(),scalb(),logb(),sqrt(),t,r;
        int finite(), exp;
 
+#if (!defined(VAX)&&!defined(TAHOE))
        if(finite(x))
            if(finite(y))
            {   
        if(finite(x))
            if(finite(y))
            {   
+#endif
                x=copysign(x,one);
                y=copysign(y,one);
                if(y > x) 
                x=copysign(x,one);
                y=copysign(y,one);
                if(y > x) 
@@ -149,6 +151,7 @@ double x, y;
                r=y/r;
                return(x+r);
 
                r=y/r;
                return(x+r);
 
+#if (!defined(VAX)&&!defined(TAHOE))
            }
 
            else if(y==y)          /* y is +-INF */
            }
 
            else if(y==y)          /* y is +-INF */
@@ -162,6 +165,7 @@ double x, y;
                 return(x);                /* x is NaN, y is finite */
        else if(y!=y) return(y);  /* x and y is NaN */
        else return(copysign(y,one));   /* y is INF */
                 return(x);                /* x is NaN, y is finite */
        else if(y!=y) return(y);  /* x and y is NaN */
        else return(copysign(y,one));   /* y is INF */
+#endif
 }
 
 /* A faster but less accurate version of cabs(x,y) */
 }
 
 /* A faster but less accurate version of cabs(x,y) */
index 6335548..92a47d9 100644 (file)
 
 #ifndef lint
 static char sccsid[] =
 
 #ifndef lint
 static char sccsid[] =
-"@(#)support.c 1.1 (Berkeley) 5/23/85; 1.8 (ucb.elefunt) %G%";
+"@(#)support.c 1.1 (Berkeley) 5/23/85; 1.9 (ucb.elefunt) %G%";
 #endif not lint
 
 /* 
 #endif not lint
 
 /* 
- * Some IEEE standard p754 recommended functions and remainder and sqrt for 
+ * Some IEEE standard 754 recommended functions and remainder and sqrt for 
  * supporting the C elementary functions.
  ******************************************************************************
  * WARNING:
  * supporting the C elementary functions.
  ******************************************************************************
  * WARNING:
@@ -28,7 +28,7 @@ static char sccsid[] =
  * its own assembler.
  ******************************************************************************
  *
  * its own assembler.
  ******************************************************************************
  *
- * IEEE p754 required operations:
+ * IEEE 754 required operations:
  *     drem(x,p) 
  *              returns  x REM y  =  x - [x/y]*y , where [x/y] is the integer
  *              nearest x/y; in half way case, choose the even one.
  *     drem(x,p) 
  *              returns  x REM y  =  x - [x/y]*y , where [x/y] is the integer
  *              nearest x/y; in half way case, choose the even one.
@@ -36,7 +36,7 @@ static char sccsid[] =
  *              returns the square root of x correctly rounded according to 
  *             the rounding mod.
  *
  *              returns the square root of x correctly rounded according to 
  *             the rounding mod.
  *
- * IEEE p754 recommended functions:
+ * IEEE 754 recommended functions:
  * (a) copysign(x,y) 
  *              returns x with the sign of y. 
  * (b) scalb(x,N) 
  * (a) copysign(x,y) 
  *              returns x with the sign of y. 
  * (b) scalb(x,N) 
@@ -56,6 +56,7 @@ static char sccsid[] =
 
 
 #if (defined(VAX)||defined(TAHOE))      /* VAX D format */
 
 
 #if (defined(VAX)||defined(TAHOE))      /* VAX D format */
+#include <errno.h>
     static unsigned short msign=0x7fff , mexp =0x7f80 ;
     static short  prep1=57, gap=7, bias=129           ;   
     static double novf=1.7E38, nunf=3.0E-39, zero=0.0 ;
     static unsigned short msign=0x7fff , mexp =0x7f80 ;
     static short  prep1=57, gap=7, bias=129           ;   
     static double novf=1.7E38, nunf=3.0E-39, zero=0.0 ;
@@ -81,7 +82,12 @@ double x; int N;
 
 #if (defined(VAX)||defined(TAHOE))
         if( (k= *px & mexp ) != ~msign ) {
 
 #if (defined(VAX)||defined(TAHOE))
         if( (k= *px & mexp ) != ~msign ) {
-            if( N<-260) return(nunf*nunf); else if(N>260) return(novf+novf);
+            if (N < -260)
+               return(nunf*nunf);
+           else if (N > 260) {
+               extern double infnan(),copysign();
+               return(copysign(infnan(ERANGE),x));
+           }
 #else   /* IEEE */
         if( (k= *px & mexp ) != mexp ) {
             if( N<-2100) return(nunf*nunf); else if(N>2100) return(novf+novf);
 #else   /* IEEE */
         if( (k= *px & mexp ) != mexp ) {
             if( N<-2100) return(nunf*nunf); else if(N>2100) return(novf+novf);
@@ -153,7 +159,7 @@ finite(x)
 double x;    
 {
 #if (defined(VAX)||defined(TAHOE))
 double x;    
 {
 #if (defined(VAX)||defined(TAHOE))
-        return(1.0);
+        return(1);
 #else  /* IEEE */
 #ifdef NATIONAL
         return( (*((short *) &x+3 ) & mexp ) != mexp );
 #else  /* IEEE */
 #ifdef NATIONAL
         return( (*((short *) &x+3 ) & mexp ) != mexp );
@@ -186,14 +192,22 @@ double x,p;
         *pp &= msign ;
 
 #if (defined(VAX)||defined(TAHOE))
         *pp &= msign ;
 
 #if (defined(VAX)||defined(TAHOE))
-        if( ( *px & mexp ) == ~msign )
+        if( ( *px & mexp ) == ~msign ) /* is x a reserved operand? */
 #else /* IEEE */
         if( ( *px & mexp ) == mexp )
 #endif
                return  (x-p)-(x-p);    /* create nan if x is inf */
 #else /* IEEE */
         if( ( *px & mexp ) == mexp )
 #endif
                return  (x-p)-(x-p);    /* create nan if x is inf */
-       if(p==zero) return zero/zero;
+       if (p == zero) {
 #if (defined(VAX)||defined(TAHOE))
 #if (defined(VAX)||defined(TAHOE))
-        if( ( *pp & mexp ) == ~msign )
+               extern double infnan();
+               return(infnan(EDOM));
+#else
+               return zero/zero;
+#endif
+       }
+
+#if (defined(VAX)||defined(TAHOE))
+        if( ( *pp & mexp ) == ~msign ) /* is p a reserved operand? */
 #else /* IEEE */
         if( ( *pp & mexp ) == mexp )
 #endif
 #else /* IEEE */
         if( ( *pp & mexp ) == mexp )
 #endif
@@ -252,7 +266,14 @@ double x;
         if(x!=x||x==zero) return(x);
 
     /* sqrt(negative) is invalid */
         if(x!=x||x==zero) return(x);
 
     /* sqrt(negative) is invalid */
-        if(x<zero) return(zero/zero);
+        if(x<zero) {
+#if (defined(VAX)||defined(TAHOE))
+               extern double infnan();
+               return (infnan(EDOM));  /* NaN */
+#else  /* IEEE double */
+               return(zero/zero);
+#endif
+       }
 
     /* sqrt(INF) is INF */
         if(!finite(x)) return(x);               
 
     /* sqrt(INF) is INF */
         if(!finite(x)) return(x);