home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_DEV08B.LHA / gerlib / Bonus / normal / modf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  558 b   |  26 lines

  1. #include <inline/mathieeedoubbas.h>
  2.  
  3. /*
  4.  * modf(value, iptr): return fractional part of value, and stores the
  5.  * integral part into iptr (a pointer to double).
  6.  */
  7.  
  8. double
  9. modf (double value, double *iptr)
  10. {
  11.   /* if value negative */
  12.   if (IEEEDPTst (value) < 0)
  13.     {
  14.       /* in that case, the integer part is calculated by ceil() */
  15.       *iptr = IEEEDPCeil (value);
  16.       return IEEEDPSub (*iptr, value);
  17.     }
  18.   else
  19.     {
  20.  
  21.       /* if positive, we go for the floor() */
  22.       *iptr = IEEEDPFloor (value);
  23.       return IEEEDPSub (value, *iptr);
  24.     }
  25. }
  26.