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