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