|
|
1.1 ! root 1: /* ! 2: * "@(#)z_sqrt.c 1.1" ! 3: */ ! 4: ! 5: #include "complex" ! 6: ! 7: z_sqrt(r, z) ! 8: dcomplex *r, *z; ! 9: { ! 10: double mag, sqrt(), cabs(); ! 11: ! 12: if( (mag = cabs(z->dreal, z->dimag)) == 0.) ! 13: r->dreal = r->dimag = 0.; ! 14: else if(z->dreal > 0) ! 15: { ! 16: r->dreal = sqrt(0.5 * (mag + z->dreal) ); ! 17: r->dimag = z->dimag / r->dreal / 2; ! 18: } ! 19: else ! 20: { ! 21: r->dimag = sqrt(0.5 * (mag - z->dreal) ); ! 22: if(z->dimag < 0) ! 23: r->dimag = - r->dimag; ! 24: r->dreal = z->dimag / r->dimag / 2; ! 25: } ! 26: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.