r_mod.c 678 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "f2c.h"
  2. #ifdef KR_headers
  3. #ifdef IEEE_drem
  4. double drem();
  5. #else
  6. double floor();
  7. #endif
  8. double r_mod(x,y) real *x, *y;
  9. #else
  10. #ifdef IEEE_drem
  11. double drem(double, double);
  12. #else
  13. #undef abs
  14. #include "math.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #endif
  19. double r_mod(real *x, real *y)
  20. #endif
  21. {
  22. #ifdef IEEE_drem
  23. double xa, ya, z;
  24. if ((ya = *y) < 0.)
  25. ya = -ya;
  26. z = drem(xa = *x, ya);
  27. if (xa > 0) {
  28. if (z < 0)
  29. z += ya;
  30. }
  31. else if (z > 0)
  32. z -= ya;
  33. return z;
  34. #else
  35. double quotient;
  36. if( (quotient = (double)*x / *y) >= 0)
  37. quotient = floor(quotient);
  38. else
  39. quotient = -floor(-quotient);
  40. return(*x - (*y) * quotient );
  41. #endif
  42. }
  43. #ifdef __cplusplus
  44. }
  45. #endif