|
|
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: * @(#)c_sqrt.c 5.2 11/3/86 ! 7: */ ! 8: ! 9: #include "complex" ! 10: #ifdef tahoe ! 11: #include <tahoemath/FP.h> ! 12: #endif tahoe ! 13: ! 14: c_sqrt(r, z) ! 15: complex *r, *z; ! 16: { ! 17: double mag, sqrt(), cabs(); ! 18: ! 19: if( (mag = cabs(z->real, z->imag)) == 0.) ! 20: r->real = r->imag = 0.; ! 21: else if(z->real > 0) ! 22: { ! 23: r->real = sqrt(0.5 * (mag + z->real) ); ! 24: r->imag = z->imag / r->real / 2; ! 25: } ! 26: else ! 27: { ! 28: r->imag = sqrt(0.5 * (mag - z->real) ); ! 29: if(z->imag < 0) ! 30: #ifndef tahoe ! 31: r->imag = - r->imag; ! 32: #else tahoe ! 33: *(unsigned long*)&(r->imag) ^= SIGN_BIT; ! 34: #endif tahoe ! 35: r->real = z->imag / r->imag /2; ! 36: } ! 37: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.