From 9381a6f3f437b4c2dfab832d20176e45d0f75bc7 Mon Sep 17 00:00:00 2001 From: David Wasley Date: Fri, 21 Jan 1983 19:21:04 -0800 Subject: [PATCH] date and time created 83/01/21 11:21:04 by dlw SCCS-vsn: usr.bin/f77/libF77/z_sqrt.c 1.1 --- usr/src/usr.bin/f77/libF77/z_sqrt.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 usr/src/usr.bin/f77/libF77/z_sqrt.c diff --git a/usr/src/usr.bin/f77/libF77/z_sqrt.c b/usr/src/usr.bin/f77/libF77/z_sqrt.c new file mode 100644 index 0000000000..3a6160e123 --- /dev/null +++ b/usr/src/usr.bin/f77/libF77/z_sqrt.c @@ -0,0 +1,26 @@ +/* + * "@(#)z_sqrt.c 1.1" + */ + +#include "complex" + +z_sqrt(r, z) +dcomplex *r, *z; +{ +double mag, sqrt(), cabs(); + +if( (mag = cabs(z->dreal, z->dimag)) == 0.) + r->dreal = r->dimag = 0.; +else if(z->dreal > 0) + { + r->dreal = sqrt(0.5 * (mag + z->dreal) ); + r->dimag = z->dimag / r->dreal / 2; + } +else + { + r->dimag = sqrt(0.5 * (mag - z->dreal) ); + if(z->dimag < 0) + r->dimag = - r->dimag; + r->dreal = z->dimag / r->dimag / 2; + } +} -- 2.20.1