c_div.c 936 B

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