1*54747Storek /*- 2*54747Storek * Copyright (c) 1992 The Regents of the University of California. 3*54747Storek * All rights reserved. 4*54747Storek * 5*54747Storek * This software was developed by the Computer Systems Engineering group 6*54747Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7*54747Storek * contributed to Berkeley. 8*54747Storek * 9*54747Storek * %sccs.include.redist.c% 10*54747Storek */ 11*54747Storek 12*54747Storek #if defined(LIBC_SCCS) && !defined(lint) 13*54747Storek static char sccsid[] = "@(#)floatdisf.c 5.1 (Berkeley) 07/07/92"; 14*54747Storek #endif /* LIBC_SCCS and not lint */ 15*54747Storek 16*54747Storek #include "quad.h" 17*54747Storek 18*54747Storek /* 19*54747Storek * Convert (signed) quad to float. 20*54747Storek */ 21*54747Storek float 22*54747Storek __floatdisf(x) 23*54747Storek quad_t x; 24*54747Storek { 25*54747Storek float f; 26*54747Storek union uu u; 27*54747Storek int neg; 28*54747Storek 29*54747Storek /* 30*54747Storek * Get an unsigned number first, by negating if necessary. 31*54747Storek */ 32*54747Storek if (x < 0) 33*54747Storek u.q = -x, neg = 1; 34*54747Storek else 35*54747Storek u.q = x, neg = 0; 36*54747Storek 37*54747Storek /* 38*54747Storek * Now u.ul[H] has the factor of 2^32 (or whatever) and u.ul[L] 39*54747Storek * has the units. Ideally we could just set f, add LONG_BITS to 40*54747Storek * its exponent, and then add the units, but this is portable 41*54747Storek * code and does not know how to get at an exponent. Machine- 42*54747Storek * specific code may be able to do this more efficiently. 43*54747Storek * 44*54747Storek * Using double here may be excessive paranoia. 45*54747Storek */ 46*54747Storek f = (double)u.ul[H] * ((1 << (LONG_BITS - 2)) * 4.0); 47*54747Storek f += u.ul[L]; 48*54747Storek 49*54747Storek return (neg ? -f : f); 50*54747Storek } 51