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