date and time created 83/01/21 11:19:18 by dlw
[unix-history] / usr / src / usr.bin / f77 / libF77 / c_sqrt.c
CommitLineData
c788ff04
DW
1/*
2 * "@(#)c_sqrt.c 1.1"
3 */
4
5#include "complex"
6
7c_sqrt(r, z)
8complex *r, *z;
9{
10double mag, sqrt(), cabs();
11
12if( (mag = cabs(z->real, z->imag)) == 0.)
13 r->real = r->imag = 0.;
14else if(z->real > 0)
15 {
16 r->real = sqrt(0.5 * (mag + z->real) );
17 r->imag = z->imag / r->real / 2;
18 }
19else
20 {
21 r->imag = sqrt(0.5 * (mag - z->real) );
22 if(z->imag < 0)
23 r->imag = - r->imag;
24 r->real = z->imag / r->imag /2;
25 }
26}