home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / Python2 / Python20_source / Amiga / fmod.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-25  |  672 b   |  32 lines

  1.  
  2. /* Portable fmod(x, y) implementation for systems that don't have it */
  3.  
  4. /* This version adapted to Amiga FFP/IEEE roundoff errors */
  5.  
  6. #include <errno.h>
  7. #include "config.h"
  8.  
  9.  
  10. /* Only use this function for FFP or IEEE math */
  11.  
  12. #if defined(_FFP) || (defined(_IEEE) && !defined(_M68881))
  13.  
  14. double fmod(double x, double y)
  15. {
  16.         double f;
  17.  
  18.         if (y == 0.0) {
  19.                 errno = EDOM;
  20.                 return 0.0;
  21.         }
  22.  
  23.         /* return f such that x = i*y + f for some integer i
  24.            such that |f| < |y| and f has the same sign as x */
  25.  
  26.         f = x-y*floor(x/y);
  27.                 if((f!=0.0) && ((x<0.0)!=(y<0.0))) f-=y;
  28.         return f;
  29. }
  30.  
  31. #endif
  32.