ieee754.h
001: 
002: 
003: 
004: 
005: 
006: 
007: 
008: 
009: 
010: 
011: 
012: 
013: 
014: 
015: 
016: 
017: 
018: 
019: #ifndef _IEEE754_H
020: 
021: #define _IEEE754_H 1
022: #include <features.h>
023: 
024: #include <endian.h>
025: 
026: __BEGIN_DECLS
027: 
028: union ieee754_float
029:   {
030:     float f;
031: 
032:     
033:     struct
034:       {
035: #if     __BYTE_ORDER == __BIG_ENDIAN
036:         unsigned int negative:1;
037:         unsigned int exponent:8;
038:         unsigned int mantissa:23;
039: #endif                          
040: #if     __BYTE_ORDER == __LITTLE_ENDIAN
041:         unsigned int mantissa:23;
042:         unsigned int exponent:8;
043:         unsigned int negative:1;
044: #endif                          
045:       } ieee;
046: 
047:     
048:     struct
049:       {
050: #if     __BYTE_ORDER == __BIG_ENDIAN
051:         unsigned int negative:1;
052:         unsigned int exponent:8;
053:         unsigned int quiet_nan:1;
054:         unsigned int mantissa:22;
055: #endif                          
056: #if     __BYTE_ORDER == __LITTLE_ENDIAN
057:         unsigned int mantissa:22;
058:         unsigned int quiet_nan:1;
059:         unsigned int exponent:8;
060:         unsigned int negative:1;
061: #endif                          
062:       } ieee_nan;
063:   };
064: 
065: #define IEEE754_FLOAT_BIAS      0x7f 
066: 
067: 
068: union ieee754_double
069:   {
070:     double d;
071: 
072:     
073:     struct
074:       {
075: #if     __BYTE_ORDER == __BIG_ENDIAN
076:         unsigned int negative:1;
077:         unsigned int exponent:11;
078:         
079:         unsigned int mantissa0:20;
080:         unsigned int mantissa1:32;
081: #endif                          
082: #if     __BYTE_ORDER == __LITTLE_ENDIAN
083: # if    __FLOAT_WORD_ORDER == __BIG_ENDIAN
084:         unsigned int mantissa0:20;
085:         unsigned int exponent:11;
086:         unsigned int negative:1;
087:         unsigned int mantissa1:32;
088: # else
089:         
090:         unsigned int mantissa1:32;
091:         unsigned int mantissa0:20;
092:         unsigned int exponent:11;
093:         unsigned int negative:1;
094: # endif
095: #endif                          
096:       } ieee;
097: 
098:     
099:     struct
100:       {
101: #if     __BYTE_ORDER == __BIG_ENDIAN
102:         unsigned int negative:1;
103:         unsigned int exponent:11;
104:         unsigned int quiet_nan:1;
105:         
106:         unsigned int mantissa0:19;
107:         unsigned int mantissa1:32;
108: #else
109: # if    __FLOAT_WORD_ORDER == __BIG_ENDIAN
110:         unsigned int mantissa0:19;
111:         unsigned int quiet_nan:1;
112:         unsigned int exponent:11;
113:         unsigned int negative:1;
114:         unsigned int mantissa1:32;
115: # else
116:         
117:         unsigned int mantissa1:32;
118:         unsigned int mantissa0:19;
119:         unsigned int quiet_nan:1;
120:         unsigned int exponent:11;
121:         unsigned int negative:1;
122: # endif
123: #endif
124:       } ieee_nan;
125:   };
126: 
127: #define IEEE754_DOUBLE_BIAS     0x3ff 
128: 
129: 
130: union ieee854_long_double
131:   {
132:     long double d;
133: 
134:     
135:     struct
136:       {
137: #if     __BYTE_ORDER == __BIG_ENDIAN
138:         unsigned int negative:1;
139:         unsigned int exponent:15;
140:         unsigned int empty:16;
141:         unsigned int mantissa0:32;
142:         unsigned int mantissa1:32;
143: #endif
144: #if     __BYTE_ORDER == __LITTLE_ENDIAN
145: # if    __FLOAT_WORD_ORDER == __BIG_ENDIAN
146:         unsigned int exponent:15;
147:         unsigned int negative:1;
148:         unsigned int empty:16;
149:         unsigned int mantissa0:32;
150:         unsigned int mantissa1:32;
151: # else
152:         unsigned int mantissa1:32;
153:         unsigned int mantissa0:32;
154:         unsigned int exponent:15;
155:         unsigned int negative:1;
156:         unsigned int empty:16;
157: # endif
158: #endif
159:       } ieee;
160: 
161:     
162:     struct
163:       {
164: #if     __BYTE_ORDER == __BIG_ENDIAN
165:         unsigned int negative:1;
166:         unsigned int exponent:15;
167:         unsigned int empty:16;
168:         unsigned int one:1;
169:         unsigned int quiet_nan:1;
170:         unsigned int mantissa0:30;
171:         unsigned int mantissa1:32;
172: #endif
173: #if     __BYTE_ORDER == __LITTLE_ENDIAN
174: # if    __FLOAT_WORD_ORDER == __BIG_ENDIAN
175:         unsigned int exponent:15;
176:         unsigned int negative:1;
177:         unsigned int empty:16;
178:         unsigned int mantissa0:30;
179:         unsigned int quiet_nan:1;
180:         unsigned int one:1;
181:         unsigned int mantissa1:32;
182: # else
183:         unsigned int mantissa1:32;
184:         unsigned int mantissa0:30;
185:         unsigned int quiet_nan:1;
186:         unsigned int one:1;
187:         unsigned int exponent:15;
188:         unsigned int negative:1;
189:         unsigned int empty:16;
190: # endif
191: #endif
192:       } ieee_nan;
193:   };
194: 
195: #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
196: 
197: __END_DECLS
198: 
199: #endif 
200: 
      
      
      
      
   
      
      
         
            
            © Andrew Scott 2006 -
            2025, 
            All Rights Reserved