1 /*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)frexp.c 8.1 (Berkeley) 06/04/93"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/types.h> 13 #include <machine/endian.h> 14 #include <math.h> 15 16 double 17 frexp(value, eptr) 18 double value; 19 int *eptr; 20 { 21 union { 22 double v; 23 struct { 24 #if BYTE_ORDER == LITTLE_ENDIAN 25 u_int u_mant2 : 32; 26 u_int u_mant1 : 20; 27 u_int u_exp : 11; 28 u_int u_sign : 1; 29 #else 30 u_int u_sign : 1; 31 u_int u_exp : 11; 32 u_int u_mant1 : 20; 33 u_int u_mant2 : 32; 34 #endif 35 } s; 36 } u; 37 38 if (value) { 39 u.v = value; 40 *eptr = u.s.u_exp - 1022; 41 u.s.u_exp = 1022; 42 return(u.v); 43 } else { 44 *eptr = 0; 45 return((double)0); 46 } 47 } 48