home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / f2c / f77lib / d_mod.c < prev    next >
C/C++ Source or Header  |  2000-06-22  |  621b  |  41 lines

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