frexp.c revision 1.4
11.4Sagc/*	$NetBSD: frexp.c,v 1.4 2003/08/07 16:42:31 agc Exp $	*/
21.2Schristos
31.1Sragge/*-
41.1Sragge * Copyright (c) 1991, 1993
51.1Sragge *	The Regents of the University of California.  All rights reserved.
61.1Sragge *
71.1Sragge * Redistribution and use in source and binary forms, with or without
81.1Sragge * modification, are permitted provided that the following conditions
91.1Sragge * are met:
101.1Sragge * 1. Redistributions of source code must retain the above copyright
111.1Sragge *    notice, this list of conditions and the following disclaimer.
121.1Sragge * 2. Redistributions in binary form must reproduce the above copyright
131.1Sragge *    notice, this list of conditions and the following disclaimer in the
141.1Sragge *    documentation and/or other materials provided with the distribution.
151.4Sagc * 3. Neither the name of the University nor the names of its contributors
161.1Sragge *    may be used to endorse or promote products derived from this software
171.1Sragge *    without specific prior written permission.
181.1Sragge *
191.1Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.1Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.1Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.1Sragge * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.1Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.1Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.1Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.1Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.1Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.1Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.1Sragge * SUCH DAMAGE.
301.1Sragge */
311.1Sragge
321.2Schristos#include <sys/cdefs.h>
331.1Sragge#if defined(LIBC_SCCS) && !defined(lint)
341.2Schristos#if 0
351.2Schristosstatic char sccsid[] = "@(#)frexp.c	8.1 (Berkeley) 6/4/93";
361.2Schristos#else
371.4Sagc__RCSID("$NetBSD: frexp.c,v 1.4 2003/08/07 16:42:31 agc Exp $");
381.2Schristos#endif
391.1Sragge#endif /* LIBC_SCCS and not lint */
401.1Sragge
411.1Sragge#include <sys/types.h>
421.1Sragge#include <math.h>
431.1Sragge
441.1Sraggedouble
451.1Sraggefrexp(value, eptr)
461.1Sragge	double value;
471.1Sragge	int *eptr;
481.1Sragge{
491.1Sragge	union {
501.1Sragge                double v;
511.1Sragge                struct {
521.1Sragge			u_int u_mant1 :  7;
531.1Sragge			u_int   u_exp :  8;
541.1Sragge			u_int  u_sign :  1;
551.1Sragge			u_int u_mant2 : 16;
561.1Sragge			u_int u_mant3 : 32;
571.1Sragge                } s;
581.1Sragge        } u;
591.1Sragge
601.1Sragge	if (value) {
611.1Sragge		u.v = value;
621.1Sragge		*eptr = u.s.u_exp - 128;
631.1Sragge		u.s.u_exp = 128;
641.3Smycroft		return (u.v);
651.1Sragge	} else {
661.1Sragge		*eptr = 0;
671.3Smycroft		return (0.0);
681.1Sragge	}
691.1Sragge}
70