1 /*- 2 * Copyright (c) 1980 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.proprietary.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)z_sqrt.c 5.4 (Berkeley) 04/12/91"; 10 #endif /* not lint */ 11 12 #include "complex" 13 #ifdef tahoe 14 #include <tahoe/math/FP.h> 15 #define cabs zabs 16 #endif 17 18 z_sqrt(r, z) 19 dcomplex *r, *z; 20 { 21 double mag, sqrt(), cabs(); 22 23 if( (mag = cabs(z->dreal, z->dimag)) == 0.) 24 r->dreal = r->dimag = 0.; 25 else if(z->dreal > 0) 26 { 27 r->dreal = sqrt(0.5 * (mag + z->dreal) ); 28 r->dimag = z->dimag / r->dreal / 2; 29 } 30 else 31 { 32 r->dimag = sqrt(0.5 * (mag - z->dreal) ); 33 if(z->dimag < 0) 34 #ifndef tahoe 35 r->dimag = - r->dimag; 36 #else tahoe 37 *((long int *)&r->dimag) ^= SIGN_BIT; 38 #endif tahoe 39 r->dreal = z->dimag / r->dimag / 2; 40 } 41 } 42