xref: /csrg-svn/usr.bin/f77/libF77/cabs.c (revision 22837)
110448Sdlw /*
2*22837Skre  * Copyright (c) 1980 Regents of the University of California.
3*22837Skre  * All rights reserved.  The Berkeley software License Agreement
4*22837Skre  * specifies the terms and conditions for redistribution.
5*22837Skre  *
6*22837Skre  *	@(#)cabs.c	5.1	06/07/85
710448Sdlw  */
810448Sdlw 
cabs(real,imag)910448Sdlw double cabs(real, imag)
1010448Sdlw double real, imag;
1110448Sdlw {
1210448Sdlw double temp, sqrt();
1310448Sdlw 
1410448Sdlw if(real < 0)
1510448Sdlw 	real = -real;
1610448Sdlw if(imag < 0)
1710448Sdlw 	imag = -imag;
1810448Sdlw if(imag > real){
1910448Sdlw 	temp = real;
2010448Sdlw 	real = imag;
2110448Sdlw 	imag = temp;
2210448Sdlw }
2310448Sdlw if((real+imag) == real)
2410448Sdlw 	return(real);
2510448Sdlw 
2610448Sdlw temp = imag/real;
2710448Sdlw temp = real*sqrt(1.0 + temp*temp);  /*overflow!!*/
2810448Sdlw return(temp);
2910448Sdlw }
30