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
* 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.
*
-#ifndef tahoe
-pow_ci(p, a, b) /* p = a**b */
-complex *p, *a;
-long int *b;
-{
-dcomplex p1, a1;
-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 */
+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;
+ }
+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;
-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;
- }
-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;
* 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.
*
-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;
- 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)) {
+#ifdef tahoe
+#undef double
+#endif /* tahoe */
* 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.
*
+#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;
- }