xref: /csrg-svn/lib/libc/i386/gen/frexp.c (revision 47052)
1*47052Sbostic /*-
2*47052Sbostic  * Copyright (c) 1991 The Regents of the University of California.
3*47052Sbostic  * All rights reserved.
4*47052Sbostic  *
5*47052Sbostic  * %sccs.include.redist.c%
6*47052Sbostic  */
7*47052Sbostic 
8*47052Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*47052Sbostic static char sccsid[] = "@(#)frexp.c	5.1 (Berkeley) 03/07/91";
10*47052Sbostic #endif /* LIBC_SCCS and not lint */
11*47052Sbostic 
12*47052Sbostic #include <sys/types.h>
13*47052Sbostic #include <math.h>
14*47052Sbostic 
15*47052Sbostic double
16*47052Sbostic frexp(value, eptr)
17*47052Sbostic 	double value;
18*47052Sbostic 	int *eptr;
19*47052Sbostic {
20*47052Sbostic 	union {
21*47052Sbostic                 double v;
22*47052Sbostic                 struct {
23*47052Sbostic 			u_int u_mant2 : 32;
24*47052Sbostic 			u_int u_mant1 : 20;
25*47052Sbostic 			u_int   u_exp : 11;
26*47052Sbostic                         u_int  u_sign :  1;
27*47052Sbostic                 } s;
28*47052Sbostic         } u;
29*47052Sbostic 
30*47052Sbostic 	if (value) {
31*47052Sbostic 		u.v = value;
32*47052Sbostic 		*eptr = u.s.u_exp - 1022;
33*47052Sbostic 		u.s.u_exp = 1022;
34*47052Sbostic 		return(u.v);
35*47052Sbostic 	} else {
36*47052Sbostic 		*eptr = 0;
37*47052Sbostic 		return((double)0);
38*47052Sbostic 	}
39*47052Sbostic }
40