386BSD 0.1 development
authorWilliam F. Jolitz <wjolitz@soda.berkeley.edu>
Tue, 22 Jan 1991 06:54:07 +0000 (22:54 -0800)
committerWilliam F. Jolitz <wjolitz@soda.berkeley.edu>
Tue, 22 Jan 1991 06:54:07 +0000 (22:54 -0800)
Work on file usr/src/usr.bin/gcc/gnulib/longlong/fixunsdfdi.c

Co-Authored-By: Lynne Greer Jolitz <ljolitz@cardio.ucsf.edu>
Synthesized-from: 386BSD-0.1

usr/src/usr.bin/gcc/gnulib/longlong/fixunsdfdi.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/gcc/gnulib/longlong/fixunsdfdi.c b/usr/src/usr.bin/gcc/gnulib/longlong/fixunsdfdi.c
new file mode 100644 (file)
index 0000000..ee5bfe8
--- /dev/null
@@ -0,0 +1,31 @@
+#include "longlong.h"
+
+#define HIGH_WORD_COEFF (((long long) 1) << BITS_PER_WORD)
+
+long long
+__fixunsdfdi (a)
+     double a;
+{
+  double b;
+  unsigned long long v;
+
+  if (a < 0)
+    return 0;
+
+  /* Compute high word of result, as a flonum.  */
+  b = (a / HIGH_WORD_COEFF);
+  /* Convert that to fixed (but not to long long!),
+     and shift it into the high word.  */
+  v = (unsigned long int) b;
+  v <<= BITS_PER_WORD;
+  /* Remove high part from the double, leaving the low part as flonum.  */
+  a -= (double)v;
+  /* Convert that to fixed (but not to long long!) and add it in.
+     Sometimes A comes out negative.  This is significant, since
+     A has more bits than a long int does.  */
+  if (a < 0)
+    v -= (unsigned long int) (- a);
+  else
+    v += (unsigned long int) a;
+  return v;
+}