Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
z_sqrt.c
Go to the documentation of this file.00001 #include "f2c.h"
00002
00003 #ifdef KR_headers
00004 double sqrt(), f__cabs();
00005 VOID z_sqrt(r, z) doublecomplex *r, *z;
00006 #else
00007 #undef abs
00008 #include "mathh.h"
00009 extern double f__cabs(double, double);
00010 void z_sqrt(doublecomplex *r, doublecomplex *z)
00011 #endif
00012 {
00013 double mag;
00014
00015 if( (mag = f__cabs(z->r, z->i)) == 0.)
00016 r->r = r->i = 0.;
00017 else if(z->r > 0)
00018 {
00019 r->r = sqrt(0.5 * (mag + z->r) );
00020 r->i = z->i / r->r / 2;
00021 }
00022 else
00023 {
00024 r->i = sqrt(0.5 * (mag - z->r) );
00025 if(z->i < 0)
00026 r->i = - r->i;
00027 r->r = z->i / r->i / 2;
00028 }
00029 }