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