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