floatdidf.c revision 1.5
11.5Sscw/*	$NetBSD: floatdidf.c,v 1.5 2002/10/20 10:15:47 scw Exp $	*/
21.3Scgd
31.1Smycroft/*-
41.1Smycroft * Copyright (c) 1992, 1993
51.1Smycroft *	The Regents of the University of California.  All rights reserved.
61.1Smycroft *
71.1Smycroft * This software was developed by the Computer Systems Engineering group
81.1Smycroft * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
91.1Smycroft * contributed to Berkeley.
101.1Smycroft *
111.1Smycroft * Redistribution and use in source and binary forms, with or without
121.1Smycroft * modification, are permitted provided that the following conditions
131.1Smycroft * are met:
141.1Smycroft * 1. Redistributions of source code must retain the above copyright
151.1Smycroft *    notice, this list of conditions and the following disclaimer.
161.1Smycroft * 2. Redistributions in binary form must reproduce the above copyright
171.1Smycroft *    notice, this list of conditions and the following disclaimer in the
181.1Smycroft *    documentation and/or other materials provided with the distribution.
191.1Smycroft * 3. All advertising materials mentioning features or use of this software
201.1Smycroft *    must display the following acknowledgement:
211.1Smycroft *	This product includes software developed by the University of
221.1Smycroft *	California, Berkeley and its contributors.
231.1Smycroft * 4. Neither the name of the University nor the names of its contributors
241.1Smycroft *    may be used to endorse or promote products derived from this software
251.1Smycroft *    without specific prior written permission.
261.1Smycroft *
271.1Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
281.1Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
291.1Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
301.1Smycroft * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
311.1Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
321.1Smycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
331.1Smycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
341.1Smycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
351.1Smycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
361.1Smycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
371.1Smycroft * SUCH DAMAGE.
381.1Smycroft */
391.1Smycroft
401.4Schristos#include <sys/cdefs.h>
411.1Smycroft#if defined(LIBC_SCCS) && !defined(lint)
421.3Scgd#if 0
431.3Scgdstatic char sccsid[] = "@(#)floatdidf.c	8.1 (Berkeley) 6/4/93";
441.3Scgd#else
451.5Sscw__RCSID("$NetBSD: floatdidf.c,v 1.5 2002/10/20 10:15:47 scw Exp $");
461.3Scgd#endif
471.1Smycroft#endif /* LIBC_SCCS and not lint */
481.1Smycroft
491.1Smycroft#include "quad.h"
501.1Smycroft
511.1Smycroft/*
521.1Smycroft * Convert (signed) quad to double.
531.1Smycroft */
541.1Smycroftdouble
551.1Smycroft__floatdidf(x)
561.1Smycroft	quad_t x;
571.1Smycroft{
581.1Smycroft	double d;
591.1Smycroft	union uu u;
601.1Smycroft	int neg;
611.1Smycroft
621.1Smycroft	/*
631.1Smycroft	 * Get an unsigned number first, by negating if necessary.
641.1Smycroft	 */
651.1Smycroft	if (x < 0)
661.1Smycroft		u.q = -x, neg = 1;
671.1Smycroft	else
681.1Smycroft		u.q = x, neg = 0;
691.1Smycroft
701.1Smycroft	/*
711.1Smycroft	 * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
721.5Sscw	 * has the units.  Ideally we could just set d, add INT_BITS to
731.1Smycroft	 * its exponent, and then add the units, but this is portable
741.1Smycroft	 * code and does not know how to get at an exponent.  Machine-
751.1Smycroft	 * specific code may be able to do this more efficiently.
761.1Smycroft	 */
771.5Sscw	d = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0);
781.1Smycroft	d += u.ul[L];
791.1Smycroft
801.1Smycroft	return (neg ? -d : d);
811.1Smycroft}
82