Commit | Line | Data |
---|---|---|
9381a6f3 | 1 | /* |
3337a9c2 RE |
2 | * Copyright (c) 1980 Regents of the University of California. |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
6 | * @(#)z_sqrt.c 5.1 %G% | |
9381a6f3 DW |
7 | */ |
8 | ||
9 | #include "complex" | |
10 | ||
11 | z_sqrt(r, z) | |
12 | dcomplex *r, *z; | |
13 | { | |
14 | double mag, sqrt(), cabs(); | |
15 | ||
16 | if( (mag = cabs(z->dreal, z->dimag)) == 0.) | |
17 | r->dreal = r->dimag = 0.; | |
18 | else if(z->dreal > 0) | |
19 | { | |
20 | r->dreal = sqrt(0.5 * (mag + z->dreal) ); | |
21 | r->dimag = z->dimag / r->dreal / 2; | |
22 | } | |
23 | else | |
24 | { | |
25 | r->dimag = sqrt(0.5 * (mag - z->dreal) ); | |
26 | if(z->dimag < 0) | |
27 | r->dimag = - r->dimag; | |
28 | r->dreal = z->dimag / r->dimag / 2; | |
29 | } | |
30 | } |