xref: /csrg-svn/lib/libc/mips/gen/frexp.c (revision 61141)
154521Sbostic /*-
2*61141Sbostic  * Copyright (c) 1991, 1993
3*61141Sbostic  *	The Regents of the University of California.  All rights reserved.
454521Sbostic  *
554521Sbostic  * %sccs.include.redist.c%
654521Sbostic  */
754521Sbostic 
854521Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*61141Sbostic static char sccsid[] = "@(#)frexp.c	8.1 (Berkeley) 06/04/93";
1054521Sbostic #endif /* LIBC_SCCS and not lint */
1154521Sbostic 
1254521Sbostic #include <sys/types.h>
1354521Sbostic #include <machine/endian.h>
1454521Sbostic #include <math.h>
1554521Sbostic 
1654521Sbostic double
frexp(value,eptr)1754521Sbostic frexp(value, eptr)
1854521Sbostic 	double value;
1954521Sbostic 	int *eptr;
2054521Sbostic {
2154521Sbostic 	union {
2254521Sbostic                 double v;
2354521Sbostic                 struct {
2454521Sbostic #if BYTE_ORDER == LITTLE_ENDIAN
2554521Sbostic 			u_int u_mant2 : 32;
2654521Sbostic 			u_int u_mant1 : 20;
2754521Sbostic 			u_int   u_exp : 11;
2854521Sbostic                         u_int  u_sign :  1;
2954521Sbostic #else
3054521Sbostic                         u_int  u_sign :  1;
3154521Sbostic 			u_int   u_exp : 11;
3254521Sbostic 			u_int u_mant1 : 20;
3354521Sbostic 			u_int u_mant2 : 32;
3454521Sbostic #endif
3554521Sbostic                 } s;
3654521Sbostic         } u;
3754521Sbostic 
3854521Sbostic 	if (value) {
3954521Sbostic 		u.v = value;
4054521Sbostic 		*eptr = u.s.u_exp - 1022;
4154521Sbostic 		u.s.u_exp = 1022;
4254521Sbostic 		return(u.v);
4354521Sbostic 	} else {
4454521Sbostic 		*eptr = 0;
4554521Sbostic 		return((double)0);
4654521Sbostic 	}
4754521Sbostic }
48