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