updated files; from Zhishun Alex Liu
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 25 Jan 1988 04:34:21 +0000 (20:34 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 25 Jan 1988 04:34:21 +0000 (20:34 -0800)
SCCS-vsn: usr.bin/f77/libF77/pow_ci.c 5.3
SCCS-vsn: usr.bin/f77/libF77/pow_ri.c 5.4
SCCS-vsn: usr.bin/f77/libF77/pow_zi.c 5.2

usr/src/usr.bin/f77/libF77/pow_ci.c
usr/src/usr.bin/f77/libF77/pow_ri.c
usr/src/usr.bin/f77/libF77/pow_zi.c

index acb9bfe..6a240b0 100644 (file)
@@ -3,70 +3,64 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)pow_ci.c    5.2     %G%
+ *     @(#)pow_ci.c    5.3     %G%
  */
 
 #include "complex"
 
  */
 
 #include "complex"
 
-#ifndef tahoe
-pow_ci(p, a, b)        /* p = a**b  */
-complex *p, *a;
-long int *b;
-{
-dcomplex p1, a1;
+#ifdef tahoe
 
 
-a1.dreal = a->real;
-a1.dimag = a->imag;
+#define        C_MULEQ(A,B)    \
+       t = (A).real * (B).real - (A).imag * (B).imag,\
+       (A).imag = (A).real * (B).imag + (A).imag * (B).real,\
+       (A).real = t    /* A *= B */
 
 
-pow_zi(&p1, &a1, b);
+void
+pow_ci(p, a, b)        /* p = a**b  */
+       complex *p, *a;
+       long *b;
+{
+       register long n = *b;
+       register float t;
+       complex x;
 
 
-p->real = p1.dreal;
-p->imag = p1.dimag;
+       x = *a;
+       p->real = (float)1, p->imag = (float)0;
+       if (!n)
+               return;
+       if (n < 0) {
+               c_div(&x, p, a);
+               n = -n;
+       }
+       while (!(n&1)) {
+               C_MULEQ(x, x);
+               n >>= 1;
+       }
+       for (*p = x; --n > 0; C_MULEQ(*p, x))
+               while (!(n&1)) {
+                       C_MULEQ(x, x);
+                       n >>= 1;
+               }
 }
 
 }
 
-#else tahoe
+#else /* !tahoe */
 
 
+extern void pow_zi();
+
+void
 pow_ci(p, a, b)        /* p = a**b  */
 pow_ci(p, a, b)        /* p = a**b  */
-complex *p, *a;
-long int *b;
+       complex *p, *a;
+       long *b;
 {
 {
-register long int n;
-register float t;
-complex x;
+       dcomplex p1, a1;
 
 
-n = *b;
-p->real = 1;
-p->imag = 0;
+       a1.dreal = a->real;
+       a1.dimag = a->imag;
 
 
-if(n == 0)
-       return;
-if(n < 0)
-       {
-       n = -n;
-       c_div(&x,p,a);
-       }
-else
-       {
-       x.real = a->real;
-       x.imag = a->imag;
-       }
+       pow_zi(&p1, &a1, b);
 
 
-for( ; ; )
-       {
-       if(n & 01)
-               {
-               t = p->real * x.real - p->imag * x.imag;
-               p->imag = p->real * x.imag + p->imag * x.real;
-               p->real = t;
-               }
-       if(n >>= 1)
-               {
-               t = x.real * x.real - x.imag * x.imag;
-               x.imag = 2 * x.real * x.imag;
-               x.real = t;
-               }
-       else
-               break;
-       }
+       p->real = p1.dreal;
+       p->imag = p1.dimag;
 }
 }
-#endif tahoe
+
+#endif /* tahoe */
index 281bb9a..793e42c 100644 (file)
@@ -3,43 +3,41 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)pow_ri.c    5.3     %G%
+ *     @(#)pow_ri.c    5.4     %G%
  */
 
  */
 
-float pow_ri(ap, bp)
-float *ap;
-long int *bp;
-{
-double pow, x;
-long int n;
+#ifdef tahoe
+#define        double  float
+#endif /* tahoe */
 
 
-pow = 1;
-x = *ap;
-n = *bp;
+float
+pow_ri(ap, bp)
+       float *ap;
+       long *bp;
+{
+       register long n = *bp;
+#ifdef tahoe
+       register
+#endif /* tahoe */
+       double y, x = *ap;
 
 
-if(n != 0)
-       {
-       if(n < 0)
-               {
-               if(x == 0)
-                       {
-                       return(pow);
-                       }
+       if (!n)
+               return((double)1);
+       if (n < 0) {
+               x = (double)1 / x;
                n = -n;
                n = -n;
-               x = 1/x;
-               }
-       if (x == 0)
-               return(0);
-
-       for( ; ; )
-               {
-               if(n & 01)
-                       pow *= x;
-               if(n >>= 1)
+       }
+       while (!(n&1)) {
+               x *= x;
+               n >>= 1;
+       }
+       for (y = x; --n > 0; y *= x)
+               while (!(n&1)) {
                        x *= x;
                        x *= x;
-               else
-                       break;
+                       n >>= 1;
                }
                }
-       }
-return(pow);
+       return(y);
 }
 }
+#ifdef tahoe
+#undef double
+#endif /* tahoe */
index c77dcdf..1e3f098 100644 (file)
@@ -3,51 +3,40 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)pow_zi.c    5.1     %G%
+ *     @(#)pow_zi.c    5.2     %G%
  */
 
 #include "complex"
 
  */
 
 #include "complex"
 
+#define        Z_MULEQ(A,B)    \
+       t = (A).dreal * (B).dreal - (A).dimag * (B).dimag,\
+       (A).dimag = (A).dreal * (B).dimag + (A).dimag * (B).dreal,\
+       (A).dreal = t   /* A *= B */
+
+void
 pow_zi(p, a, b)        /* p = a**b  */
 pow_zi(p, a, b)        /* p = a**b  */
-dcomplex *p, *a;
-long int *b;
+       dcomplex *p, *a;
+       long int *b;
 {
 {
-long int n;
-double t;
-dcomplex x;
-
-n = *b;
-p->dreal = 1;
-p->dimag = 0;
+       register long n = *b;
+       double t;
+       dcomplex x;
 
 
-if(n == 0)
-       return;
-if(n < 0)
-       {
-       n = -n;
-       z_div(&x, p, a);
+       x = *a;
+       p->dreal = (double)1, p->dimag = (double)0;
+       if (!n)
+               return;
+       if (n < 0) {
+               z_div(&x, p, a);
+               n = -n;
        }
        }
-else
-       {
-       x.dreal = a->dreal;
-       x.dimag = a->dimag;
+       while (!(n&1)) {
+               Z_MULEQ(x, x);
+               n >>= 1;
        }
        }
-
-for( ; ; )
-       {
-       if(n & 01)
-               {
-               t = p->dreal * x.dreal - p->dimag * x.dimag;
-               p->dimag = p->dreal * x.dimag + p->dimag * x.dreal;
-               p->dreal = t;
+       for (*p = x; --n > 0; Z_MULEQ(*p, x))
+               while (!(n&1)) {
+                       Z_MULEQ(x, x);
+                       n >>= 1;
                }
                }
-       if(n >>= 1)
-               {
-               t = x.dreal * x.dreal - x.dimag * x.dimag;
-               x.dimag = 2 * x.dreal * x.dimag;
-               x.dreal = t;
-               }
-       else
-               break;
-       }
 }
 }