floatundisf.c revision 1.1
11.1Smrg/* $NetBSD: floatundisf.c,v 1.1 2011/07/04 11:22:39 mrg 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.1Smrg__RCSID("$NetBSD: floatundisf.c,v 1.1 2011/07/04 11:22:39 mrg Exp $"); 421.1Smrg#endif 431.1Smrg#endif /* LIBC_SCCS and not lint */ 441.1Smrg 451.1Smrg#include "quad.h" 461.1Smrg 471.1Smrg/* 481.1Smrg * Convert (unsigned) quad to float. 491.1Smrg */ 501.1Smrgfloat 511.1Smrg__floatundisf(u_quad_t x) 521.1Smrg{ 531.1Smrg float f; 541.1Smrg union uu u; 551.1Smrg 561.1Smrg u.q = x; 571.1Smrg 581.1Smrg /* 591.1Smrg * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L] 601.1Smrg * has the units. Ideally we could just set f, add INT_BITS to 611.1Smrg * its exponent, and then add the units, but this is portable 621.1Smrg * code and does not know how to get at an exponent. Machine- 631.1Smrg * specific code may be able to do this more efficiently. 641.1Smrg * 651.1Smrg * Using double here may be excessive paranoia. 661.1Smrg */ 671.1Smrg f = (double)u.ul[H] * (((int)1 << (INT_BITS - 2)) * 4.0); 681.1Smrg f += u.ul[L]; 691.1Smrg 701.1Smrg return f; 711.1Smrg} 72