xref: /csrg-svn/lib/libc/quad/floatdisf.c (revision 61160)
154747Storek /*-
2*61160Sbostic  * Copyright (c) 1992, 1993
3*61160Sbostic  *	The Regents of the University of California.  All rights reserved.
454747Storek  *
554747Storek  * This software was developed by the Computer Systems Engineering group
654747Storek  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
754747Storek  * contributed to Berkeley.
854747Storek  *
954747Storek  * %sccs.include.redist.c%
1054747Storek  */
1154747Storek 
1254747Storek #if defined(LIBC_SCCS) && !defined(lint)
13*61160Sbostic static char sccsid[] = "@(#)floatdisf.c	8.1 (Berkeley) 06/04/93";
1454747Storek #endif /* LIBC_SCCS and not lint */
1554747Storek 
1654747Storek #include "quad.h"
1754747Storek 
1854747Storek /*
1954747Storek  * Convert (signed) quad to float.
2054747Storek  */
2154747Storek float
__floatdisf(x)2254747Storek __floatdisf(x)
2354747Storek 	quad_t x;
2454747Storek {
2554747Storek 	float f;
2654747Storek 	union uu u;
2754747Storek 	int neg;
2854747Storek 
2954747Storek 	/*
3054747Storek 	 * Get an unsigned number first, by negating if necessary.
3154747Storek 	 */
3254747Storek 	if (x < 0)
3354747Storek 		u.q = -x, neg = 1;
3454747Storek 	else
3554747Storek 		u.q = x, neg = 0;
3654747Storek 
3754747Storek 	/*
3854747Storek 	 * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
3954747Storek 	 * has the units.  Ideally we could just set f, add LONG_BITS to
4054747Storek 	 * its exponent, and then add the units, but this is portable
4154747Storek 	 * code and does not know how to get at an exponent.  Machine-
4254747Storek 	 * specific code may be able to do this more efficiently.
4354747Storek 	 *
4454747Storek 	 * Using double here may be excessive paranoia.
4554747Storek 	 */
4654747Storek 	f = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0);
4754747Storek 	f += u.ul[L];
4854747Storek 
4954747Storek 	return (neg ? -f : f);
5054747Storek }
51