floatundisf.c revision 1.4
11.4Smatt/* $NetBSD: floatundisf.c,v 1.4 2013/02/03 01:48:53 matt Exp $ */ 21.1Smrg 31.1Smrg/*- 41.1Smrg * Copyright (c) 1992, 1993 51.1Smrg * The Regents of the University of California. All rights reserved. 61.1Smrg * 71.1Smrg * This software was developed by the Computer Systems Engineering group 81.1Smrg * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 91.1Smrg * contributed to Berkeley. 101.1Smrg * 111.1Smrg * Redistribution and use in source and binary forms, with or without 121.1Smrg * modification, are permitted provided that the following conditions 131.1Smrg * are met: 141.1Smrg * 1. Redistributions of source code must retain the above copyright 151.1Smrg * notice, this list of conditions and the following disclaimer. 161.1Smrg * 2. Redistributions in binary form must reproduce the above copyright 171.1Smrg * notice, this list of conditions and the following disclaimer in the 181.1Smrg * documentation and/or other materials provided with the distribution. 191.1Smrg * 3. Neither the name of the University nor the names of its contributors 201.1Smrg * may be used to endorse or promote products derived from this software 211.1Smrg * without specific prior written permission. 221.1Smrg * 231.1Smrg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241.1Smrg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251.1Smrg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261.1Smrg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271.1Smrg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281.1Smrg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291.1Smrg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.1Smrg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.1Smrg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.1Smrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.1Smrg * SUCH DAMAGE. 341.1Smrg */ 351.1Smrg 361.1Smrg#include <sys/cdefs.h> 371.1Smrg#if defined(LIBC_SCCS) && !defined(lint) 381.1Smrg#if 0 391.1Smrgstatic char sccsid[] = "@(#)floatdisf.c 8.1 (Berkeley) 6/4/93"; 401.1Smrg#else 411.4Smatt__RCSID("$NetBSD: floatundisf.c,v 1.4 2013/02/03 01:48:53 matt Exp $"); 421.1Smrg#endif 431.1Smrg#endif /* LIBC_SCCS and not lint */ 441.1Smrg 451.4Smatt#if defined(SOFTFLOAT) || defined(__ARM_EABI__) 461.3Smatt#include "softfloat/softfloat-for-gcc.h" 471.3Smatt#endif 481.3Smatt 491.1Smrg#include "quad.h" 501.1Smrg 511.1Smrg/* 521.1Smrg * Convert (unsigned) quad to float. 531.1Smrg */ 541.1Smrgfloat 551.1Smrg__floatundisf(u_quad_t x) 561.1Smrg{ 571.1Smrg float f; 581.1Smrg union uu u; 591.1Smrg 601.1Smrg u.q = x; 611.1Smrg 621.1Smrg /* 631.1Smrg * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L] 641.1Smrg * has the units. Ideally we could just set f, add INT_BITS to 651.1Smrg * its exponent, and then add the units, but this is portable 661.1Smrg * code and does not know how to get at an exponent. Machine- 671.1Smrg * specific code may be able to do this more efficiently. 681.1Smrg * 691.1Smrg * Using double here may be excessive paranoia. 701.1Smrg */ 711.2Schristos f = (double)u.ul[H] * (((int)1 << (unsigned int)(INT_BITS - 2)) * 4.0); 721.1Smrg f += u.ul[L]; 731.1Smrg 741.1Smrg return f; 751.1Smrg} 76