1*54386Storek /* 2*54386Storek * Copyright (c) 1992 The Regents of the University of California. 3*54386Storek * All rights reserved. 4*54386Storek * 5*54386Storek * This software was developed by the Computer Systems Engineering group 6*54386Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7*54386Storek * contributed to Berkeley. 8*54386Storek * 9*54386Storek * %sccs.include.redist.c% 10*54386Storek * 11*54386Storek * from: $Header: frexp.c,v 1.1 91/07/07 04:45:01 torek Exp $ 12*54386Storek */ 13*54386Storek 14*54386Storek #if defined(LIBC_SCCS) && !defined(lint) 15*54386Storek static char sccsid[] = "@(#)frexp.c 5.1 (Berkeley) 06/25/92"; 16*54386Storek #endif /* LIBC_SCCS and not lint */ 17*54386Storek 18*54386Storek #include <sys/types.h> 19*54386Storek #include <machine/ieee.h> 20*54386Storek 21*54386Storek /* 22*54386Storek * Split the given value into a fraction in the range [0.5, 1.0) and 23*54386Storek * an exponent, such that frac * (2^exp) == value. If value is 0, 24*54386Storek * return 0. 25*54386Storek */ 26*54386Storek double 27*54386Storek frexp(value, eptr) 28*54386Storek double value; 29*54386Storek int *eptr; 30*54386Storek { 31*54386Storek union { 32*54386Storek double v; 33*54386Storek struct ieee_double s; 34*54386Storek } u; 35*54386Storek 36*54386Storek if (value) { 37*54386Storek /* 38*54386Storek * Fractions in [0.5..1.0) have an exponent of 2^-1. 39*54386Storek * Leave Inf and NaN alone, however. 40*54386Storek * WHAT ABOUT DENORMS? 41*54386Storek */ 42*54386Storek u.v = value; 43*54386Storek if (u.s.dbl_exp != DBL_EXP_INFNAN) { 44*54386Storek *eptr = u.s.dbl_exp - (DBL_EXP_BIAS - 1); 45*54386Storek u.s.dbl_exp = DBL_EXP_BIAS - 1; 46*54386Storek } 47*54386Storek return (u.v); 48*54386Storek } else { 49*54386Storek *eptr = 0; 50*54386Storek return ((double)0); 51*54386Storek } 52*54386Storek } 53