Doxygen Source Code Documentation
pow_zi.c File Reference
#include "f2c.h"
Go to the source code of this file.
Functions | |
void | z_div (doublecomplex *, doublecomplex *, doublecomplex *) |
void | pow_zi (doublecomplex *p, doublecomplex *a, integer *b) |
Function Documentation
|
Definition at line 8 of file pow_zi.c. References a, doublecomplex::i, p, doublecomplex::r, and z_div(). Referenced by pow_ci().
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 } |
|
Definition at line 8 of file z_div.c. References a, c, and sig_die(). Referenced by pow_zi().
00010 { 00011 double ratio, den; 00012 double abr, abi; 00013 00014 if( (abr = b->r) < 0.) 00015 abr = - abr; 00016 if( (abi = b->i) < 0.) 00017 abi = - abi; 00018 if( abr <= abi ) 00019 { 00020 if(abi == 0) 00021 sig_die("complex division by zero", 1); 00022 ratio = b->r / b->i ; 00023 den = b->i * (1 + ratio*ratio); 00024 c->r = (a->r*ratio + a->i) / den; 00025 c->i = (a->i*ratio - a->r) / den; 00026 } 00027 00028 else 00029 { 00030 ratio = b->i / b->r ; 00031 den = b->r * (1 + ratio*ratio); 00032 c->r = (a->r + a->i*ratio) / den; 00033 c->i = (a->i - a->r*ratio) / den; 00034 } 00035 00036 } |