1*7b36286aSmartynas /* $OpenBSD: ieee.h,v 1.3 2008/09/07 20:36:07 martynas Exp $ */ 295c7671fSmiod 395c7671fSmiod /* 495c7671fSmiod * Copyright (c) 1992, 1993 595c7671fSmiod * The Regents of the University of California. All rights reserved. 695c7671fSmiod * 795c7671fSmiod * This software was developed by the Computer Systems Engineering group 895c7671fSmiod * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 995c7671fSmiod * contributed to Berkeley. 1095c7671fSmiod * 1195c7671fSmiod * All advertising materials mentioning features or use of this software 1295c7671fSmiod * must display the following acknowledgement: 1395c7671fSmiod * This product includes software developed by the University of 1495c7671fSmiod * California, Lawrence Berkeley Laboratory. 1595c7671fSmiod * 1695c7671fSmiod * Redistribution and use in source and binary forms, with or without 1795c7671fSmiod * modification, are permitted provided that the following conditions 1895c7671fSmiod * are met: 1995c7671fSmiod * 1. Redistributions of source code must retain the above copyright 2095c7671fSmiod * notice, this list of conditions and the following disclaimer. 2195c7671fSmiod * 2. Redistributions in binary form must reproduce the above copyright 2295c7671fSmiod * notice, this list of conditions and the following disclaimer in the 2395c7671fSmiod * documentation and/or other materials provided with the distribution. 2495c7671fSmiod * 3. Neither the name of the University nor the names of its contributors 2595c7671fSmiod * may be used to endorse or promote products derived from this software 2695c7671fSmiod * without specific prior written permission. 2795c7671fSmiod * 2895c7671fSmiod * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2995c7671fSmiod * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3095c7671fSmiod * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3195c7671fSmiod * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3295c7671fSmiod * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3395c7671fSmiod * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3495c7671fSmiod * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3595c7671fSmiod * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3695c7671fSmiod * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3795c7671fSmiod * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3895c7671fSmiod * SUCH DAMAGE. 3995c7671fSmiod * 4095c7671fSmiod * @(#)ieee.h 8.1 (Berkeley) 6/11/93 4195c7671fSmiod */ 4295c7671fSmiod 4395c7671fSmiod /* 4495c7671fSmiod * ieee.h defines the machine-dependent layout of the machine's IEEE 4595c7671fSmiod * floating point. It does *not* define (yet?) any of the rounding 4695c7671fSmiod * mode bits, exceptions, and so forth. 4795c7671fSmiod */ 4895c7671fSmiod 4995c7671fSmiod /* 5095c7671fSmiod * Define the number of bits in each fraction and exponent. 5195c7671fSmiod * 5295c7671fSmiod * k k+1 5395c7671fSmiod * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented 5495c7671fSmiod * 5595c7671fSmiod * (-exp_bias+1) 5695c7671fSmiod * as fractions that look like 0.fffff x 2 . This means that 5795c7671fSmiod * 5895c7671fSmiod * -126 5995c7671fSmiod * the number 0.10000 x 2 , for instance, is the same as the normalized 6095c7671fSmiod * 6195c7671fSmiod * -127 -128 6295c7671fSmiod * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero 6395c7671fSmiod * 6495c7671fSmiod * -129 6595c7671fSmiod * in the fraction; to represent 2 , we need two, and so on. This 6695c7671fSmiod * 6795c7671fSmiod * (-exp_bias-fracbits+1) 6895c7671fSmiod * implies that the smallest denormalized number is 2 6995c7671fSmiod * 7095c7671fSmiod * for whichever format we are talking about: for single precision, for 7195c7671fSmiod * 7295c7671fSmiod * -126 -149 7395c7671fSmiod * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and 7495c7671fSmiod * 7595c7671fSmiod * -149 == -127 - 23 + 1. 7695c7671fSmiod */ 7795c7671fSmiod #define SNG_EXPBITS 8 7895c7671fSmiod #define SNG_FRACBITS 23 7995c7671fSmiod 8095c7671fSmiod #define DBL_EXPBITS 11 81*7b36286aSmartynas #define DBL_FRACHBITS 20 82*7b36286aSmartynas #define DBL_FRACLBITS 32 8395c7671fSmiod #define DBL_FRACBITS 52 8495c7671fSmiod 8595c7671fSmiod struct ieee_single { 8695c7671fSmiod u_int sng_frac:23; 874f0dcf5aSotto u_int sng_exp:8; 884f0dcf5aSotto u_int sng_sign:1; 8995c7671fSmiod }; 9095c7671fSmiod 9195c7671fSmiod struct ieee_double { 9295c7671fSmiod u_int dbl_fracl; 934f0dcf5aSotto u_int dbl_frach:20; 944f0dcf5aSotto u_int dbl_exp:11; 954f0dcf5aSotto u_int dbl_sign:1; 9695c7671fSmiod }; 9795c7671fSmiod 9895c7671fSmiod /* 9995c7671fSmiod * Floats whose exponent is in [1..INFNAN) (of whatever type) are 10095c7671fSmiod * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. 10195c7671fSmiod * Floats whose exponent is zero are either zero (iff all fraction 10295c7671fSmiod * bits are zero) or subnormal values. 10395c7671fSmiod * 10495c7671fSmiod * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its 10595c7671fSmiod * high fraction; if the bit is set, it is a `quiet NaN'. 10695c7671fSmiod */ 10795c7671fSmiod #define SNG_EXP_INFNAN 255 10895c7671fSmiod #define DBL_EXP_INFNAN 2047 10995c7671fSmiod 11095c7671fSmiod #if 0 11195c7671fSmiod #define SNG_QUIETNAN (1 << 22) 11295c7671fSmiod #define DBL_QUIETNAN (1 << 19) 11395c7671fSmiod #endif 11495c7671fSmiod 11595c7671fSmiod /* 11695c7671fSmiod * Exponent biases. 11795c7671fSmiod */ 11895c7671fSmiod #define SNG_EXP_BIAS 127 11995c7671fSmiod #define DBL_EXP_BIAS 1023 120