frexp.c revision 1.2
11.2Schristos/* $NetBSD: frexp.c,v 1.2 1997/07/13 18:45:44 christos 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.1Sragge * 3. All advertising materials mentioning features or use of this software 161.1Sragge * must display the following acknowledgement: 171.1Sragge * This product includes software developed by the University of 181.1Sragge * California, Berkeley and its contributors. 191.1Sragge * 4. Neither the name of the University nor the names of its contributors 201.1Sragge * may be used to endorse or promote products derived from this software 211.1Sragge * without specific prior written permission. 221.1Sragge * 231.1Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241.1Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251.1Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261.1Sragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271.1Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281.1Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291.1Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.1Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.1Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.1Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.1Sragge * SUCH DAMAGE. 341.1Sragge */ 351.1Sragge 361.2Schristos#include <sys/cdefs.h> 371.1Sragge#if defined(LIBC_SCCS) && !defined(lint) 381.2Schristos#if 0 391.2Schristosstatic char sccsid[] = "@(#)frexp.c 8.1 (Berkeley) 6/4/93"; 401.2Schristos#else 411.2Schristos__RCSID("$NetBSD: frexp.c,v 1.2 1997/07/13 18:45:44 christos Exp $"); 421.2Schristos#endif 431.1Sragge#endif /* LIBC_SCCS and not lint */ 441.1Sragge 451.1Sragge#include <sys/types.h> 461.1Sragge#include <math.h> 471.1Sragge 481.1Sraggedouble 491.1Sraggefrexp(value, eptr) 501.1Sragge double value; 511.1Sragge int *eptr; 521.1Sragge{ 531.1Sragge union { 541.1Sragge double v; 551.1Sragge struct { 561.1Sragge u_int u_mant1 : 7; 571.1Sragge u_int u_exp : 8; 581.1Sragge u_int u_sign : 1; 591.1Sragge u_int u_mant2 : 16; 601.1Sragge u_int u_mant3 : 32; 611.1Sragge } s; 621.1Sragge } u; 631.1Sragge 641.1Sragge if (value) { 651.1Sragge u.v = value; 661.1Sragge *eptr = u.s.u_exp - 128; 671.1Sragge u.s.u_exp = 128; 681.1Sragge return(u.v); 691.1Sragge } else { 701.1Sragge *eptr = 0; 711.1Sragge return((double)0); 721.1Sragge } 731.1Sragge} 74