xref: /csrg-svn/usr.bin/f77/libF77/z_sqrt.c (revision 23001)
110554Sdlw /*
2*23001Skre  * Copyright (c) 1980 Regents of the University of California.
3*23001Skre  * All rights reserved.  The Berkeley software License Agreement
4*23001Skre  * specifies the terms and conditions for redistribution.
5*23001Skre  *
6*23001Skre  *	@(#)z_sqrt.c	5.1	06/07/85
710554Sdlw  */
810554Sdlw 
910554Sdlw #include "complex"
1010554Sdlw 
1110554Sdlw z_sqrt(r, z)
1210554Sdlw dcomplex *r, *z;
1310554Sdlw {
1410554Sdlw double mag, sqrt(), cabs();
1510554Sdlw 
1610554Sdlw if( (mag = cabs(z->dreal, z->dimag)) == 0.)
1710554Sdlw 	r->dreal = r->dimag = 0.;
1810554Sdlw else if(z->dreal > 0)
1910554Sdlw 	{
2010554Sdlw 	r->dreal = sqrt(0.5 * (mag + z->dreal) );
2110554Sdlw 	r->dimag = z->dimag / r->dreal / 2;
2210554Sdlw 	}
2310554Sdlw else
2410554Sdlw 	{
2510554Sdlw 	r->dimag = sqrt(0.5 * (mag - z->dreal) );
2610554Sdlw 	if(z->dimag < 0)
2710554Sdlw 		r->dimag = - r->dimag;
2810554Sdlw 	r->dreal = z->dimag / r->dimag / 2;
2910554Sdlw 	}
3010554Sdlw }
31