c_sqrt.c
Go to the documentation of this file.
00001 #include "f2c.h"
00002 
00003 #ifdef KR_headers
00004 extern double sqrt(), f__cabs();
00005 
00006 VOID c_sqrt(r, z) complex *r, *z;
00007 #else
00008 #undef abs
00009 #include "math.h"
00010 #ifdef __cplusplus
00011 extern "C" {
00012 #endif
00013 extern double f__cabs(double, double);
00014 
00015 void c_sqrt(complex *r, complex *z)
00016 #endif
00017 {
00018         double mag, t;
00019         double zi = z->i, zr = z->r;
00020 
00021         if( (mag = f__cabs(zr, zi)) == 0.)
00022                 r->r = r->i = 0.;
00023         else if(zr > 0)
00024                 {
00025                 r->r = t = sqrt(0.5 * (mag + zr) );
00026                 t = zi / t;
00027                 r->i = 0.5 * t;
00028                 }
00029         else
00030                 {
00031                 t = sqrt(0.5 * (mag - zr) );
00032                 if(zi < 0)
00033                         t = -t;
00034                 r->i = t;
00035                 t = zi / t;
00036                 r->r = 0.5 * t;
00037                 }
00038         }
00039 #ifdef __cplusplus
00040 }
00041 #endif


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:15