xref: /csrg-svn/lib/libc/quad/floatdidf.c (revision 61160)
153438Sbostic /*-
2*61160Sbostic  * Copyright (c) 1992, 1993
3*61160Sbostic  *	The Regents of the University of California.  All rights reserved.
453438Sbostic  *
553794Sbostic  * This software was developed by the Computer Systems Engineering group
653794Sbostic  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
753794Sbostic  * contributed to Berkeley.
853794Sbostic  *
953438Sbostic  * %sccs.include.redist.c%
1053438Sbostic  */
1153438Sbostic 
1253438Sbostic #if defined(LIBC_SCCS) && !defined(lint)
13*61160Sbostic static char sccsid[] = "@(#)floatdidf.c	8.1 (Berkeley) 06/04/93";
1453438Sbostic #endif /* LIBC_SCCS and not lint */
1553438Sbostic 
1653794Sbostic #include "quad.h"
1753459Sbostic 
1853794Sbostic /*
1953794Sbostic  * Convert (signed) quad to double.
2053794Sbostic  */
2153438Sbostic double
__floatdidf(x)2254431Sbostic __floatdidf(x)
2354431Sbostic 	quad_t x;
2453438Sbostic {
2553794Sbostic 	double d;
2653794Sbostic 	union uu u;
2753794Sbostic 	int neg;
2853438Sbostic 
2953794Sbostic 	/*
3053794Sbostic 	 * Get an unsigned number first, by negating if necessary.
3153794Sbostic 	 */
3253794Sbostic 	if (x < 0)
3353794Sbostic 		u.q = -x, neg = 1;
3453794Sbostic 	else
3553794Sbostic 		u.q = x, neg = 0;
3653438Sbostic 
3753794Sbostic 	/*
3853794Sbostic 	 * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
3953794Sbostic 	 * has the units.  Ideally we could just set d, add LONG_BITS to
4053794Sbostic 	 * its exponent, and then add the units, but this is portable
4153794Sbostic 	 * code and does not know how to get at an exponent.  Machine-
4253794Sbostic 	 * specific code may be able to do this more efficiently.
4353794Sbostic 	 */
4453794Sbostic 	d = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0);
4553794Sbostic 	d += u.ul[L];
4653438Sbostic 
4753794Sbostic 	return (neg ? -d : d);
4853438Sbostic }
49