xref: /original-bsd/lib/libc/i386/gen/frexp.c (revision c3e32dec)
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 <math.h>
14 
15 double
16 frexp(value, eptr)
17 	double value;
18 	int *eptr;
19 {
20 	union {
21                 double v;
22                 struct {
23 			u_int u_mant2 : 32;
24 			u_int u_mant1 : 20;
25 			u_int   u_exp : 11;
26                         u_int  u_sign :  1;
27                 } s;
28         } u;
29 
30 	if (value) {
31 		u.v = value;
32 		*eptr = u.s.u_exp - 1022;
33 		u.s.u_exp = 1022;
34 		return(u.v);
35 	} else {
36 		*eptr = 0;
37 		return((double)0);
38 	}
39 }
40