166458Sdfr/* $FreeBSD$ */ 266458Sdfr/* From: NetBSD: ieee.h,v 1.2 1997/04/06 08:47:27 cgd Exp */ 366458Sdfr 4139790Simp/*- 566458Sdfr * Copyright (c) 1992, 1993 666458Sdfr * The Regents of the University of California. All rights reserved. 766458Sdfr * 866458Sdfr * This software was developed by the Computer Systems Engineering group 966458Sdfr * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 1066458Sdfr * contributed to Berkeley. 1166458Sdfr * 1266458Sdfr * Redistribution and use in source and binary forms, with or without 1366458Sdfr * modification, are permitted provided that the following conditions 1466458Sdfr * are met: 1566458Sdfr * 1. Redistributions of source code must retain the above copyright 1666458Sdfr * notice, this list of conditions and the following disclaimer. 1766458Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1866458Sdfr * notice, this list of conditions and the following disclaimer in the 1966458Sdfr * documentation and/or other materials provided with the distribution. 2066458Sdfr * 4. Neither the name of the University nor the names of its contributors 2166458Sdfr * may be used to endorse or promote products derived from this software 2266458Sdfr * without specific prior written permission. 2366458Sdfr * 2466458Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2566458Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2666458Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2766458Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2866458Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2966458Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3066458Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3166458Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3266458Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3366458Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3466458Sdfr * SUCH DAMAGE. 3566458Sdfr * 3666458Sdfr * @(#)ieee.h 8.1 (Berkeley) 6/11/93 3766458Sdfr * 3866458Sdfr * from: Header: ieee.h,v 1.7 92/11/26 02:04:37 torek Exp 3966458Sdfr */ 4066458Sdfr 4166458Sdfr/* 4266458Sdfr * ieee.h defines the machine-dependent layout of the machine's IEEE 4366458Sdfr * floating point. It does *not* define (yet?) any of the rounding 4466458Sdfr * mode bits, exceptions, and so forth. 4566458Sdfr */ 4666458Sdfr 4766458Sdfr/* 4866458Sdfr * Define the number of bits in each fraction and exponent. 4966458Sdfr * 5066458Sdfr * k k+1 5166458Sdfr * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented 5266458Sdfr * 5366458Sdfr * (-exp_bias+1) 5466458Sdfr * as fractions that look like 0.fffff x 2 . This means that 5566458Sdfr * 5666458Sdfr * -126 5766458Sdfr * the number 0.10000 x 2 , for instance, is the same as the normalized 5866458Sdfr * 5966458Sdfr * -127 -128 6066458Sdfr * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero 6166458Sdfr * 6266458Sdfr * -129 6366458Sdfr * in the fraction; to represent 2 , we need two, and so on. This 6466458Sdfr * 6566458Sdfr * (-exp_bias-fracbits+1) 6666458Sdfr * implies that the smallest denormalized number is 2 6766458Sdfr * 6866458Sdfr * for whichever format we are talking about: for single precision, for 6966458Sdfr * 7066458Sdfr * -126 -149 7166458Sdfr * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and 7266458Sdfr * 7366458Sdfr * -149 == -127 - 23 + 1. 7466458Sdfr */ 7566458Sdfr#define SNG_EXPBITS 8 7666458Sdfr#define SNG_FRACBITS 23 7766458Sdfr 7866458Sdfr#define DBL_EXPBITS 11 7966458Sdfr#define DBL_FRACBITS 52 8066458Sdfr 8166458Sdfrstruct ieee_single { 8266458Sdfr u_int sng_frac:23; 8366458Sdfr u_int sng_exp:8; 8466458Sdfr u_int sng_sign:1; 8566458Sdfr}; 8666458Sdfr 8766458Sdfrstruct ieee_double { 8866458Sdfr u_int dbl_fracl; 8966458Sdfr u_int dbl_frach:20; 9066458Sdfr u_int dbl_exp:11; 9166458Sdfr u_int dbl_sign:1; 9266458Sdfr}; 9366458Sdfr 9466458Sdfr/* 9566458Sdfr * Floats whose exponent is in [1..INFNAN) (of whatever type) are 9666458Sdfr * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. 9766458Sdfr * Floats whose exponent is zero are either zero (iff all fraction 9866458Sdfr * bits are zero) or subnormal values. 9966458Sdfr * 10066458Sdfr * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its 10166458Sdfr * high fraction; if the bit is set, it is a `quiet NaN'. 10266458Sdfr */ 10366458Sdfr#define SNG_EXP_INFNAN 255 10466458Sdfr#define DBL_EXP_INFNAN 2047 10566458Sdfr 10666458Sdfr#if 0 10766458Sdfr#define SNG_QUIETNAN (1 << 22) 10866458Sdfr#define DBL_QUIETNAN (1 << 19) 10966458Sdfr#endif 11066458Sdfr 11166458Sdfr/* 11266458Sdfr * Exponent biases. 11366458Sdfr */ 11466458Sdfr#define SNG_EXP_BIAS 127 11566458Sdfr#define DBL_EXP_BIAS 1023 116