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[] = "@(#)c_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 #endif 16 17 c_sqrt(r, z) 18 complex *r, *z; 19 { 20 double mag, sqrt(), cabs(); 21 22 if( (mag = cabs(z->real, z->imag)) == 0.) 23 r->real = r->imag = 0.; 24 else if(z->real > 0) 25 { 26 r->real = sqrt(0.5 * (mag + z->real) ); 27 r->imag = z->imag / r->real / 2; 28 } 29 else 30 { 31 r->imag = sqrt(0.5 * (mag - z->real) ); 32 if(z->imag < 0) 33 #ifndef tahoe 34 r->imag = - r->imag; 35 #else tahoe 36 *(unsigned long*)&(r->imag) ^= SIGN_BIT; 37 #endif tahoe 38 r->real = z->imag / r->imag /2; 39 } 40 } 41