date and time created 92/07/07 11:50:15 by torek
authorChris Torek <torek@ucbvax.Berkeley.EDU>
Wed, 8 Jul 1992 02:50:15 +0000 (18:50 -0800)
committerChris Torek <torek@ucbvax.Berkeley.EDU>
Wed, 8 Jul 1992 02:50:15 +0000 (18:50 -0800)
SCCS-vsn: lib/libc/quad/floatdisf.c 5.1

usr/src/lib/libc/quad/floatdisf.c [new file with mode: 0644]

diff --git a/usr/src/lib/libc/quad/floatdisf.c b/usr/src/lib/libc/quad/floatdisf.c
new file mode 100644 (file)
index 0000000..ff2d7a0
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 1992 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * %sccs.include.redist.c%
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)floatdisf.c        5.1 (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include "quad.h"
+
+/*
+ * Convert (signed) quad to float.
+ */
+float
+__floatdisf(x)
+       quad_t x;
+{
+       float f;
+       union uu u;
+       int neg;
+
+       /*
+        * Get an unsigned number first, by negating if necessary.
+        */
+       if (x < 0)
+               u.q = -x, neg = 1;
+       else
+               u.q = x, neg = 0;
+
+       /*
+        * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
+        * has the units.  Ideally we could just set f, add LONG_BITS to
+        * its exponent, and then add the units, but this is portable
+        * code and does not know how to get at an exponent.  Machine-
+        * specific code may be able to do this more efficiently.
+        *
+        * Using double here may be excessive paranoia.
+        */
+       f = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0);
+       f += u.ul[L];
+
+       return (neg ? -f : f);
+}