1*84d9c625SLionel Sambuc /* $NetBSD: floatundisf.c,v 1.4 2013/02/03 01:48:53 matt Exp $ */
2f14fb602SLionel Sambuc
3f14fb602SLionel Sambuc /*-
4f14fb602SLionel Sambuc * Copyright (c) 1992, 1993
5f14fb602SLionel Sambuc * The Regents of the University of California. All rights reserved.
6f14fb602SLionel Sambuc *
7f14fb602SLionel Sambuc * This software was developed by the Computer Systems Engineering group
8f14fb602SLionel Sambuc * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9f14fb602SLionel Sambuc * contributed to Berkeley.
10f14fb602SLionel Sambuc *
11f14fb602SLionel Sambuc * Redistribution and use in source and binary forms, with or without
12f14fb602SLionel Sambuc * modification, are permitted provided that the following conditions
13f14fb602SLionel Sambuc * are met:
14f14fb602SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
15f14fb602SLionel Sambuc * notice, this list of conditions and the following disclaimer.
16f14fb602SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
17f14fb602SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
18f14fb602SLionel Sambuc * documentation and/or other materials provided with the distribution.
19f14fb602SLionel Sambuc * 3. Neither the name of the University nor the names of its contributors
20f14fb602SLionel Sambuc * may be used to endorse or promote products derived from this software
21f14fb602SLionel Sambuc * without specific prior written permission.
22f14fb602SLionel Sambuc *
23f14fb602SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24f14fb602SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25f14fb602SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26f14fb602SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27f14fb602SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28f14fb602SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29f14fb602SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30f14fb602SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31f14fb602SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32f14fb602SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33f14fb602SLionel Sambuc * SUCH DAMAGE.
34f14fb602SLionel Sambuc */
35f14fb602SLionel Sambuc
36f14fb602SLionel Sambuc #include <sys/cdefs.h>
37f14fb602SLionel Sambuc #if defined(LIBC_SCCS) && !defined(lint)
38f14fb602SLionel Sambuc #if 0
39f14fb602SLionel Sambuc static char sccsid[] = "@(#)floatdisf.c 8.1 (Berkeley) 6/4/93";
40f14fb602SLionel Sambuc #else
41*84d9c625SLionel Sambuc __RCSID("$NetBSD: floatundisf.c,v 1.4 2013/02/03 01:48:53 matt Exp $");
42f14fb602SLionel Sambuc #endif
43f14fb602SLionel Sambuc #endif /* LIBC_SCCS and not lint */
44f14fb602SLionel Sambuc
45*84d9c625SLionel Sambuc #if defined(SOFTFLOAT) || defined(__ARM_EABI__)
46f14fb602SLionel Sambuc #include "softfloat/softfloat-for-gcc.h"
47f14fb602SLionel Sambuc #endif
48f14fb602SLionel Sambuc
49f14fb602SLionel Sambuc #include "quad.h"
50f14fb602SLionel Sambuc
51f14fb602SLionel Sambuc /*
52f14fb602SLionel Sambuc * Convert (unsigned) quad to float.
53f14fb602SLionel Sambuc */
54f14fb602SLionel Sambuc float
__floatundisf(u_quad_t x)55f14fb602SLionel Sambuc __floatundisf(u_quad_t x)
56f14fb602SLionel Sambuc {
57f14fb602SLionel Sambuc float f;
58f14fb602SLionel Sambuc union uu u;
59f14fb602SLionel Sambuc
60f14fb602SLionel Sambuc u.q = x;
61f14fb602SLionel Sambuc
62f14fb602SLionel Sambuc /*
63f14fb602SLionel Sambuc * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L]
64f14fb602SLionel Sambuc * has the units. Ideally we could just set f, add INT_BITS to
65f14fb602SLionel Sambuc * its exponent, and then add the units, but this is portable
66f14fb602SLionel Sambuc * code and does not know how to get at an exponent. Machine-
67f14fb602SLionel Sambuc * specific code may be able to do this more efficiently.
68f14fb602SLionel Sambuc *
69f14fb602SLionel Sambuc * Using double here may be excessive paranoia.
70f14fb602SLionel Sambuc */
71f14fb602SLionel Sambuc f = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0);
72f14fb602SLionel Sambuc f += u.ul[L];
73f14fb602SLionel Sambuc
74f14fb602SLionel Sambuc return f;
75f14fb602SLionel Sambuc }
76