z_div.c 913 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "f2c.h"
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #ifdef KR_headers
  6. extern VOID sig_die();
  7. VOID z_div(c, a, b) doublecomplex *a, *b, *c;
  8. #else
  9. extern void sig_die(const char*, int);
  10. void z_div(doublecomplex *c, doublecomplex *a, doublecomplex *b)
  11. #endif
  12. {
  13. double ratio, den;
  14. double abr, abi, cr;
  15. if( (abr = b->r) < 0.)
  16. abr = - abr;
  17. if( (abi = b->i) < 0.)
  18. abi = - abi;
  19. if( abr <= abi )
  20. {
  21. if(abi == 0) {
  22. #ifdef IEEE_COMPLEX_DIVIDE
  23. if (a->i != 0 || a->r != 0)
  24. abi = 1.;
  25. c->i = c->r = abi / abr;
  26. return;
  27. #else
  28. sig_die("complex division by zero", 1);
  29. #endif
  30. }
  31. ratio = b->r / b->i ;
  32. den = b->i * (1 + ratio*ratio);
  33. cr = (a->r*ratio + a->i) / den;
  34. c->i = (a->i*ratio - a->r) / den;
  35. }
  36. else
  37. {
  38. ratio = b->i / b->r ;
  39. den = b->r * (1 + ratio*ratio);
  40. cr = (a->r + a->i*ratio) / den;
  41. c->i = (a->i - a->r*ratio) / den;
  42. }
  43. c->r = cr;
  44. }
  45. #ifdef __cplusplus
  46. }
  47. #endif