Back to index

glibc  2.9
double.h
Go to the documentation of this file.
00001 /* Software floating-point emulation.
00002    Definitions for IEEE Double Precision
00003    Copyright (C) 1997,1998,1999,2006,2007 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Richard Henderson (rth@cygnus.com),
00006                 Jakub Jelinek (jj@ultra.linux.cz),
00007                 David S. Miller (davem@redhat.com) and
00008                 Peter Maydell (pmaydell@chiark.greenend.org.uk).
00009 
00010    The GNU C Library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Lesser General Public
00012    License as published by the Free Software Foundation; either
00013    version 2.1 of the License, or (at your option) any later version.
00014 
00015    In addition to the permissions in the GNU Lesser General Public
00016    License, the Free Software Foundation gives you unlimited
00017    permission to link the compiled version of this file into
00018    combinations with other programs, and to distribute those
00019    combinations without any restriction coming from the use of this
00020    file.  (The Lesser General Public License restrictions do apply in
00021    other respects; for example, they cover modification of the file,
00022    and distribution when not linked into a combine executable.)
00023 
00024    The GNU C Library is distributed in the hope that it will be useful,
00025    but WITHOUT ANY WARRANTY; without even the implied warranty of
00026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027    Lesser General Public License for more details.
00028 
00029    You should have received a copy of the GNU Lesser General Public
00030    License along with the GNU C Library; if not, write to the Free
00031    Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
00032    MA 02110-1301, USA.  */
00033 
00034 #if _FP_W_TYPE_SIZE < 32
00035 #error "Here's a nickel kid.  Go buy yourself a real computer."
00036 #endif
00037 
00038 #if _FP_W_TYPE_SIZE < 64
00039 #define _FP_FRACTBITS_D            (2 * _FP_W_TYPE_SIZE)
00040 #else
00041 #define _FP_FRACTBITS_D            _FP_W_TYPE_SIZE
00042 #endif
00043 
00044 #define _FP_FRACBITS_D             53
00045 #define _FP_FRACXBITS_D            (_FP_FRACTBITS_D - _FP_FRACBITS_D)
00046 #define _FP_WFRACBITS_D            (_FP_WORKBITS + _FP_FRACBITS_D)
00047 #define _FP_WFRACXBITS_D    (_FP_FRACTBITS_D - _FP_WFRACBITS_D)
00048 #define _FP_EXPBITS_D              11
00049 #define _FP_EXPBIAS_D              1023
00050 #define _FP_EXPMAX_D        2047
00051 
00052 #define _FP_QNANBIT_D              \
00053        ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-2) % _FP_W_TYPE_SIZE)
00054 #define _FP_QNANBIT_SH_D           \
00055        ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-2+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
00056 #define _FP_IMPLBIT_D              \
00057        ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-1) % _FP_W_TYPE_SIZE)
00058 #define _FP_IMPLBIT_SH_D           \
00059        ((_FP_W_TYPE)1 << (_FP_FRACBITS_D-1+_FP_WORKBITS) % _FP_W_TYPE_SIZE)
00060 #define _FP_OVERFLOW_D             \
00061        ((_FP_W_TYPE)1 << _FP_WFRACBITS_D % _FP_W_TYPE_SIZE)
00062 
00063 typedef float DFtype __attribute__((mode(DF)));
00064 
00065 #if _FP_W_TYPE_SIZE < 64
00066 
00067 union _FP_UNION_D
00068 {
00069   DFtype flt;
00070   struct {
00071 #if __BYTE_ORDER == __BIG_ENDIAN
00072     unsigned sign  : 1;
00073     unsigned exp   : _FP_EXPBITS_D;
00074     unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
00075     unsigned frac0 : _FP_W_TYPE_SIZE;
00076 #else
00077     unsigned frac0 : _FP_W_TYPE_SIZE;
00078     unsigned frac1 : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0) - _FP_W_TYPE_SIZE;
00079     unsigned exp   : _FP_EXPBITS_D;
00080     unsigned sign  : 1;
00081 #endif
00082   } bits __attribute__((packed));
00083 };
00084 
00085 #define FP_DECL_D(X)        _FP_DECL(2,X)
00086 #define FP_UNPACK_RAW_D(X,val)     _FP_UNPACK_RAW_2(D,X,val)
00087 #define FP_UNPACK_RAW_DP(X,val)    _FP_UNPACK_RAW_2_P(D,X,val)
00088 #define FP_PACK_RAW_D(val,X)       _FP_PACK_RAW_2(D,val,X)
00089 #define FP_PACK_RAW_DP(val,X)             \
00090   do {                             \
00091     if (!FP_INHIBIT_RESULTS)              \
00092       _FP_PACK_RAW_2_P(D,val,X);   \
00093   } while (0)
00094 
00095 #define FP_UNPACK_D(X,val)         \
00096   do {                             \
00097     _FP_UNPACK_RAW_2(D,X,val);            \
00098     _FP_UNPACK_CANONICAL(D,2,X);   \
00099   } while (0)
00100 
00101 #define FP_UNPACK_DP(X,val)        \
00102   do {                             \
00103     _FP_UNPACK_RAW_2_P(D,X,val);   \
00104     _FP_UNPACK_CANONICAL(D,2,X);   \
00105   } while (0)
00106 
00107 #define FP_UNPACK_SEMIRAW_D(X,val) \
00108   do {                             \
00109     _FP_UNPACK_RAW_2(D,X,val);            \
00110     _FP_UNPACK_SEMIRAW(D,2,X);            \
00111   } while (0)
00112 
00113 #define FP_UNPACK_SEMIRAW_DP(X,val)       \
00114   do {                             \
00115     _FP_UNPACK_RAW_2_P(D,X,val);   \
00116     _FP_UNPACK_SEMIRAW(D,2,X);            \
00117   } while (0)
00118 
00119 #define FP_PACK_D(val,X)           \
00120   do {                             \
00121     _FP_PACK_CANONICAL(D,2,X);            \
00122     _FP_PACK_RAW_2(D,val,X);              \
00123   } while (0)
00124 
00125 #define FP_PACK_DP(val,X)          \
00126   do {                             \
00127     _FP_PACK_CANONICAL(D,2,X);            \
00128     if (!FP_INHIBIT_RESULTS)              \
00129       _FP_PACK_RAW_2_P(D,val,X);   \
00130   } while (0)
00131 
00132 #define FP_PACK_SEMIRAW_D(val,X)   \
00133   do {                             \
00134     _FP_PACK_SEMIRAW(D,2,X);              \
00135     _FP_PACK_RAW_2(D,val,X);              \
00136   } while (0)
00137 
00138 #define FP_PACK_SEMIRAW_DP(val,X)  \
00139   do {                             \
00140     _FP_PACK_SEMIRAW(D,2,X);              \
00141     if (!FP_INHIBIT_RESULTS)              \
00142       _FP_PACK_RAW_2_P(D,val,X);   \
00143   } while (0)
00144 
00145 #define FP_ISSIGNAN_D(X)           _FP_ISSIGNAN(D,2,X)
00146 #define FP_NEG_D(R,X)                     _FP_NEG(D,2,R,X)
00147 #define FP_ADD_D(R,X,Y)                   _FP_ADD(D,2,R,X,Y)
00148 #define FP_SUB_D(R,X,Y)                   _FP_SUB(D,2,R,X,Y)
00149 #define FP_MUL_D(R,X,Y)                   _FP_MUL(D,2,R,X,Y)
00150 #define FP_DIV_D(R,X,Y)                   _FP_DIV(D,2,R,X,Y)
00151 #define FP_SQRT_D(R,X)                    _FP_SQRT(D,2,R,X)
00152 #define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_2(R,S,T,X,Q)
00153 
00154 #define FP_CMP_D(r,X,Y,un)  _FP_CMP(D,2,r,X,Y,un)
00155 #define FP_CMP_EQ_D(r,X,Y)  _FP_CMP_EQ(D,2,r,X,Y)
00156 #define FP_CMP_UNORD_D(r,X,Y)      _FP_CMP_UNORD(D,2,r,X,Y)
00157 
00158 #define FP_TO_INT_D(r,X,rsz,rsg)   _FP_TO_INT(D,2,r,X,rsz,rsg)
00159 #define FP_FROM_INT_D(X,r,rs,rt)   _FP_FROM_INT(D,2,X,r,rs,rt)
00160 
00161 #define _FP_FRAC_HIGH_D(X)  _FP_FRAC_HIGH_2(X)
00162 #define _FP_FRAC_HIGH_RAW_D(X)     _FP_FRAC_HIGH_2(X)
00163 
00164 #else
00165 
00166 union _FP_UNION_D
00167 {
00168   DFtype flt;
00169   struct {
00170 #if __BYTE_ORDER == __BIG_ENDIAN
00171     unsigned sign   : 1;
00172     unsigned exp    : _FP_EXPBITS_D;
00173     _FP_W_TYPE frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
00174 #else
00175     _FP_W_TYPE frac : _FP_FRACBITS_D - (_FP_IMPLBIT_D != 0);
00176     unsigned exp    : _FP_EXPBITS_D;
00177     unsigned sign   : 1;
00178 #endif
00179   } bits __attribute__((packed));
00180 };
00181 
00182 #define FP_DECL_D(X)        _FP_DECL(1,X)
00183 #define FP_UNPACK_RAW_D(X,val)     _FP_UNPACK_RAW_1(D,X,val)
00184 #define FP_UNPACK_RAW_DP(X,val)    _FP_UNPACK_RAW_1_P(D,X,val)
00185 #define FP_PACK_RAW_D(val,X)       _FP_PACK_RAW_1(D,val,X)
00186 #define FP_PACK_RAW_DP(val,X)             \
00187   do {                             \
00188     if (!FP_INHIBIT_RESULTS)              \
00189       _FP_PACK_RAW_1_P(D,val,X);   \
00190   } while (0)
00191 
00192 #define FP_UNPACK_D(X,val)         \
00193   do {                             \
00194     _FP_UNPACK_RAW_1(D,X,val);            \
00195     _FP_UNPACK_CANONICAL(D,1,X);   \
00196   } while (0)
00197 
00198 #define FP_UNPACK_DP(X,val)        \
00199   do {                             \
00200     _FP_UNPACK_RAW_1_P(D,X,val);   \
00201     _FP_UNPACK_CANONICAL(D,1,X);   \
00202   } while (0)
00203 
00204 #define FP_UNPACK_SEMIRAW_D(X,val) \
00205   do {                             \
00206     _FP_UNPACK_RAW_2(1,X,val);            \
00207     _FP_UNPACK_SEMIRAW(D,1,X);            \
00208   } while (0)
00209 
00210 #define FP_UNPACK_SEMIRAW_DP(X,val)       \
00211   do {                             \
00212     _FP_UNPACK_RAW_2_P(1,X,val);   \
00213     _FP_UNPACK_SEMIRAW(D,1,X);            \
00214   } while (0)
00215 
00216 #define FP_PACK_D(val,X)           \
00217   do {                             \
00218     _FP_PACK_CANONICAL(D,1,X);            \
00219     _FP_PACK_RAW_1(D,val,X);              \
00220   } while (0)
00221 
00222 #define FP_PACK_DP(val,X)          \
00223   do {                             \
00224     _FP_PACK_CANONICAL(D,1,X);            \
00225     if (!FP_INHIBIT_RESULTS)              \
00226       _FP_PACK_RAW_1_P(D,val,X);   \
00227   } while (0)
00228 
00229 #define FP_PACK_SEMIRAW_D(val,X)   \
00230   do {                             \
00231     _FP_PACK_SEMIRAW(D,1,X);              \
00232     _FP_PACK_RAW_1(D,val,X);              \
00233   } while (0)
00234 
00235 #define FP_PACK_SEMIRAW_DP(val,X)  \
00236   do {                             \
00237     _FP_PACK_SEMIRAW(D,1,X);              \
00238     if (!FP_INHIBIT_RESULTS)              \
00239       _FP_PACK_RAW_1_P(D,val,X);   \
00240   } while (0)
00241 
00242 #define FP_ISSIGNAN_D(X)           _FP_ISSIGNAN(D,1,X)
00243 #define FP_NEG_D(R,X)                     _FP_NEG(D,1,R,X)
00244 #define FP_ADD_D(R,X,Y)                   _FP_ADD(D,1,R,X,Y)
00245 #define FP_SUB_D(R,X,Y)                   _FP_SUB(D,1,R,X,Y)
00246 #define FP_MUL_D(R,X,Y)                   _FP_MUL(D,1,R,X,Y)
00247 #define FP_DIV_D(R,X,Y)                   _FP_DIV(D,1,R,X,Y)
00248 #define FP_SQRT_D(R,X)                    _FP_SQRT(D,1,R,X)
00249 #define _FP_SQRT_MEAT_D(R,S,T,X,Q) _FP_SQRT_MEAT_1(R,S,T,X,Q)
00250 
00251 /* The implementation of _FP_MUL_D and _FP_DIV_D should be chosen by
00252    the target machine.  */
00253 
00254 #define FP_CMP_D(r,X,Y,un)  _FP_CMP(D,1,r,X,Y,un)
00255 #define FP_CMP_EQ_D(r,X,Y)  _FP_CMP_EQ(D,1,r,X,Y)
00256 #define FP_CMP_UNORD_D(r,X,Y)      _FP_CMP_UNORD(D,1,r,X,Y)
00257 
00258 #define FP_TO_INT_D(r,X,rsz,rsg)   _FP_TO_INT(D,1,r,X,rsz,rsg)
00259 #define FP_FROM_INT_D(X,r,rs,rt)   _FP_FROM_INT(D,1,X,r,rs,rt)
00260 
00261 #define _FP_FRAC_HIGH_D(X)  _FP_FRAC_HIGH_1(X)
00262 #define _FP_FRAC_HIGH_RAW_D(X)     _FP_FRAC_HIGH_1(X)
00263 
00264 #endif /* W_TYPE_SIZE < 64 */