Back to index

glibc  2.9
ieee754.h
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _IEEE754_H
00020 
00021 #define _IEEE754_H 1
00022 #include <features.h>
00023 
00024 #include <endian.h>
00025 
00026 __BEGIN_DECLS
00027 
00028 union ieee754_float
00029   {
00030     float f;
00031 
00032     /* This is the IEEE 754 single-precision format.  */
00033     struct
00034       {
00035 #if    __BYTE_ORDER == __BIG_ENDIAN
00036        unsigned int negative:1;
00037        unsigned int exponent:8;
00038        unsigned int mantissa:23;
00039 #endif                      /* Big endian.  */
00040 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00041        unsigned int mantissa:23;
00042        unsigned int exponent:8;
00043        unsigned int negative:1;
00044 #endif                      /* Little endian.  */
00045       } ieee;
00046 
00047     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00048     struct
00049       {
00050 #if    __BYTE_ORDER == __BIG_ENDIAN
00051        unsigned int negative:1;
00052        unsigned int exponent:8;
00053        unsigned int quiet_nan:1;
00054        unsigned int mantissa:22;
00055 #endif                      /* Big endian.  */
00056 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00057        unsigned int mantissa:22;
00058        unsigned int quiet_nan:1;
00059        unsigned int exponent:8;
00060        unsigned int negative:1;
00061 #endif                      /* Little endian.  */
00062       } ieee_nan;
00063   };
00064 
00065 #define IEEE754_FLOAT_BIAS  0x7f /* Added to exponent.  */
00066 
00067 
00068 union ieee754_double
00069   {
00070     double d;
00071 
00072     /* This is the IEEE 754 double-precision format.  */
00073     struct
00074       {
00075 #if    __BYTE_ORDER == __BIG_ENDIAN
00076        unsigned int negative:1;
00077        unsigned int exponent:11;
00078        /* Together these comprise the mantissa.  */
00079        unsigned int mantissa0:20;
00080        unsigned int mantissa1:32;
00081 #endif                      /* Big endian.  */
00082 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00083        /* Together these comprise the mantissa.  */
00084        unsigned int mantissa1:32;
00085        unsigned int mantissa0:20;
00086        unsigned int exponent:11;
00087        unsigned int negative:1;
00088 #endif                      /* Little endian.  */
00089       } ieee;
00090 
00091     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00092     struct
00093       {
00094 #if    __BYTE_ORDER == __BIG_ENDIAN
00095        unsigned int negative:1;
00096        unsigned int exponent:11;
00097        unsigned int quiet_nan:1;
00098        /* Together these comprise the mantissa.  */
00099        unsigned int mantissa0:19;
00100        unsigned int mantissa1:32;
00101 #else
00102        /* Together these comprise the mantissa.  */
00103        unsigned int mantissa1:32;
00104        unsigned int mantissa0:19;
00105        unsigned int quiet_nan:1;
00106        unsigned int exponent:11;
00107        unsigned int negative:1;
00108 #endif
00109       } ieee_nan;
00110   };
00111 
00112 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent.  */
00113 
00114 
00115 union ieee854_long_double
00116   {
00117     long double d;
00118 
00119     /* This is the IEEE 854 quad-precision format.  */
00120     struct
00121       {
00122 #if    __BYTE_ORDER == __BIG_ENDIAN
00123        unsigned int negative:1;
00124        unsigned int exponent:15;
00125        /* Together these comprise the mantissa.  */
00126        unsigned int mantissa0:16;
00127        unsigned int mantissa1:32;
00128        unsigned int mantissa2:32;
00129        unsigned int mantissa3:32;
00130 #endif                      /* Big endian.  */
00131 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00132        /* Together these comprise the mantissa.  */
00133        unsigned int mantissa3:32;
00134        unsigned int mantissa2:32;
00135        unsigned int mantissa1:32;
00136        unsigned int mantissa0:16;
00137        unsigned int exponent:15;
00138        unsigned int negative:1;
00139 #endif                      /* Little endian.  */
00140       } ieee;
00141 
00142     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00143     struct
00144       {
00145 #if    __BYTE_ORDER == __BIG_ENDIAN
00146        unsigned int negative:1;
00147        unsigned int exponent:15;
00148        unsigned int quiet_nan:1;
00149        /* Together these comprise the mantissa.  */
00150        unsigned int mantissa0:15;
00151        unsigned int mantissa1:32;
00152        unsigned int mantissa2:32;
00153        unsigned int mantissa3:32;
00154 #else
00155        /* Together these comprise the mantissa.  */
00156        unsigned int mantissa3:32;
00157        unsigned int mantissa2:32;
00158        unsigned int mantissa1:32;
00159        unsigned int mantissa0:15;
00160        unsigned int quiet_nan:1;
00161        unsigned int exponent:15;
00162        unsigned int negative:1;
00163 #endif
00164       } ieee_nan;
00165   };
00166 
00167 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff /* Added to exponent.  */
00168 
00169 __END_DECLS
00170 
00171 #endif /* ieee754.h */