117680Spst/*- 239297Sfenner * Copyright (c) 1992, 1993 317680Spst * The Regents of the University of California. All rights reserved. 417680Spst * 517680Spst * This software was developed by the Computer Systems Engineering group 617680Spst * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 717680Spst * contributed to Berkeley. 817680Spst * 917680Spst * Redistribution and use in source and binary forms, with or without 1017680Spst * modification, are permitted provided that the following conditions 1117680Spst * are met: 1217680Spst * 1. Redistributions of source code must retain the above copyright 1317680Spst * notice, this list of conditions and the following disclaimer. 1417680Spst * 2. Redistributions in binary form must reproduce the above copyright 1517680Spst * notice, this list of conditions and the following disclaimer in the 1617680Spst * documentation and/or other materials provided with the distribution. 1717680Spst * 4. Neither the name of the University nor the names of its contributors 1817680Spst * may be used to endorse or promote products derived from this software 1917680Spst * without specific prior written permission. 2017680Spst * 2117680Spst * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2217680Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2317680Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2417680Spst * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25127668Sbms * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26190207Srpaulo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2717680Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2817680Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2956893Sfenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3056893Sfenner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3156893Sfenner * SUCH DAMAGE. 3256893Sfenner */ 33127668Sbms 3417680Spst#if defined(LIBC_SCCS) && !defined(lint) 3517680Spststatic char sccsid[] = "@(#)floatdisf.c 8.1 (Berkeley) 6/4/93"; 3617680Spst#endif /* LIBC_SCCS and not lint */ 3717680Spst#include <sys/cdefs.h> 3817680Spst__FBSDID("$FreeBSD: releng/10.3/lib/libc/quad/floatdisf.c 165903 2007-01-09 00:28:16Z imp $"); 39127668Sbms 4017680Spst#include "quad.h" 41127668Sbms 42127668Sbms/* 43127668Sbms * Convert (signed) quad to float. 4417680Spst */ 4517680Spstfloat 4617680Spst__floatdisf(x) 4717680Spst quad_t x; 4817680Spst{ 4917680Spst float f; 5017680Spst union uu u; 5117680Spst int neg; 5217680Spst 5317680Spst /* 5417680Spst * Get an unsigned number first, by negating if necessary. 5517680Spst */ 5617680Spst if (x < 0) 5717680Spst u.q = -x, neg = 1; 5817680Spst else 5917680Spst u.q = x, neg = 0; 6017680Spst 6117680Spst /* 6217680Spst * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L] 6317680Spst * has the units. Ideally we could just set f, add LONG_BITS to 6417680Spst * its exponent, and then add the units, but this is portable 6517680Spst * code and does not know how to get at an exponent. Machine- 6617680Spst * specific code may be able to do this more efficiently. 6717680Spst * 68127668Sbms * Using double here may be excessive paranoia. 69127668Sbms */ 7017680Spst f = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0); 7117680Spst f += u.ul[L]; 7217680Spst 7317680Spst return (neg ? -f : f); 7417680Spst} 7539297Sfenner