added whiteout
[unix-history] / usr / src / lib / libc / quad / floatdisf.c
CommitLineData
54a39327 1/*-
f7e479c4
KB
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
54a39327
CT
4 *
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
8 *
9 * %sccs.include.redist.c%
10 */
11
12#if defined(LIBC_SCCS) && !defined(lint)
f7e479c4 13static char sccsid[] = "@(#)floatdisf.c 8.1 (Berkeley) %G%";
54a39327
CT
14#endif /* LIBC_SCCS and not lint */
15
16#include "quad.h"
17
18/*
19 * Convert (signed) quad to float.
20 */
21float
22__floatdisf(x)
23 quad_t x;
24{
25 float f;
26 union uu u;
27 int neg;
28
29 /*
30 * Get an unsigned number first, by negating if necessary.
31 */
32 if (x < 0)
33 u.q = -x, neg = 1;
34 else
35 u.q = x, neg = 0;
36
37 /*
38 * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
39 * has the units. Ideally we could just set f, add LONG_BITS to
40 * its exponent, and then add the units, but this is portable
41 * code and does not know how to get at an exponent. Machine-
42 * specific code may be able to do this more efficiently.
43 *
44 * Using double here may be excessive paranoia.
45 */
46 f = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0);
47 f += u.ul[L];
48
49 return (neg ? -f : f);
50}