|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: * ! 6: * @(#)z_sqrt.c 5.2 11/3/86 ! 7: */ ! 8: ! 9: #include "complex" ! 10: #ifdef tahoe ! 11: #include <tahoemath/FP.h> ! 12: #define cabs zabs ! 13: #endif tahoe ! 14: ! 15: z_sqrt(r, z) ! 16: dcomplex *r, *z; ! 17: { ! 18: double mag, sqrt(), cabs(); ! 19: ! 20: if( (mag = cabs(z->dreal, z->dimag)) == 0.) ! 21: r->dreal = r->dimag = 0.; ! 22: else if(z->dreal > 0) ! 23: { ! 24: r->dreal = sqrt(0.5 * (mag + z->dreal) ); ! 25: r->dimag = z->dimag / r->dreal / 2; ! 26: } ! 27: else ! 28: { ! 29: r->dimag = sqrt(0.5 * (mag - z->dreal) ); ! 30: if(z->dimag < 0) ! 31: #ifndef tahoe ! 32: r->dimag = - r->dimag; ! 33: #else tahoe ! 34: *((long int *)&r->dimag) ^= SIGN_BIT; ! 35: #endif tahoe ! 36: r->dreal = z->dimag / r->dimag / 2; ! 37: } ! 38: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.