]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /* $NetBSD: ieee754.h,v 1.6.24.1 2007/05/07 19:49:10 pavel Exp $ */\r |
2 | \r | |
3 | /*\r | |
4 | * Copyright (c) 1992, 1993\r | |
5 | * The Regents of the University of California. All rights reserved.\r | |
6 | *\r | |
7 | * This software was developed by the Computer Systems Engineering group\r | |
8 | * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and\r | |
9 | * contributed to Berkeley.\r | |
10 | *\r | |
11 | * All advertising materials mentioning features or use of this software\r | |
12 | * must display the following acknowledgement:\r | |
13 | * This product includes software developed by the University of\r | |
14 | * California, Lawrence Berkeley Laboratory.\r | |
15 | *\r | |
16 | * Redistribution and use in source and binary forms, with or without\r | |
17 | * modification, are permitted provided that the following conditions\r | |
18 | * are met:\r | |
19 | * 1. Redistributions of source code must retain the above copyright\r | |
20 | * notice, this list of conditions and the following disclaimer.\r | |
21 | * 2. Redistributions in binary form must reproduce the above copyright\r | |
22 | * notice, this list of conditions and the following disclaimer in the\r | |
23 | * documentation and/or other materials provided with the distribution.\r | |
24 | * 3. Neither the name of the University nor the names of its contributors\r | |
25 | * may be used to endorse or promote products derived from this software\r | |
26 | * without specific prior written permission.\r | |
27 | *\r | |
28 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r | |
29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r | |
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r | |
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r | |
34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r | |
36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r | |
37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r | |
38 | * SUCH DAMAGE.\r | |
39 | *\r | |
40 | * @(#)ieee.h 8.1 (Berkeley) 6/11/93\r | |
41 | */\r | |
42 | #ifndef _SYS_IEEE754_H_\r | |
43 | #define _SYS_IEEE754_H_\r | |
44 | \r | |
45 | /*\r | |
46 | * NOTICE: This is not a standalone file. To use it, #include it in\r | |
47 | * your port's ieee.h header.\r | |
48 | */\r | |
49 | \r | |
50 | #include <machine/endian.h>\r | |
51 | \r | |
52 | /*\r | |
53 | * <sys/ieee754.h> defines the layout of IEEE 754 floating point types.\r | |
54 | * Only single-precision and double-precision types are defined here;\r | |
55 | * extended types, if available, are defined in the machine-dependent\r | |
56 | * header.\r | |
57 | */\r | |
58 | \r | |
59 | /*\r | |
60 | * Define the number of bits in each fraction and exponent.\r | |
61 | *\r | |
62 | * k k+1\r | |
63 | * Note that 1.0 x 2 == 0.1 x 2 and that denorms are represented\r | |
64 | *\r | |
65 | * (-exp_bias+1)\r | |
66 | * as fractions that look like 0.fffff x 2 . This means that\r | |
67 | *\r | |
68 | * -126\r | |
69 | * the number 0.10000 x 2 , for instance, is the same as the normalized\r | |
70 | *\r | |
71 | * -127 -128\r | |
72 | * float 1.0 x 2 . Thus, to represent 2 , we need one leading zero\r | |
73 | *\r | |
74 | * -129\r | |
75 | * in the fraction; to represent 2 , we need two, and so on. This\r | |
76 | *\r | |
77 | * (-exp_bias-fracbits+1)\r | |
78 | * implies that the smallest denormalized number is 2\r | |
79 | *\r | |
80 | * for whichever format we are talking about: for single precision, for\r | |
81 | *\r | |
82 | * -126 -149\r | |
83 | * instance, we get .00000000000000000000001 x 2 , or 1.0 x 2 , and\r | |
84 | *\r | |
85 | * -149 == -127 - 23 + 1.\r | |
86 | */\r | |
87 | #define SNG_EXPBITS 8\r | |
88 | #define SNG_FRACBITS 23\r | |
89 | \r | |
90 | struct ieee_single {\r | |
91 | #if _BYTE_ORDER == _BIG_ENDIAN\r | |
92 | u_int sng_sign:1;\r | |
93 | u_int sng_exp:SNG_EXPBITS;\r | |
94 | u_int sng_frac:SNG_FRACBITS;\r | |
95 | #else\r | |
96 | u_int sng_frac:SNG_FRACBITS;\r | |
97 | u_int sng_exp:SNG_EXPBITS;\r | |
98 | u_int sng_sign:1;\r | |
99 | #endif\r | |
100 | };\r | |
101 | \r | |
102 | #define DBL_EXPBITS 11\r | |
103 | #define DBL_FRACHBITS 20\r | |
104 | #define DBL_FRACLBITS 32\r | |
105 | #define DBL_FRACBITS (DBL_FRACHBITS + DBL_FRACLBITS)\r | |
106 | \r | |
107 | struct ieee_double {\r | |
108 | #if _BYTE_ORDER == _BIG_ENDIAN\r | |
109 | u_int dbl_sign:1;\r | |
110 | u_int dbl_exp:DBL_EXPBITS;\r | |
111 | u_int dbl_frach:DBL_FRACHBITS;\r | |
112 | u_int dbl_fracl:DBL_FRACLBITS;\r | |
113 | #else\r | |
114 | u_int dbl_fracl:DBL_FRACLBITS;\r | |
115 | u_int dbl_frach:DBL_FRACHBITS;\r | |
116 | u_int dbl_exp:DBL_EXPBITS;\r | |
117 | u_int dbl_sign:1;\r | |
118 | #endif\r | |
119 | };\r | |
120 | \r | |
121 | /*\r | |
122 | * Floats whose exponent is in [1..INFNAN) (of whatever type) are\r | |
123 | * `normal'. Floats whose exponent is INFNAN are either Inf or NaN.\r | |
124 | * Floats whose exponent is zero are either zero (iff all fraction\r | |
125 | * bits are zero) or subnormal values.\r | |
126 | *\r | |
127 | * At least one `signalling NaN' and one `quiet NaN' value must be\r | |
128 | * implemented. It is left to the architecture to specify how to\r | |
129 | * distinguish between these.\r | |
130 | */\r | |
131 | #define SNG_EXP_INFNAN 255\r | |
132 | #define DBL_EXP_INFNAN 2047\r | |
133 | \r | |
134 | /*\r | |
135 | * Exponent biases.\r | |
136 | */\r | |
137 | #define SNG_EXP_BIAS 127\r | |
138 | #define DBL_EXP_BIAS 1023\r | |
139 | \r | |
140 | /*\r | |
141 | * Convenience data structures.\r | |
142 | */\r | |
143 | union ieee_single_u {\r | |
144 | float sngu_f;\r | |
145 | struct ieee_single sngu_sng;\r | |
146 | };\r | |
147 | \r | |
148 | union ieee_double_u {\r | |
149 | double dblu_d;\r | |
150 | struct ieee_double dblu_dbl;\r | |
151 | };\r | |
152 | #endif /* _SYS_IEEE754_H_ */\r |