110447Sdlw /* 2*22835Skre * Copyright (c) 1980 Regents of the University of California. 3*22835Skre * All rights reserved. The Berkeley software License Agreement 4*22835Skre * specifies the terms and conditions for redistribution. 5*22835Skre * 6*22835Skre * @(#)c_sqrt.c 5.1 06/07/85 710447Sdlw */ 810447Sdlw 910447Sdlw #include "complex" 1010447Sdlw 1110447Sdlw c_sqrt(r, z) 1210447Sdlw complex *r, *z; 1310447Sdlw { 1410447Sdlw double mag, sqrt(), cabs(); 1510447Sdlw 1610447Sdlw if( (mag = cabs(z->real, z->imag)) == 0.) 1710447Sdlw r->real = r->imag = 0.; 1810447Sdlw else if(z->real > 0) 1910447Sdlw { 2010447Sdlw r->real = sqrt(0.5 * (mag + z->real) ); 2110447Sdlw r->imag = z->imag / r->real / 2; 2210447Sdlw } 2310447Sdlw else 2410447Sdlw { 2510447Sdlw r->imag = sqrt(0.5 * (mag - z->real) ); 2610447Sdlw if(z->imag < 0) 2710447Sdlw r->imag = - r->imag; 2810447Sdlw r->real = z->imag / r->imag /2; 2910447Sdlw } 3010447Sdlw } 31