110554Sdlw /* 223001Skre * Copyright (c) 1980 Regents of the University of California. 323001Skre * All rights reserved. The Berkeley software License Agreement 423001Skre * specifies the terms and conditions for redistribution. 523001Skre * 6*29973Smckusick * @(#)z_sqrt.c 5.2 11/03/86 710554Sdlw */ 810554Sdlw 910554Sdlw #include "complex" 10*29973Smckusick #ifdef tahoe 11*29973Smckusick #include <tahoemath/FP.h> 12*29973Smckusick #define cabs zabs 13*29973Smckusick #endif tahoe 1410554Sdlw 1510554Sdlw z_sqrt(r, z) 1610554Sdlw dcomplex *r, *z; 1710554Sdlw { 1810554Sdlw double mag, sqrt(), cabs(); 1910554Sdlw 2010554Sdlw if( (mag = cabs(z->dreal, z->dimag)) == 0.) 2110554Sdlw r->dreal = r->dimag = 0.; 2210554Sdlw else if(z->dreal > 0) 2310554Sdlw { 2410554Sdlw r->dreal = sqrt(0.5 * (mag + z->dreal) ); 2510554Sdlw r->dimag = z->dimag / r->dreal / 2; 2610554Sdlw } 2710554Sdlw else 2810554Sdlw { 2910554Sdlw r->dimag = sqrt(0.5 * (mag - z->dreal) ); 3010554Sdlw if(z->dimag < 0) 31*29973Smckusick #ifndef tahoe 3210554Sdlw r->dimag = - r->dimag; 33*29973Smckusick #else tahoe 34*29973Smckusick *((long int *)&r->dimag) ^= SIGN_BIT; 35*29973Smckusick #endif tahoe 3610554Sdlw r->dreal = z->dimag / r->dimag / 2; 3710554Sdlw } 3810554Sdlw } 39