xref: /csrg-svn/lib/libc/tahoe/gen/frexp.c (revision 61183)
147049Sbostic /*-
2*61183Sbostic  * Copyright (c) 1991, 1993
3*61183Sbostic  *	The Regents of the University of California.  All rights reserved.
447049Sbostic  *
547049Sbostic  * %sccs.include.redist.c%
647049Sbostic  */
747049Sbostic 
847049Sbostic #if defined(LIBC_SCCS) && !defined(lint)
9*61183Sbostic static char sccsid[] = "@(#)frexp.c	8.1 (Berkeley) 06/04/93";
1047049Sbostic #endif /* LIBC_SCCS and not lint */
1147049Sbostic 
1247049Sbostic #include <sys/types.h>
1347049Sbostic #include <math.h>
1447049Sbostic 
1547049Sbostic double
frexp(value,eptr)1647049Sbostic frexp(value, eptr)
1747049Sbostic 	double value;
1847049Sbostic 	int *eptr;
1947049Sbostic {
2047049Sbostic 	union {
2147049Sbostic                 double v;
2247049Sbostic                 struct {
2347049Sbostic                         u_int  u_sign :  1;
2447049Sbostic 			u_int   u_exp :  8;
2547049Sbostic 			u_int u_mant1 : 23;
2647049Sbostic 			u_int u_mant2 : 32;
2747049Sbostic                 } s;
2847049Sbostic         } u;
2947049Sbostic 
3047049Sbostic 	if (value) {
3147049Sbostic 		u.v = value;
3247049Sbostic 		*eptr = u.s.u_exp - 128;
3347049Sbostic 		u.s.u_exp = 128;
3447049Sbostic 		return(u.v);
3547049Sbostic 	} else {
3647049Sbostic 		*eptr = 0;
3747049Sbostic 		return((double)0);
3847049Sbostic 	}
3947049Sbostic }
40