Back to index

glibc  2.9
ieee754.h
Go to the documentation of this file.
00001 /* Copyright (C) 1992, 1995, 1996, 1999, 2004, 2006
00002    Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _IEEE754_H
00021 
00022 #define _IEEE754_H 1
00023 #include <features.h>
00024 
00025 #include <endian.h>
00026 
00027 __BEGIN_DECLS
00028 
00029 union ieee754_float
00030   {
00031     float f;
00032 
00033     /* This is the IEEE 754 single-precision format.  */
00034     struct
00035       {
00036 #if    __BYTE_ORDER == __BIG_ENDIAN
00037        unsigned int negative:1;
00038        unsigned int exponent:8;
00039        unsigned int mantissa:23;
00040 #endif                      /* Big endian.  */
00041 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00042        unsigned int mantissa:23;
00043        unsigned int exponent:8;
00044        unsigned int negative:1;
00045 #endif                      /* Little endian.  */
00046       } ieee;
00047 
00048     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00049     struct
00050       {
00051 #if    __BYTE_ORDER == __BIG_ENDIAN
00052        unsigned int negative:1;
00053        unsigned int exponent:8;
00054        unsigned int quiet_nan:1;
00055        unsigned int mantissa:22;
00056 #endif                      /* Big endian.  */
00057 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00058        unsigned int mantissa:22;
00059        unsigned int quiet_nan:1;
00060        unsigned int exponent:8;
00061        unsigned int negative:1;
00062 #endif                      /* Little endian.  */
00063       } ieee_nan;
00064   };
00065 
00066 #define IEEE754_FLOAT_BIAS  0x7f /* Added to exponent.  */
00067 
00068 
00069 union ieee754_double
00070   {
00071     double d;
00072 
00073     /* This is the IEEE 754 double-precision format.  */
00074     struct
00075       {
00076 #if    __BYTE_ORDER == __BIG_ENDIAN
00077        unsigned int negative:1;
00078        unsigned int exponent:11;
00079        /* Together these comprise the mantissa.  */
00080        unsigned int mantissa0:20;
00081        unsigned int mantissa1:32;
00082 #endif                      /* Big endian.  */
00083 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00084        /* Together these comprise the mantissa.  */
00085        unsigned int mantissa1:32;
00086        unsigned int mantissa0:20;
00087        unsigned int exponent:11;
00088        unsigned int negative:1;
00089 #endif                      /* Little endian.  */
00090       } ieee;
00091 
00092     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00093     struct
00094       {
00095 #if    __BYTE_ORDER == __BIG_ENDIAN
00096        unsigned int negative:1;
00097        unsigned int exponent:11;
00098        unsigned int quiet_nan:1;
00099        /* Together these comprise the mantissa.  */
00100        unsigned int mantissa0:19;
00101        unsigned int mantissa1:32;
00102 #else
00103        /* Together these comprise the mantissa.  */
00104        unsigned int mantissa1:32;
00105        unsigned int mantissa0:19;
00106        unsigned int quiet_nan:1;
00107        unsigned int exponent:11;
00108        unsigned int negative:1;
00109 #endif
00110       } ieee_nan;
00111   };
00112 
00113 #define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent.  */
00114 
00115 
00116 union ieee854_long_double
00117   {
00118     long double d;
00119 
00120     /* This is the IEEE 854 quad-precision format.  */
00121     struct
00122       {
00123 #if    __BYTE_ORDER == __BIG_ENDIAN
00124        unsigned int negative:1;
00125        unsigned int exponent:15;
00126        /* Together these comprise the mantissa.  */
00127        unsigned int mantissa0:16;
00128        unsigned int mantissa1:32;
00129        unsigned int mantissa2:32;
00130        unsigned int mantissa3:32;
00131 #endif                      /* Big endian.  */
00132 #if    __BYTE_ORDER == __LITTLE_ENDIAN
00133        /* Together these comprise the mantissa.  */
00134        unsigned int mantissa3:32;
00135        unsigned int mantissa2:32;
00136        unsigned int mantissa1:32;
00137        unsigned int mantissa0:16;
00138        unsigned int exponent:15;
00139        unsigned int negative:1;
00140 #endif                      /* Little endian.  */
00141       } ieee;
00142 
00143     /* This format makes it easier to see if a NaN is a signalling NaN.  */
00144     struct
00145       {
00146 #if    __BYTE_ORDER == __BIG_ENDIAN
00147        unsigned int negative:1;
00148        unsigned int exponent:15;
00149        unsigned int quiet_nan:1;
00150        /* Together these comprise the mantissa.  */
00151        unsigned int mantissa0:15;
00152        unsigned int mantissa1:32;
00153        unsigned int mantissa2:32;
00154        unsigned int mantissa3:32;
00155 #else
00156        /* Together these comprise the mantissa.  */
00157        unsigned int mantissa3:32;
00158        unsigned int mantissa2:32;
00159        unsigned int mantissa1:32;
00160        unsigned int mantissa0:15;
00161        unsigned int quiet_nan:1;
00162        unsigned int exponent:15;
00163        unsigned int negative:1;
00164 #endif
00165       } ieee_nan;
00166   };
00167 
00168 #define IEEE854_LONG_DOUBLE_BIAS 0x3fff /* Added to exponent.  */
00169 
00170 
00171 /* IBM extended format for long double.
00172 
00173    Each long double is made up of two IEEE doubles.  The value of the
00174    long double is the sum of the values of the two parts.  The most
00175    significant part is required to be the value of the long double
00176    rounded to the nearest double, as specified by IEEE.  For Inf
00177    values, the least significant part is required to be one of +0.0 or
00178    -0.0.  No other requirements are made; so, for example, 1.0 may be
00179    represented as (1.0, +0.0) or (1.0, -0.0), and the low part of a
00180    NaN is don't-care.  */
00181 
00182 union ibm_extended_long_double
00183   {
00184     long double d;
00185     double dd[2];
00186 
00187     /* This is the IBM extended format long double.  */
00188     struct
00189       { /* Big endian.  There is no other.  */
00190 
00191        unsigned int negative:1;
00192        unsigned int exponent:11;
00193        /* Together Mantissa0-3 comprise the mantissa.  */
00194        unsigned int mantissa0:20;
00195        unsigned int mantissa1:32;
00196 
00197        unsigned int negative2:1;
00198        unsigned int exponent2:11;
00199        /* There is an implied 1 here?  */
00200        /* Together these comprise the mantissa.  */
00201        unsigned int mantissa2:20;
00202        unsigned int mantissa3:32;
00203       } ieee;
00204    };
00205 
00206 #define IBM_EXTENDED_LONG_DOUBLE_BIAS 0x3ff /* Added to exponent.  */
00207 
00208 __END_DECLS
00209 
00210 #endif /* ieee754.h */