Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
pow_zi.c
Go to the documentation of this file.00001 #include "f2c.h"
00002
00003 #ifdef KR_headers
00004 VOID pow_zi(p, a, b)
00005 doublecomplex *p, *a; integer *b;
00006 #else
00007 extern void z_div(doublecomplex*, doublecomplex*, doublecomplex*);
00008 void pow_zi(doublecomplex *p, doublecomplex *a, integer *b)
00009 #endif
00010 {
00011 integer n;
00012 unsigned long u;
00013 double t;
00014 doublecomplex x;
00015 static doublecomplex one = {1.0, 0.0};
00016
00017 n = *b;
00018 p->r = 1;
00019 p->i = 0;
00020
00021 if(n == 0)
00022 return;
00023 if(n < 0)
00024 {
00025 n = -n;
00026 z_div(&x, &one, a);
00027 }
00028 else
00029 {
00030 x.r = a->r;
00031 x.i = a->i;
00032 }
00033
00034 for(u = n; ; )
00035 {
00036 if(u & 01)
00037 {
00038 t = p->r * x.r - p->i * x.i;
00039 p->i = p->r * x.i + p->i * x.r;
00040 p->r = t;
00041 }
00042 if(u >>= 1)
00043 {
00044 t = x.r * x.r - x.i * x.i;
00045 x.i = 2 * x.r * x.i;
00046 x.r = t;
00047 }
00048 else
00049 break;
00050 }
00051 }