ieee.h revision 1.3
11.3Sagc/* $NetBSD: ieee.h,v 1.3 2003/08/07 16:29:39 agc Exp $ */ 21.2Sderaadt 31.1Sderaadt/* 41.1Sderaadt * Copyright (c) 1992, 1993 51.1Sderaadt * The Regents of the University of California. All rights reserved. 61.1Sderaadt * 71.1Sderaadt * This software was developed by the Computer Systems Engineering group 81.1Sderaadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 91.1Sderaadt * contributed to Berkeley. 101.1Sderaadt * 111.1Sderaadt * All advertising materials mentioning features or use of this software 121.1Sderaadt * must display the following acknowledgement: 131.1Sderaadt * This product includes software developed by the University of 141.1Sderaadt * California, Lawrence Berkeley Laboratory. 151.1Sderaadt * 161.1Sderaadt * Redistribution and use in source and binary forms, with or without 171.1Sderaadt * modification, are permitted provided that the following conditions 181.1Sderaadt * are met: 191.1Sderaadt * 1. Redistributions of source code must retain the above copyright 201.1Sderaadt * notice, this list of conditions and the following disclaimer. 211.1Sderaadt * 2. Redistributions in binary form must reproduce the above copyright 221.1Sderaadt * notice, this list of conditions and the following disclaimer in the 231.1Sderaadt * documentation and/or other materials provided with the distribution. 241.3Sagc * 3. Neither the name of the University nor the names of its contributors 251.1Sderaadt * may be used to endorse or promote products derived from this software 261.1Sderaadt * without specific prior written permission. 271.1Sderaadt * 281.1Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 291.1Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 301.1Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 311.1Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 321.1Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 331.1Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 341.1Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 351.1Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 361.1Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 371.1Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 381.1Sderaadt * SUCH DAMAGE. 391.1Sderaadt * 401.1Sderaadt * @(#)ieee.h 8.1 (Berkeley) 6/11/93 411.1Sderaadt */ 421.1Sderaadt 431.1Sderaadt/* 441.1Sderaadt * ieee.h defines the machine-dependent layout of the machine's IEEE 451.1Sderaadt * floating point. It does *not* define (yet?) any of the rounding 461.1Sderaadt * mode bits, exceptions, and so forth. 471.1Sderaadt */ 481.1Sderaadt 491.1Sderaadt/* 501.1Sderaadt * Define the number of bits in each fraction and exponent. 511.1Sderaadt * 521.1Sderaadt * k k+1 531.1Sderaadt * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented 541.1Sderaadt * 551.1Sderaadt * (-exp_bias+1) 561.1Sderaadt * as fractions that look like 0.fffff x 2 . This means that 571.1Sderaadt * 581.1Sderaadt * -126 591.1Sderaadt * the number 0.10000 x 2 , for instance, is the same as the normalized 601.1Sderaadt * 611.1Sderaadt * -127 -128 621.1Sderaadt * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero 631.1Sderaadt * 641.1Sderaadt * -129 651.1Sderaadt * in the fraction; to represent 2 , we need two, and so on. This 661.1Sderaadt * 671.1Sderaadt * (-exp_bias-fracbits+1) 681.1Sderaadt * implies that the smallest denormalized number is 2 691.1Sderaadt * 701.1Sderaadt * for whichever format we are talking about: for single precision, for 711.1Sderaadt * 721.1Sderaadt * -126 -149 731.1Sderaadt * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and 741.1Sderaadt * 751.1Sderaadt * -149 == -127 - 23 + 1. 761.1Sderaadt */ 771.1Sderaadt#define SNG_EXPBITS 8 781.1Sderaadt#define SNG_FRACBITS 23 791.1Sderaadt 801.1Sderaadt#define DBL_EXPBITS 11 811.1Sderaadt#define DBL_FRACBITS 52 821.1Sderaadt 831.1Sderaadt#ifdef notyet 841.1Sderaadt#define E80_EXPBITS 15 851.1Sderaadt#define E80_FRACBITS 64 861.1Sderaadt#endif 871.1Sderaadt 881.1Sderaadt#define EXT_EXPBITS 15 891.1Sderaadt#define EXT_FRACBITS 112 901.1Sderaadt 911.1Sderaadtstruct ieee_single { 921.1Sderaadt u_int sng_sign:1; 931.1Sderaadt u_int sng_exp:8; 941.1Sderaadt u_int sng_frac:23; 951.1Sderaadt}; 961.1Sderaadt 971.1Sderaadtstruct ieee_double { 981.1Sderaadt u_int dbl_sign:1; 991.1Sderaadt u_int dbl_exp:11; 1001.1Sderaadt u_int dbl_frach:20; 1011.1Sderaadt u_int dbl_fracl; 1021.1Sderaadt}; 1031.1Sderaadt 1041.1Sderaadtstruct ieee_ext { 1051.1Sderaadt u_int ext_sign:1; 1061.1Sderaadt u_int ext_exp:15; 1071.1Sderaadt u_int ext_frach:16; 1081.1Sderaadt u_int ext_frachm; 1091.1Sderaadt u_int ext_fraclm; 1101.1Sderaadt u_int ext_fracl; 1111.1Sderaadt}; 1121.1Sderaadt 1131.1Sderaadt/* 1141.1Sderaadt * Floats whose exponent is in [1..INFNAN) (of whatever type) are 1151.1Sderaadt * `normal'. Floats whose exponent is INFNAN are either Inf or NaN. 1161.1Sderaadt * Floats whose exponent is zero are either zero (iff all fraction 1171.1Sderaadt * bits are zero) or subnormal values. 1181.1Sderaadt * 1191.1Sderaadt * A NaN is a `signalling NaN' if its QUIETNAN bit is clear in its 1201.1Sderaadt * high fraction; if the bit is set, it is a `quiet NaN'. 1211.1Sderaadt */ 1221.1Sderaadt#define SNG_EXP_INFNAN 255 1231.1Sderaadt#define DBL_EXP_INFNAN 2047 1241.1Sderaadt#define EXT_EXP_INFNAN 32767 1251.1Sderaadt 1261.1Sderaadt#if 0 1271.1Sderaadt#define SNG_QUIETNAN (1 << 22) 1281.1Sderaadt#define DBL_QUIETNAN (1 << 19) 1291.1Sderaadt#define EXT_QUIETNAN (1 << 15) 1301.1Sderaadt#endif 1311.1Sderaadt 1321.1Sderaadt/* 1331.1Sderaadt * Exponent biases. 1341.1Sderaadt */ 1351.1Sderaadt#define SNG_EXP_BIAS 127 1361.1Sderaadt#define DBL_EXP_BIAS 1023 1371.1Sderaadt#define EXT_EXP_BIAS 16383 138