home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / LIBSRC.ZOO / libsrc / longlong / fixudfdi.c < prev    next >
C/C++ Source or Header  |  1992-02-22  |  791b  |  32 lines

  1. #include "longlong.h"
  2.  
  3. #define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
  4.  
  5. long long
  6. __fixunsdfdi (a)
  7.      double a;
  8. {
  9.   double b;
  10.   unsigned long long v;
  11.  
  12.   if (a < 0)
  13.     return 0;
  14.  
  15.   /* Compute high word of result, as a flonum.  */
  16.   b = (a / HIGH_WORD_COEFF);
  17.   /* Convert that to fixed (but not to long long!),
  18.      and shift it into the high word.  */
  19.   v = (unsigned long int) b;
  20.   v <<= BITS_PER_WORD;
  21.   /* Remove high part from the double, leaving the low part as flonum.  */
  22.   a -= (double)v;
  23.   /* Convert that to fixed (but not to long long!) and add it in.
  24.      Sometimes A comes out negative.  This is significant, since
  25.      A has more bits than a long int does.  */
  26.   if (a < 0)
  27.     v -= (unsigned long int) (- a);
  28.   else
  29.     v += (unsigned long int) a;
  30.   return v;
  31. }
  32.