Back to index

glibc  2.9
libm_support.h
Go to the documentation of this file.
00001 /* file: libm_support.h */
00002 
00003 
00004 /*
00005 // Copyright (c) 2000 - 2004, Intel Corporation
00006 // All rights reserved.
00007 //
00008 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // * Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // * Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // * The name of Intel Corporation may not be used to endorse or promote
00022 // products derived from this software without specific prior written
00023 // permission.
00024 
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00029 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00034 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Intel Corporation is the author of this code, and requests that all
00039 // problem reports or change requests be submitted to it directly at
00040 // http://www.intel.com/software/products/opensource/libraries/num.htm.
00041 //
00042 
00043 // History: 02/02/2000 Initial version
00044 //          2/28/2000 added tags for logb and nextafter
00045 //          3/22/2000 Changes to support _LIB_VERSIONIMF variable
00046 //                    and filled some enum gaps. Added support for C99.
00047 //          5/31/2000 added prototypes for __libm_frexp_4l/8l
00048 //          8/10/2000 Changed declaration of _LIB_VERSIONIMF to work for library
00049 //                    builds and other application builds (precompiler directives).
00050 //          8/11/2000 Added pointers-to-matherr-functions declarations to allow
00051 //                    for user-defined matherr functions in the dll build.
00052 //         12/07/2000 Added scalbn error_types values.
00053 //          5/01/2001 Added error_types values for C99 nearest integer
00054 //                    functions.
00055 //          6/07/2001 Added error_types values for fdim.
00056 //          6/18/2001 Added include of complex_support.h.
00057 //          8/03/2001 Added error_types values for nexttoward, scalbln.
00058 //          8/23/2001 Corrected tag numbers from 186 and higher.
00059 //          8/27/2001 Added check for long int and long long int definitions.
00060 //         12/10/2001 Added error_types for erfc.
00061 //         12/27/2001 Added error_types for degree argument functions.
00062 //         01/02/2002 Added error_types for tand, cotd.
00063 //         01/04/2002 Delete include of complex_support.h
00064 //         01/23/2002 Deleted prototypes for __libm_frexp*.  Added check for
00065 //                    multiple int, long int, and long long int definitions.
00066 //         05/20/2002 Added error_types for cot.
00067 //         06/27/2002 Added error_types for sinhcosh.
00068 //         12/05/2002 Added error_types for annuity and compound
00069 //         04/10/2003 Added error_types for tgammal/tgamma/tgammaf
00070 //         05/16/2003 FP-treatment macros copied here from IA32 libm_support.h
00071 //         06/02/2003 Added pad into struct fp80 (12/16 bytes).
00072 //         08/01/2003 Added struct ker80 and macros for multiprecision addition,
00073 //                    subtraction, multiplication, division, square root.
00074 //         08/07/2003 History section updated.
00075 //         09/03/2003 ALIGN(n) macro added.
00076 //         10/01/2003 LDOUBLE_ALIGN and fp80 corrected on linux to 16 bytes.
00077 //         11/24/2004 Added ifdef around definitions of INT32/64
00078 //         12/15/2004 Added error_types for exp10, nextafter, nexttoward
00079 //                    underflow.  Moved error codes into libm_error_codes.h.
00080 //
00081 */
00082 
00083 #ifndef __LIBM_SUPPORT_H_INCLUDED__
00084 #define __LIBM_SUPPORT_H_INCLUDED__
00085 
00086 #ifndef _LIBC
00087 #if !(defined(_WIN32) || defined(_WIN64))
00088 # pragma const_seg(".rodata") /* place constant data in text (code) section */
00089 #endif
00090 
00091 #if defined(__ICC) || defined(__ICL) || defined(__ECC) || defined(__ECL)
00092 # pragma warning( disable : 1682 ) /* #1682: ixplicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem) */
00093 # pragma warning( disable : 1683 ) /* #1683: explicit conversion of a 64-bit integral type to a smaller integral type (potential portability problem) */
00094 #endif
00095 #endif
00096 
00097 /* macros to form a double value in hex representation (unsigned int type) */
00098 
00099 #define DOUBLE_HEX(hi,lo) 0x##lo,0x##hi /*LITTLE_ENDIAN*/
00100 
00101 #include "libm_cpu_defs.h"
00102 
00103 #if !(defined (IA64))
00104 #  include "libm_dll.h"
00105 #  include "libm_dispatch.h"
00106 #endif
00107 
00108 #include "libm_error_codes.h"
00109 
00110 struct exceptionf
00111 {
00112   int type;
00113   char *name;
00114   float arg1, arg2, retval;
00115 };
00116 
00117 # ifdef __cplusplus
00118 struct __exception
00119 {
00120   int type;
00121   char *name;
00122   double arg1, arg2, retval;
00123 };
00124 # else
00125 
00126 #  ifndef _LIBC
00127 struct exception
00128 {
00129   int type;
00130   char *name;
00131   double arg1, arg2, retval;
00132 };
00133 #  endif
00134 # endif
00135 
00136 struct exceptionl
00137 {
00138   int type;
00139   char *name;
00140   long double arg1, arg2, retval;
00141 };
00142 
00143 #if (defined (_MS_) && defined (IA64))
00144 #define   MATHERR_F   _matherrf
00145 #define   MATHERR_D   _matherr
00146 #else
00147 #define MATHERR_F   matherrf
00148 #define MATHERR_D   matherr
00149 #endif
00150 
00151 # ifdef __cplusplus
00152 #define EXC_DECL_D  __exception
00153 #else
00154 // exception is a reserved name in C++
00155 #define EXC_DECL_D  exception
00156 #endif
00157 
00158 extern int MATHERR_F(struct exceptionf*);
00159 extern int MATHERR_D(struct EXC_DECL_D*);
00160 extern int matherrl(struct exceptionl*);
00161 
00162 #ifndef _LIBC
00163 // Add code to support _LIB_VERSIONIMF
00164 typedef enum
00165 {
00166     _IEEE_ = -1, // IEEE-like behavior
00167     _SVID_,      // SysV, Rel. 4 behavior
00168     _XOPEN_,     // Unix98
00169     _POSIX_,     // Posix
00170     _ISOC_       // ISO C9X
00171 } _LIB_VERSION_TYPE;
00172 #endif
00173 
00174 // This is a run-time variable and may affect
00175 // floating point behavior of the libm functions
00176 
00177 #if !defined( LIBM_BUILD )
00178 #if defined( _DLL )
00179 extern _LIB_VERSION_TYPE __declspec(dllimport) _LIB_VERSIONIMF;
00180 #else
00181 extern _LIB_VERSION_TYPE _LIB_VERSIONIMF;
00182 #endif  /* _DLL */
00183 #else
00184 extern int (*pmatherrf)(struct exceptionf*);
00185 extern int (*pmatherr)(struct EXC_DECL_D*);
00186 extern int (*pmatherrl)(struct exceptionl*);
00187 #endif  /* LIBM_BUILD */
00188 
00189 /* memory format definitions (LITTLE_ENDIAN only) */
00190 
00191 #if !(defined(SIZE_INT_32) || defined(SIZE_INT_64))
00192 # error "You need to define SIZE_INT_32 or SIZE_INT_64"
00193 #endif
00194 
00195 #if (defined(SIZE_INT_32) && defined(SIZE_INT_64))
00196 #error multiple integer size definitions; define SIZE_INT_32 or SIZE_INT_64
00197 #endif
00198 
00199 #if !(defined(SIZE_LONG_32) || defined(SIZE_LONG_64))
00200 # error "You need to define SIZE_LONG_32 or SIZE_LONG_64"
00201 #endif
00202 
00203 #if (defined(SIZE_LONG_32) && defined(SIZE_LONG_64))
00204 #error multiple integer size definitions; define SIZE_LONG_32 or SIZE_LONG_64
00205 #endif
00206 
00207 #if !defined(__USE_EXTERNAL_FPMEMTYP_H__)
00208 
00209 #define BIAS_32  0x007F
00210 #define BIAS_64  0x03FF
00211 #define BIAS_80  0x3FFF
00212 
00213 #define MAXEXP_32  0x00FE
00214 #define MAXEXP_64  0x07FE
00215 #define MAXEXP_80  0x7FFE
00216 
00217 #define EXPINF_32  0x00FF
00218 #define EXPINF_64  0x07FF
00219 #define EXPINF_80  0x7FFF
00220 
00221 struct fp32 { /*// sign:1 exponent:8 significand:23 (implied leading 1)*/
00222 #if defined(SIZE_INT_32)
00223     unsigned significand:23;
00224     unsigned exponent:8;
00225     unsigned sign:1;
00226 #elif defined(SIZE_INT_64)
00227     unsigned significand:23;
00228     unsigned exponent:8;
00229     unsigned sign:1;
00230 #endif
00231 };
00232 
00233 struct fp64 { /*/ sign:1 exponent:11 significand:52 (implied leading 1)*/
00234 #if defined(SIZE_INT_32)
00235     unsigned lo_significand:32;
00236     unsigned hi_significand:20;
00237     unsigned exponent:11;
00238     unsigned sign:1;
00239 #elif defined(SIZE_INT_64)
00240     unsigned significand:52;
00241     unsigned exponent:11;
00242     unsigned sign:1;
00243 #endif
00244 };
00245 
00246 struct fp80 { /*/ sign:1 exponent:15 significand:64 (NO implied bits) */
00247 #if defined(SIZE_INT_32)
00248     unsigned         lo_significand;
00249     unsigned         hi_significand;
00250     unsigned         exponent:15;
00251     unsigned         sign:1;
00252 #elif defined(SIZE_INT_64)
00253     unsigned         significand;
00254     unsigned         exponent:15;
00255     unsigned         sign:1;
00256 #endif
00257     unsigned         pad:16;
00258 #if !(defined(__unix__) && defined(__i386__))
00259     unsigned         padwin:32;
00260 #endif
00261 };
00262 
00263 #endif /*__USE_EXTERNAL_FPMEMTYP_H__*/
00264 
00265 #if !(defined(opensource))
00266 typedef          __int32  INT32;
00267 typedef   signed __int32 SINT32;
00268 typedef unsigned __int32 UINT32;
00269 
00270 typedef          __int64  INT64;
00271 typedef   signed __int64 SINT64;
00272 typedef unsigned __int64 UINT64;
00273 #else
00274 typedef          int  INT32;
00275 typedef   signed int SINT32;
00276 typedef unsigned int UINT32;
00277 
00278 typedef          long long  INT64;
00279 typedef   signed long long SINT64;
00280 typedef unsigned long long UINT64;
00281 #endif
00282 
00283 #if (defined(_WIN32) || defined(_WIN64))        /* Windows */
00284 # define I64CONST(bits) 0x##bits##i64
00285 # define U64CONST(bits) 0x##bits##ui64
00286 #elif (defined(__linux__) && defined(_M_IA64))  /* Linux,64 */
00287 # define I64CONST(bits) 0x##bits##L
00288 # define U64CONST(bits) 0x##bits##uL
00289 #else                                           /* Linux,32 */
00290 # define I64CONST(bits) 0x##bits##LL
00291 # define U64CONST(bits) 0x##bits##uLL
00292 #endif
00293 
00294 struct ker80 {
00295     union {
00296         long double ldhi;
00297         struct fp80 fphi;
00298     };
00299     union {
00300         long double ldlo;
00301         struct fp80 fplo;
00302     };
00303     int ex;
00304 };
00305 
00306 /* Addition: x+y                                            */
00307 /* The result is sum rhi+rlo                                */
00308 /* Temporary variables: t1                                  */
00309 /* All variables are in long double precision               */
00310 /* Correct if no overflow (algorithm by D.Knuth)           */
00311 #define __LIBM_ADDL1_K80( rhi,rlo,x,y, t1 )                 \
00312     rhi = x   + y;                                          \
00313     rlo = rhi - x;                                          \
00314     t1  = rhi - rlo;                                        \
00315     rlo = y   - rlo;                                        \
00316     t1  = x   - t1;                                         \
00317     rlo = rlo + t1;
00318 
00319 /* Addition: (xhi+xlo) + (yhi+ylo)                          */
00320 /* The result is sum rhi+rlo                                */
00321 /* Temporary variables: t1                                  */
00322 /* All variables are in long double precision               */
00323 /* Correct if no overflow (algorithm by T.J.Dekker)         */
00324 #define __LIBM_ADDL2_K80( rhi,rlo,xhi,xlo,yhi,ylo, t1 )     \
00325     rlo = xhi+yhi;                                          \
00326     if ( VALUE_GT_80(FP80(xhi),FP80(yhi)) ) {               \
00327         t1=xhi-rlo;t1=t1+yhi;t1=t1+ylo;t1=t1+xlo;           \
00328     } else {                                                \
00329         t1=yhi-rlo;t1=t1+xhi;t1=t1+xlo;t1=t1+ylo;           \
00330     }                                                       \
00331     rhi=rlo+t1;                                             \
00332     rlo=rlo-rhi;rlo=rlo+t1;
00333 
00334 /* Addition: r=x+y                                          */
00335 /* Variables r,x,y are pointers to struct ker80,            */
00336 /* all other variables are in long double precision         */
00337 /* Temporary variables: t1                                  */
00338 /* Correct if x and y belong to interval [2^-8000;2^8000],  */
00339 /* or when one or both of them are zero                     */
00340 #if   defined(SIZE_INT_32)
00341 #define __LIBM_ADDL_K80(r,x,y, t1)                          \
00342     if ( ((y)->ex+(y)->fphi.exponent-134 <                  \
00343           (x)->ex+(x)->fphi.exponent)       &&              \
00344          ((x)->ex+(x)->fphi.exponent <                      \
00345           (y)->ex+(y)->fphi.exponent+134)   &&              \
00346          !SIGNIFICAND_ZERO_80(&((x)->fphi)) &&              \
00347          !SIGNIFICAND_ZERO_80(&((y)->fphi)) )               \
00348     {                                                       \
00349         /* y/2^134 < x < y*2^134,               */          \
00350         /* and x,y are nonzero finite numbers   */          \
00351         if ( (x)->ex != (y)->ex ) {                         \
00352             /* adjust x->ex to y->ex */                     \
00353             /* t1 = 2^(x->ex - y->ex) */                    \
00354             FP80(t1)->sign = 0;                             \
00355             FP80(t1)->exponent = BIAS_80 + (x)->ex-(y)->ex; \
00356             /*  exponent is correct because             */  \
00357             /*  |x->ex - y->ex| =                       */  \
00358             /*  = |  (x->ex + x->fphi.exponent) -       */  \
00359             /*      -(y->ex + y->fphi.exponent) +       */  \
00360             /*              + y->fphi.exponent  -       */  \
00361             /*              - x->fphi.exponent     | <  */  \
00362             /*  < |  (x->ex+x->fphi.exponent) -         */  \
00363             /*      -(y->ex+y->fphi.exponent)      | +  */  \
00364             /*   +|  y->fphi.exponent -                 */  \
00365             /*      -x->fphi.exponent              | <  */  \
00366             /*  < 134 + 16000                           */  \
00367             FP80(t1)->hi_significand = 0x80000000;          \
00368             FP80(t1)->lo_significand = 0x00000000;          \
00369             (x)->ex = (y)->ex;                              \
00370             (x)->ldhi *= t1;                                \
00371             (x)->ldlo *= t1;                                \
00372         }                                                   \
00373         /* r==x+y */                                        \
00374         (r)->ex = (y)->ex;                                  \
00375         __LIBM_ADDL2_K80( (r)->ldhi,(r)->ldlo,              \
00376             (x)->ldhi,(x)->ldlo, (y)->ldhi,(y)->ldlo, t1 ); \
00377     } else if ( SIGNIFICAND_ZERO_80(&((x)->fphi)) ||        \
00378              ((y)->ex+(y)->fphi.exponent-BIAS_80 - 134 >=   \
00379               (x)->ex+(x)->fphi.exponent-BIAS_80) )         \
00380     {                                                       \
00381         /* |x|<<|y| */                                      \
00382         *(r) = *(y);                                        \
00383     } else {                                                \
00384         /* |y|<<|x| */                                      \
00385         *(r) = *(x);                                        \
00386     }
00387 #elif defined(SIZE_INT_64)
00388 #define __LIBM_ADDL_K80(r,x,y, t1)                          \
00389     if ( ((y)->ex+(y)->fphi.exponent-134 <                  \
00390           (x)->ex+(x)->fphi.exponent)       &&              \
00391          ((x)->ex+(x)->fphi.exponent <                      \
00392           (y)->ex+(y)->fphi.exponent+134)   &&              \
00393          !SIGNIFICAND_ZERO_80(&((x)->fphi)) &&              \
00394          !SIGNIFICAND_ZERO_80(&((y)->fphi)) )               \
00395     {                                                       \
00396         /* y/2^134 < x < y*2^134,               */          \
00397         /* and x,y are nonzero finite numbers   */          \
00398         if ( (x)->ex != (y)->ex ) {                         \
00399             /* adjust x->ex to y->ex */                     \
00400             /* t1 = 2^(x->ex - y->ex) */                    \
00401             FP80(t1)->sign = 0;                             \
00402             FP80(t1)->exponent = BIAS_80 + (x)->ex-(y)->ex; \
00403             /*  exponent is correct because             */  \
00404             /*  |x->ex - y->ex| =                       */  \
00405             /*  = |  (x->ex + x->fphi.exponent) -       */  \
00406             /*      -(y->ex + y->fphi.exponent) +       */  \
00407             /*              + y->fphi.exponent  -       */  \
00408             /*              - x->fphi.exponent     | <  */  \
00409             /*  < |  (x->ex+x->fphi.exponent) -         */  \
00410             /*      -(y->ex+y->fphi.exponent)      | +  */  \
00411             /*   +|  y->fphi.exponent -                 */  \
00412             /*      -x->fphi.exponent              | <  */  \
00413             /*  < 134 + 16000                           */  \
00414             FP80(t1)->significand = 0x8000000000000000;     \
00415             (x)->ex = (y)->ex;                              \
00416             (x)->ldhi *= t1;                                \
00417             (x)->ldlo *= t1;                                \
00418         }                                                   \
00419         /* r==x+y */                                        \
00420         (r)->ex = (y)->ex;                                  \
00421         __LIBM_ADDL2_K80( (r)->ldhi,(r)->ldlo,              \
00422             (x)->ldhi,(x)->ldlo, (y)->ldhi,(y)->ldlo, t1 ); \
00423     } else if ( SIGNIFICAND_ZERO_80(&((x)->fphi)) ||        \
00424              ((y)->ex+(y)->fphi.exponent-BIAS_80 - 134 >=   \
00425               (x)->ex+(x)->fphi.exponent-BIAS_80) )         \
00426     {                                                       \
00427         /* |x|<<|y| */                                      \
00428         *(r) = *(y);                                        \
00429     } else {                                                \
00430         /* |y|<<|x| */                                      \
00431         *(r) = *(x);                                        \
00432     }
00433 #endif
00434 
00435 /* Addition: r=x+y                                          */
00436 /* Variables r,x,y are pointers to struct ker80,            */
00437 /* all other variables are in long double precision         */
00438 /* Temporary variables: t1                                  */
00439 /* Correct for any finite x and y                           */
00440 #define __LIBM_ADDL_NORM_K80(r,x,y, t1)                     \
00441     if ( ((x)->fphi.exponent-BIAS_80<-8000) ||              \
00442          ((x)->fphi.exponent-BIAS_80>+8000) ||              \
00443          ((y)->fphi.exponent-BIAS_80<-8000) ||              \
00444          ((y)->fphi.exponent-BIAS_80>+8000) )               \
00445     {                                                       \
00446         __libm_normalizel_k80(x);                           \
00447         __libm_normalizel_k80(y);                           \
00448     }                                                       \
00449     __LIBM_ADDL_K80(r,x,y, t1)
00450 
00451 /* Subtraction: x-y                                         */
00452 /* The result is sum rhi+rlo                                */
00453 /* Temporary variables: t1                                  */
00454 /* All variables are in long double precision               */
00455 /* Correct if no overflow (algorithm by D.Knuth)           */
00456 #define __LIBM_SUBL1_K80( rhi, rlo, x, y, t1 )              \
00457     rhi = x   - y;                                          \
00458     rlo = rhi - x;                                          \
00459     t1  = rhi - rlo;                                        \
00460     rlo = y   + rlo;                                        \
00461     t1  = x   - t1;                                         \
00462     rlo = t1  - rlo;
00463 
00464 /* Subtraction: (xhi+xlo) - (yhi+ylo)                       */
00465 /* The result is sum rhi+rlo                                */
00466 /* Temporary variables: t1                                  */
00467 /* All variables are in long double precision               */
00468 /* Correct if no overflow (algorithm by T.J.Dekker)         */
00469 #define __LIBM_SUBL2_K80( rhi,rlo,xhi,xlo,yhi,ylo, t1 )     \
00470     rlo = xhi-yhi;                                          \
00471     if ( VALUE_GT_80(FP80(xhi),FP80(yhi)) ) {               \
00472         t1=xhi-rlo;t1=t1-yhi;t1=t1-ylo;t1=t1+xlo;           \
00473     } else {                                                \
00474         t1=yhi+rlo;t1=xhi-t1;t1=t1+xlo;t1=t1-ylo;           \
00475     }                                                       \
00476     rhi=rlo+t1;                                             \
00477     rlo=rlo-rhi;rlo=rlo+t1;
00478 
00479 /* Subtraction: r=x-y                                       */
00480 /* Variables r,x,y are pointers to struct ker80,            */
00481 /* all other variables are in long double precision         */
00482 /* Temporary variables: t1                                  */
00483 /* Correct if x and y belong to interval [2^-8000;2^8000],  */
00484 /* or when one or both of them are zero                     */
00485 #if   defined(SIZE_INT_32)
00486 #define __LIBM_SUBL_K80(r,x,y, t1)                          \
00487     if ( ((y)->ex+(y)->fphi.exponent-134 <                  \
00488           (x)->ex+(x)->fphi.exponent)       &&              \
00489          ((x)->ex+(x)->fphi.exponent <                      \
00490           (y)->ex+(y)->fphi.exponent+134)   &&              \
00491          !SIGNIFICAND_ZERO_80(&((x)->fphi)) &&              \
00492          !SIGNIFICAND_ZERO_80(&((y)->fphi)) )               \
00493     {                                                       \
00494         /* y/2^134 < x < y*2^134,               */          \
00495         /* and x,y are nonzero finite numbers   */          \
00496         if ( (x)->ex != (y)->ex ) {                         \
00497             /* adjust x->ex to y->ex */                     \
00498             /* t1 = 2^(x->ex - y->ex) */                    \
00499             FP80(t1)->sign = 0;                             \
00500             FP80(t1)->exponent = BIAS_80 + (x)->ex-(y)->ex; \
00501             /*  exponent is correct because             */  \
00502             /*  |x->ex - y->ex| =                       */  \
00503             /*  = |  (x->ex + x->fphi.exponent) -       */  \
00504             /*      -(y->ex + y->fphi.exponent) +       */  \
00505             /*              + y->fphi.exponent  -       */  \
00506             /*              - x->fphi.exponent     | <  */  \
00507             /*  < |  (x->ex+x->fphi.exponent) -         */  \
00508             /*      -(y->ex+y->fphi.exponent)      | +  */  \
00509             /*   +|  y->fphi.exponent -                 */  \
00510             /*      -x->fphi.exponent              | <  */  \
00511             /*  < 134 + 16000                           */  \
00512             FP80(t1)->hi_significand = 0x80000000;          \
00513             FP80(t1)->lo_significand = 0x00000000;          \
00514             (x)->ex = (y)->ex;                              \
00515             (x)->ldhi *= t1;                                \
00516             (x)->ldlo *= t1;                                \
00517         }                                                   \
00518         /* r==x+y */                                        \
00519         (r)->ex = (y)->ex;                                  \
00520         __LIBM_SUBL2_K80( (r)->ldhi,(r)->ldlo,              \
00521             (x)->ldhi,(x)->ldlo, (y)->ldhi,(y)->ldlo, t1 ); \
00522     } else if ( SIGNIFICAND_ZERO_80(&((x)->fphi)) ||        \
00523              ((y)->ex+(y)->fphi.exponent-BIAS_80 - 134 >=   \
00524               (x)->ex+(x)->fphi.exponent-BIAS_80) )         \
00525     {                                                       \
00526         /* |x|<<|y| */                                      \
00527         (r)->ex   =   (y)->ex;                              \
00528         (r)->ldhi = -((y)->ldhi);                           \
00529         (r)->ldlo = -((y)->ldlo);                           \
00530     } else {                                                \
00531         /* |y|<<|x| */                                      \
00532         *(r) = *(x);                                        \
00533     }
00534 #elif defined(SIZE_INT_64)
00535 #define __LIBM_SUBL_K80(r,x,y, t1)                          \
00536     if ( ((y)->ex+(y)->fphi.exponent-134 <                  \
00537           (x)->ex+(x)->fphi.exponent)       &&              \
00538          ((x)->ex+(x)->fphi.exponent <                      \
00539           (y)->ex+(y)->fphi.exponent+134)   &&              \
00540          !SIGNIFICAND_ZERO_80(&((x)->fphi)) &&              \
00541          !SIGNIFICAND_ZERO_80(&((y)->fphi)) )               \
00542     {                                                       \
00543         /* y/2^134 < x < y*2^134,               */          \
00544         /* and x,y are nonzero finite numbers   */          \
00545         if ( (x)->ex != (y)->ex ) {                         \
00546             /* adjust x->ex to y->ex */                     \
00547             /* t1 = 2^(x->ex - y->ex) */                    \
00548             FP80(t1)->sign = 0;                             \
00549             FP80(t1)->exponent = BIAS_80 + (x)->ex-(y)->ex; \
00550             /*  exponent is correct because             */  \
00551             /*  |x->ex - y->ex| =                       */  \
00552             /*  = |  (x->ex + x->fphi.exponent) -       */  \
00553             /*      -(y->ex + y->fphi.exponent) +       */  \
00554             /*              + y->fphi.exponent  -       */  \
00555             /*              - x->fphi.exponent     | <  */  \
00556             /*  < |  (x->ex+x->fphi.exponent) -         */  \
00557             /*      -(y->ex+y->fphi.exponent)      | +  */  \
00558             /*   +|  y->fphi.exponent -                 */  \
00559             /*      -x->fphi.exponent              | <  */  \
00560             /*  < 134 + 16000                           */  \
00561             FP80(t1)->significand = 0x8000000000000000;     \
00562             (x)->ex = (y)->ex;                              \
00563             (x)->ldhi *= t1;                                \
00564             (x)->ldlo *= t1;                                \
00565         }                                                   \
00566         /* r==x+y */                                        \
00567         (r)->ex = (y)->ex;                                  \
00568         __LIBM_SUBL2_K80( (r)->ldhi,(r)->ldlo,              \
00569             (x)->ldhi,(x)->ldlo, (y)->ldhi,(y)->ldlo, t1 ); \
00570     } else if ( SIGNIFICAND_ZERO_80(&((x)->fphi)) ||        \
00571              ((y)->ex+(y)->fphi.exponent-BIAS_80 - 134 >=   \
00572               (x)->ex+(x)->fphi.exponent-BIAS_80) )         \
00573     {                                                       \
00574         /* |x|<<|y| */                                      \
00575         (r)->ex   =   (y)->ex;                              \
00576         (r)->ldhi = -((y)->ldhi);                           \
00577         (r)->ldlo = -((y)->ldlo);                           \
00578     } else {                                                \
00579         /* |y|<<|x| */                                      \
00580         *(r) = *(x);                                        \
00581     }
00582 #endif
00583 
00584 /* Subtraction: r=x+y                                       */
00585 /* Variables r,x,y are pointers to struct ker80,            */
00586 /* all other variables are in long double precision         */
00587 /* Temporary variables: t1                                  */
00588 /* Correct for any finite x and y                           */
00589 #define __LIBM_SUBL_NORM_K80(r,x,y, t1)                     \
00590     if ( ((x)->fphi.exponent-BIAS_80<-8000) ||              \
00591          ((x)->fphi.exponent-BIAS_80>+8000) ||              \
00592          ((y)->fphi.exponent-BIAS_80<-8000) ||              \
00593          ((y)->fphi.exponent-BIAS_80>+8000) )               \
00594     {                                                       \
00595         __libm_normalizel_k80(x);                           \
00596         __libm_normalizel_k80(y);                           \
00597     }                                                       \
00598     __LIBM_SUBL_K80(r,x,y, t1)
00599 
00600 /* Multiplication: x*y                                      */
00601 /* The result is sum rhi+rlo                                */
00602 /* Here t32 is the constant 2^32+1                          */
00603 /* Temporary variables: t1,t2,t3,t4,t5,t6                   */
00604 /* All variables are in long double precision               */
00605 /* Correct if no over/underflow (algorithm by T.J.Dekker)   */
00606 #define __LIBM_MULL1_K80(rhi,rlo,x,y,                       \
00607                                      t32,t1,t2,t3,t4,t5,t6) \
00608     t1=(x)*(t32); t3=x-t1; t3=t3+t1; t4=x-t3;               \
00609     t1=(y)*(t32); t5=y-t1; t5=t5+t1; t6=y-t5;               \
00610     t1=(t3)*(t5);                                           \
00611     t2=(t3)*(t6)+(t4)*(t5);                                 \
00612     rhi=t1+t2;                                              \
00613     rlo=t1-rhi; rlo=rlo+t2; rlo=rlo+(t4*t6);
00614 
00615 /* Multiplication: (xhi+xlo)*(yhi+ylo)                      */
00616 /* The result is sum rhi+rlo                                */
00617 /* Here t32 is the constant 2^32+1                          */
00618 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8             */
00619 /* All variables are in long double precision               */
00620 /* Correct if no over/underflow (algorithm by T.J.Dekker)   */
00621 #define __LIBM_MULL2_K80(rhi,rlo,xhi,xlo,yhi,ylo,           \
00622                                t32,t1,t2,t3,t4,t5,t6,t7,t8) \
00623     __LIBM_MULL1_K80(t7,t8,xhi,yhi, t32,t1,t2,t3,t4,t5,t6)  \
00624     t1=(xhi)*(ylo)+(xlo)*(yhi); t1=t1+t8;                   \
00625     rhi=t7+t1;                                              \
00626     rlo=t7-rhi; rlo=rlo+t1;
00627 
00628 /* Multiplication: r=x*y                                    */
00629 /* Variables r,x,y are pointers to struct ker80,            */
00630 /* all other variables are in long double precision         */
00631 /* Here t32 is the constant 2^32+1                          */
00632 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8             */
00633 /* Correct if x and y belong to interval [2^-8000;2^8000]   */
00634 #define __LIBM_MULL_K80(r,x,y, t32,t1,t2,t3,t4,t5,t6,t7,t8) \
00635     (r)->ex = (x)->ex + (y)->ex;                            \
00636     __LIBM_MULL2_K80((r)->ldhi,(r)->ldlo,                   \
00637         (x)->ldhi,(x)->ldlo,(y)->ldhi,(y)->ldlo,            \
00638         t32,t1,t2,t3,t4,t5,t6,t7,t8)
00639 
00640 /* Multiplication: r=x*y                                    */
00641 /* Variables r,x,y are pointers to struct ker80,            */
00642 /* all other variables are in long double precision         */
00643 /* Here t32 is the constant 2^32+1                          */
00644 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8             */
00645 /* Correct for any finite x and y                           */
00646 #define __LIBM_MULL_NORM_K80(r,x,y,                         \
00647                                t32,t1,t2,t3,t4,t5,t6,t7,t8) \
00648     if ( ((x)->fphi.exponent-BIAS_80<-8000) ||              \
00649          ((x)->fphi.exponent-BIAS_80>+8000) ||              \
00650          ((y)->fphi.exponent-BIAS_80<-8000) ||              \
00651          ((y)->fphi.exponent-BIAS_80>+8000) )               \
00652     {                                                       \
00653         __libm_normalizel_k80(x);                           \
00654         __libm_normalizel_k80(y);                           \
00655     }                                                       \
00656     __LIBM_MULL_K80(r,x,y, t32,t1,t2,t3,t4,t5,t6,t7,t8)
00657 
00658 /* Division: (xhi+xlo)/(yhi+ylo)                            */
00659 /* The result is sum rhi+rlo                                */
00660 /* Here t32 is the constant 2^32+1                          */
00661 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8,t9          */
00662 /* All variables are in long double precision               */
00663 /* Correct if no over/underflow (algorithm by T.J.Dekker)   */
00664 #define __LIBM_DIVL2_K80(rhi,rlo,xhi,xlo,yhi,ylo,           \
00665                             t32,t1,t2,t3,t4,t5,t6,t7,t8,t9) \
00666     t7=(xhi)/(yhi);                                         \
00667     __LIBM_MULL1_K80(t8,t9,t7,yhi, t32,t1,t2,t3,t4,t5,t6)   \
00668     t1=xhi-t8; t1=t1-t9; t1=t1+xlo; t1=t1-(t7)*(ylo);       \
00669     t1=(t1)/(yhi);                                          \
00670     rhi=t7+t1;                                              \
00671     rlo=t7-rhi; rlo=rlo+t1;
00672 
00673 /* Division: r=x/y                                          */
00674 /* Variables r,x,y are pointers to struct ker80,            */
00675 /* all other variables are in long double precision         */
00676 /* Here t32 is the constant 2^32+1                          */
00677 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8,t9          */
00678 /* Correct if x and y belong to interval [2^-8000;2^8000]   */
00679 #define __LIBM_DIVL_K80(r,x,y,                              \
00680                             t32,t1,t2,t3,t4,t5,t6,t7,t8,t9) \
00681     (r)->ex = (x)->ex - (y)->ex;                            \
00682     __LIBM_DIVL2_K80( (r)->ldhi,(r)->ldlo,                  \
00683         (x)->ldhi,(x)->ldlo,(y)->ldhi,(y)->ldlo,            \
00684         t32,t1,t2,t3,t4,t5,t6,t7,t8,t9)
00685 
00686 /* Division: r=x/y                                          */
00687 /* Variables r,x,y are pointers to struct ker80,            */
00688 /* all other variables are in long double precision         */
00689 /* Here t32 is the constant 2^32+1                          */
00690 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8             */
00691 /* Correct for any finite x and y                           */
00692 #define __LIBM_DIVL_NORM_K80(r,x,y,                         \
00693                             t32,t1,t2,t3,t4,t5,t6,t7,t8,t9) \
00694     if ( ((x)->fphi.exponent-BIAS_80<-8000) ||              \
00695          ((x)->fphi.exponent-BIAS_80>+8000) ||              \
00696          ((y)->fphi.exponent-BIAS_80<-8000) ||              \
00697          ((y)->fphi.exponent-BIAS_80>+8000) )               \
00698     {                                                       \
00699         __libm_normalizel_k80(x);                           \
00700         __libm_normalizel_k80(y);                           \
00701     }                                                       \
00702     __LIBM_DIVL_K80(r,x,y, t32,t1,t2,t3,t4,t5,t6,t7,t8,t9)
00703 
00704 /* Square root: sqrt(xhi+xlo)                               */
00705 /* The result is sum rhi+rlo                                */
00706 /* Here t32 is the constant 2^32+1                          */
00707 /*      half is the constant 0.5                            */
00708 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8,t9          */
00709 /* All variables are in long double precision               */
00710 /* Correct for positive xhi+xlo (algorithm by T.J.Dekker)   */
00711 #define __LIBM_SQRTL2_NORM_K80(rhi,rlo,xhi,xlo,             \
00712                        t32,half,t1,t2,t3,t4,t5,t6,t7,t8,t9) \
00713     t7=sqrtl(xhi);                                          \
00714     __LIBM_MULL1_K80(t8,t9,t7,t7, t32,t1,t2,t3,t4,t5,t6)    \
00715     t1=xhi-t8; t1=t1-t9; t1=t1+xlo; t1=(t1)*(half);         \
00716     t1=(t1)/(t7);                                           \
00717     rhi=t7+t1;                                              \
00718     rlo=t7-rhi; rlo=rlo+t1;
00719 
00720 /* Square root: r=sqrt(x)                                   */
00721 /* Variables r,x,y are pointers to struct ker80,            */
00722 /* all other variables are in long double precision         */
00723 /* Here t32 is the constant 2^32+1                          */
00724 /*      half is the constant 0.5                            */
00725 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8,t9          */
00726 /* Correct if x belongs to interval [2^-16000;2^16000]      */
00727 #define __LIBM_SQRTL_K80(r,x,                               \
00728                        t32,half,t1,t2,t3,t4,t5,t6,t7,t8,t9) \
00729     if ( ((x)->ex & 1) == 1 ) {                             \
00730         (x)->ex    = (x)->ex + 1;                           \
00731         (x)->ldhi *= half;                                  \
00732         (x)->ldlo *= half;                                  \
00733     }                                                       \
00734     (r)->ex = (x)->ex >> 1;                                 \
00735     __LIBM_SQRTL2_NORM_K80( (r)->ldhi,(r)->ldlo,            \
00736         (x)->ldhi,(x)->ldlo,                                \
00737         t32,half,t1,t2,t3,t4,t5,t6,t7,t8,t9)
00738 
00739 /* Square root: r=sqrt(x)                                   */
00740 /* Variables r,x,y are pointers to struct ker80,            */
00741 /* all other variables are in long double precision         */
00742 /* Here t32 is the constant 2^32+1                          */
00743 /*      half is the constant 0.5                            */
00744 /* Temporary variables: t1,t2,t3,t4,t5,t6,t7,t8,t9          */
00745 /* Correct for any positive x                               */
00746 #define __LIBM_SQRTL_NORM_K80(r,x,                          \
00747                        t32,half,t1,t2,t3,t4,t5,t6,t7,t8,t9) \
00748     if ( ((x)->fphi.exponent-BIAS_80<-16000) ||             \
00749          ((x)->fphi.exponent-BIAS_80>+16000) )              \
00750     {                                                       \
00751         __libm_normalizel_k80(x);                           \
00752     }                                                       \
00753     __LIBM_SQRTL_K80(r,x, t32,half,t1,t2,t3,t4,t5,t6,t7,t8,t9)
00754 
00755 
00756 #ifdef __INTEL_COMPILER
00757 #define ALIGN(n) __declspec(align(n))
00758 #else /* __INTEL_COMPILER */
00759 #define ALIGN(n)
00760 #endif /* __INTEL_COMPILER */
00761 
00762 /* macros to form a long double value in hex representation (unsigned short type) */
00763 
00764 #if (defined(__unix__) && defined(__i386__))
00765 # define LDOUBLE_ALIGN 12   /* IA32 Linux: 12-byte alignment */
00766 #else  /*__linux__ & IA32*/
00767 # define LDOUBLE_ALIGN 16   /* EFI2/IA32 Win or IPF Win/Linux: 16-byte alignment */
00768 #endif /*__linux__ & IA32*/
00769 
00770 #if (LDOUBLE_ALIGN == 16)
00771 #define _XPD_ ,0x0000,0x0000,0x0000
00772 #else /*12*/
00773 #define _XPD_ ,0x0000
00774 #endif
00775 
00776 #define LDOUBLE_HEX(w4,w3,w2,w1,w0) 0x##w0,0x##w1,0x##w2,0x##w3,0x##w4 _XPD_ /*LITTLE_ENDIAN*/
00777 
00778 /* macros to sign-expand low 'num' bits of 'val' to native integer */
00779 
00780 #if defined(SIZE_INT_32)
00781 # define SIGN_EXPAND(val,num)  ((int)(val) << (32-(num))) >> (32-(num)) /* sign expand of 'num' LSBs */
00782 #elif defined(SIZE_INT_64)
00783 # define SIGN_EXPAND(val,num)  ((int)(val) << (64-(num))) >> (64-(num)) /* sign expand of 'num' LSBs */
00784 #endif
00785 
00786 /* macros to form pointers to FP number on-the-fly */
00787 
00788 #define FP32(f)  ((struct fp32 *)&f)
00789 #define FP64(d)  ((struct fp64 *)&d)
00790 #define FP80(ld) ((struct fp80 *)&ld)
00791 
00792 /* macros to extract signed low and high doubleword of long double */
00793 
00794 #if defined(SIZE_INT_32)
00795 # define HI_DWORD_80(ld) ((((FP80(ld)->sign << 15) | FP80(ld)->exponent) << 16) | \
00796                           ((FP80(ld)->hi_significand >> 16) & 0xFFFF))
00797 # define LO_DWORD_80(ld) SIGN_EXPAND(FP80(ld)->lo_significand, 32)
00798 #elif defined(SIZE_INT_64)
00799 # define HI_DWORD_80(ld) ((((FP80(ld)->sign << 15) | FP80(ld)->exponent) << 16) | \
00800                           ((FP80(ld)->significand >> 48) & 0xFFFF))
00801 # define LO_DWORD_80(ld) SIGN_EXPAND(FP80(ld)->significand, 32)
00802 #endif
00803 
00804 /* macros to extract hi bits of significand.
00805  * note that explicit high bit do not count (returns as is)
00806  */
00807 
00808 #if defined(SIZE_INT_32)
00809 # define HI_SIGNIFICAND_80(X,NBITS) ((X)->hi_significand >> (31 - (NBITS)))
00810 #elif defined(SIZE_INT_64)
00811 # define HI_SIGNIFICAND_80(X,NBITS) ((X)->significand >> (63 - (NBITS)))
00812 #endif
00813 
00814 /* macros to check, whether a significand bits are all zero, or some of them are non-zero.
00815  * note that SIGNIFICAND_ZERO_80 tests high bit also, but SIGNIFICAND_NONZERO_80 does not
00816  */
00817 
00818 #define SIGNIFICAND_ZERO_32(X)     ((X)->significand == 0)
00819 #define SIGNIFICAND_NONZERO_32(X)  ((X)->significand != 0)
00820 
00821 #if defined(SIZE_INT_32)
00822 # define SIGNIFICAND_ZERO_64(X)    (((X)->hi_significand == 0) && ((X)->lo_significand == 0))
00823 # define SIGNIFICAND_NONZERO_64(X) (((X)->hi_significand != 0) || ((X)->lo_significand != 0))
00824 #elif defined(SIZE_INT_64)
00825 # define SIGNIFICAND_ZERO_64(X)    ((X)->significand == 0)
00826 # define SIGNIFICAND_NONZERO_64(X) ((X)->significand != 0)
00827 #endif
00828 
00829 #if defined(SIZE_INT_32)
00830 # define SIGNIFICAND_ZERO_80(X)    (((X)->hi_significand == 0x00000000) && ((X)->lo_significand == 0))
00831 # define SIGNIFICAND_NONZERO_80(X) (((X)->hi_significand != 0x80000000) || ((X)->lo_significand != 0))
00832 #elif defined(SIZE_INT_64)
00833 # define SIGNIFICAND_ZERO_80(X)    ((X)->significand == 0x0000000000000000)
00834 # define SIGNIFICAND_NONZERO_80(X) ((X)->significand != 0x8000000000000000)
00835 #endif
00836 
00837 /* macros to compare long double with constant value, represented as hex */
00838 
00839 #define SIGNIFICAND_EQ_HEX_32(X,BITS) ((X)->significand == 0x ## BITS)
00840 #define SIGNIFICAND_GT_HEX_32(X,BITS) ((X)->significand >  0x ## BITS)
00841 #define SIGNIFICAND_GE_HEX_32(X,BITS) ((X)->significand >= 0x ## BITS)
00842 #define SIGNIFICAND_LT_HEX_32(X,BITS) ((X)->significand <  0x ## BITS)
00843 #define SIGNIFICAND_LE_HEX_32(X,BITS) ((X)->significand <= 0x ## BITS)
00844 
00845 #if defined(SIZE_INT_32)
00846 # define SIGNIFICAND_EQ_HEX_64(X,HI,LO) \
00847     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand == 0x ## LO))
00848 # define SIGNIFICAND_GT_HEX_64(X,HI,LO) (((X)->hi_significand > 0x ## HI) || \
00849     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand >  0x ## LO)))
00850 # define SIGNIFICAND_GE_HEX_64(X,HI,LO) (((X)->hi_significand > 0x ## HI) || \
00851     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand >= 0x ## LO)))
00852 # define SIGNIFICAND_LT_HEX_64(X,HI,LO) (((X)->hi_significand < 0x ## HI) || \
00853     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand <  0x ## LO)))
00854 # define SIGNIFICAND_LE_HEX_64(X,HI,LO) (((X)->hi_significand < 0x ## HI) || \
00855     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand <= 0x ## LO)))
00856 #elif defined(SIZE_INT_64)
00857 # define SIGNIFICAND_EQ_HEX_64(X,HI,LO) ((X)->significand == 0x ## HI ## LO)
00858 # define SIGNIFICAND_GT_HEX_64(X,HI,LO) ((X)->significand >  0x ## HI ## LO)
00859 # define SIGNIFICAND_GE_HEX_64(X,HI,LO) ((X)->significand >= 0x ## HI ## LO)
00860 # define SIGNIFICAND_LT_HEX_64(X,HI,LO) ((X)->significand <  0x ## HI ## LO)
00861 # define SIGNIFICAND_LE_HEX_64(X,HI,LO) ((X)->significand <= 0x ## HI ## LO)
00862 #endif
00863 
00864 #if defined(SIZE_INT_32)
00865 # define SIGNIFICAND_EQ_HEX_80(X,HI,LO) \
00866     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand == 0x ## LO))
00867 # define SIGNIFICAND_GT_HEX_80(X,HI,LO) (((X)->hi_significand > 0x ## HI) || \
00868     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand >  0x ## LO)))
00869 # define SIGNIFICAND_GE_HEX_80(X,HI,LO) (((X)->hi_significand > 0x ## HI) || \
00870     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand >= 0x ## LO)))
00871 # define SIGNIFICAND_LT_HEX_80(X,HI,LO) (((X)->hi_significand < 0x ## HI) || \
00872     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand <  0x ## LO)))
00873 # define SIGNIFICAND_LE_HEX_80(X,HI,LO) (((X)->hi_significand < 0x ## HI) || \
00874     (((X)->hi_significand == 0x ## HI) && ((X)->lo_significand <= 0x ## LO)))
00875 #elif defined(SIZE_INT_64)
00876 # define SIGNIFICAND_EQ_HEX_80(X,HI,LO) ((X)->significand == 0x ## HI ## LO)
00877 # define SIGNIFICAND_GT_HEX_80(X,HI,LO) ((X)->significand >  0x ## HI ## LO)
00878 # define SIGNIFICAND_GE_HEX_80(X,HI,LO) ((X)->significand >= 0x ## HI ## LO)
00879 # define SIGNIFICAND_LT_HEX_80(X,HI,LO) ((X)->significand <  0x ## HI ## LO)
00880 # define SIGNIFICAND_LE_HEX_80(X,HI,LO) ((X)->significand <= 0x ## HI ## LO)
00881 #endif
00882 
00883 #define VALUE_EQ_HEX_32(X,EXP,BITS) \
00884    (((X)->exponent == (EXP)) && (SIGNIFICAND_EQ_HEX_32(X, BITS)))
00885 #define VALUE_GT_HEX_32(X,EXP,BITS) (((X)->exponent > (EXP)) || \
00886    (((X)->exponent == (EXP)) && (SIGNIFICAND_GT_HEX_32(X, BITS))))
00887 #define VALUE_GE_HEX_32(X,EXP,BITS) (((X)->exponent > (EXP)) || \
00888    (((X)->exponent == (EXP)) && (SIGNIFICAND_GE_HEX_32(X, BITS))))
00889 #define VALUE_LT_HEX_32(X,EXP,BITS) (((X)->exponent < (EXP)) || \
00890    (((X)->exponent == (EXP)) && (SIGNIFICAND_LT_HEX_32(X, BITS))))
00891 #define VALUE_LE_HEX_32(X,EXP,BITS) (((X)->exponent < (EXP)) || \
00892    (((X)->exponent == (EXP)) && (SIGNIFICAND_LE_HEX_32(X, BITS))))
00893 
00894 #define VALUE_EQ_HEX_64(X,EXP,HI,LO) \
00895    (((X)->exponent == (EXP)) && (SIGNIFICAND_EQ_HEX_64(X, HI, LO)))
00896 #define VALUE_GT_HEX_64(X,EXP,HI,LO) (((X)->exponent > (EXP)) || \
00897    (((X)->exponent == (EXP)) && (SIGNIFICAND_GT_HEX_64(X, HI, LO))))
00898 #define VALUE_GE_HEX_64(X,EXP,HI,LO) (((X)->exponent > (EXP)) || \
00899    (((X)->exponent == (EXP)) && (SIGNIFICAND_GE_HEX_64(X, HI, LO))))
00900 #define VALUE_LT_HEX_64(X,EXP,HI,LO) (((X)->exponent < (EXP)) || \
00901    (((X)->exponent == (EXP)) && (SIGNIFICAND_LT_HEX_64(X, HI, LO))))
00902 #define VALUE_LE_HEX_64(X,EXP,HI,LO) (((X)->exponent < (EXP)) || \
00903    (((X)->exponent == (EXP)) && (SIGNIFICAND_LE_HEX_64(X, HI, LO))))
00904 
00905 #define VALUE_EQ_HEX_80(X,EXP,HI,LO) \
00906    (((X)->exponent == (EXP)) && (SIGNIFICAND_EQ_HEX_80(X, HI, LO)))
00907 #define VALUE_GT_HEX_80(X,EXP,HI,LO) (((X)->exponent > (EXP)) || \
00908    (((X)->exponent == (EXP)) && (SIGNIFICAND_GT_HEX_80(X, HI, LO))))
00909 #define VALUE_GE_HEX_80(X,EXP,HI,LO) (((X)->exponent > (EXP)) || \
00910    (((X)->exponent == (EXP)) && (SIGNIFICAND_GE_HEX_80(X, HI, LO))))
00911 #define VALUE_LT_HEX_80(X,EXP,HI,LO) (((X)->exponent < (EXP)) || \
00912    (((X)->exponent == (EXP)) && (SIGNIFICAND_LT_HEX_80(X, HI, LO))))
00913 #define VALUE_LE_HEX_80(X,EXP,HI,LO) (((X)->exponent < (EXP)) || \
00914    (((X)->exponent == (EXP)) && (SIGNIFICAND_LE_HEX_80(X, HI, LO))))
00915 
00916 /* macros to compare two long doubles */
00917 
00918 #define SIGNIFICAND_EQ_32(X,Y) ((X)->significand == (Y)->significand)
00919 #define SIGNIFICAND_GT_32(X,Y) ((X)->significand > (Y)->significand)
00920 #define SIGNIFICAND_GE_32(X,Y) ((X)->significand >= (Y)->significand)
00921 #define SIGNIFICAND_LT_32(X,Y) ((X)->significand < (Y)->significand)
00922 #define SIGNIFICAND_LE_32(X,Y) ((X)->significand <= (Y)->significand)
00923 
00924 #if defined(SIZE_INT_32)
00925 # define SIGNIFICAND_EQ_64(X,Y) \
00926   (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand == (Y)->lo_significand))
00927 # define SIGNIFICAND_GT_64(X,Y) (((X)->hi_significand > (Y)->hi_significand) || \
00928   (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand >  (Y)->lo_significand)))
00929 # define SIGNIFICAND_GE_64(X,Y) (((X)->hi_significand > (Y)->hi_significand) || \
00930   (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand >= (Y)->lo_significand)))
00931 # define SIGNIFICAND_LT_64(X,Y) (((X)->hi_significand < (Y)->hi_significand) || \
00932   (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand <  (Y)->lo_significand)))
00933 # define SIGNIFICAND_LE_64(X,Y) (((X)->hi_significand < (Y)->hi_significand) || \
00934   (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand <= (Y)->lo_significand)))
00935 #elif defined(SIZE_INT_64)
00936 # define SIGNIFICAND_EQ_64(X,Y) ((X)->significand == (Y)->significand)
00937 # define SIGNIFICAND_GT_64(X,Y) ((X)->significand >  (Y)->significand)
00938 # define SIGNIFICAND_GE_64(X,Y) ((X)->significand >= (Y)->significand)
00939 # define SIGNIFICAND_LT_64(X,Y) ((X)->significand <  (Y)->significand)
00940 # define SIGNIFICAND_LE_64(X,Y) ((X)->significand <= (Y)->significand)
00941 #endif
00942 
00943 #if defined(SIZE_INT_32)
00944 # define SIGNIFICAND_EQ_80(X,Y) \
00945     (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand == (Y)->lo_significand))
00946 # define SIGNIFICAND_GT_80(X,Y) (((X)->hi_significand > (Y)->hi_significand) || \
00947     (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand >  (Y)->lo_significand)))
00948 # define SIGNIFICAND_GE_80(X,Y) (((X)->hi_significand > (Y)->hi_significand) || \
00949     (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand >= (Y)->lo_significand)))
00950 # define SIGNIFICAND_LT_80(X,Y) (((X)->hi_significand < (Y)->hi_significand) || \
00951     (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand <  (Y)->lo_significand)))
00952 # define SIGNIFICAND_LE_80(X,Y) (((X)->hi_significand < (Y)->hi_significand) || \
00953     (((X)->hi_significand == (Y)->hi_significand) && ((X)->lo_significand <= (Y)->lo_significand)))
00954 #elif defined(SIZE_INT_64)
00955 # define SIGNIFICAND_EQ_80(X,Y) ((X)->significand == (Y)->significand)
00956 # define SIGNIFICAND_GT_80(X,Y) ((X)->significand >  (Y)->significand)
00957 # define SIGNIFICAND_GE_80(X,Y) ((X)->significand >= (Y)->significand)
00958 # define SIGNIFICAND_LT_80(X,Y) ((X)->significand <  (Y)->significand)
00959 # define SIGNIFICAND_LE_80(X,Y) ((X)->significand <= (Y)->significand)
00960 #endif
00961 
00962 #define VALUE_EQ_32(X,Y) \
00963    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_EQ_32(X, Y)))
00964 #define VALUE_GT_32(X,Y) (((X)->exponent > (Y)->exponent) || \
00965    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_GT_32(X, Y))))
00966 #define VALUE_GE_32(X,Y) (((X)->exponent > (Y)->exponent) || \
00967    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_GE_32(X, Y))))
00968 #define VALUE_LT_32(X,Y) (((X)->exponent < (Y)->exponent) || \
00969    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_LT_32(X, Y))))
00970 #define VALUE_LE_32(X,Y) (((X)->exponent < (Y)->exponent) || \
00971    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_LE_32(X, Y))))
00972 
00973 #define VALUE_EQ_64(X,Y) \
00974    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_EQ_64(X, Y)))
00975 #define VALUE_GT_64(X,Y) (((X)->exponent > (Y)->exponent) || \
00976    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_GT_64(X, Y))))
00977 #define VALUE_GE_64(X,Y) (((X)->exponent > (Y)->exponent) || \
00978    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_GE_64(X, Y))))
00979 #define VALUE_LT_64(X,Y) (((X)->exponent < (Y)->exponent) || \
00980    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_LT_64(X, Y))))
00981 #define VALUE_LE_64(X,Y) (((X)->exponent < (Y)->exponent) || \
00982    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_LE_64(X, Y))))
00983 
00984 #define VALUE_EQ_80(X,Y) \
00985    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_EQ_80(X, Y)))
00986 #define VALUE_GT_80(X,Y) (((X)->exponent > (Y)->exponent) || \
00987    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_GT_80(X, Y))))
00988 #define VALUE_GE_80(X,Y) (((X)->exponent > (Y)->exponent) || \
00989    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_GE_80(X, Y))))
00990 #define VALUE_LT_80(X,Y) (((X)->exponent < (Y)->exponent) || \
00991    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_LT_80(X, Y))))
00992 #define VALUE_LE_80(X,Y) (((X)->exponent < (Y)->exponent) || \
00993    (((X)->exponent == (Y)->exponent) && (SIGNIFICAND_LE_80(X, Y))))
00994 
00995 /* add/subtract 1 ulp macros */
00996 
00997 #if defined(SIZE_INT_32)
00998 # define ADD_ULP_80(X) \
00999     if ((++(X)->lo_significand == 0) && \
01000         (++(X)->hi_significand == (((X)->exponent == 0) ? 0x80000000 : 0))) \
01001     { \
01002         (X)->hi_significand |= 0x80000000; \
01003         ++(X)->exponent; \
01004     }
01005 # define SUB_ULP_80(X) \
01006     if (--(X)->lo_significand == 0xFFFFFFFF) { \
01007         --(X)->hi_significand; \
01008         if (((X)->exponent != 0) && \
01009             ((X)->hi_significand == 0x7FFFFFFF) && \
01010             (--(X)->exponent != 0)) \
01011         { \
01012             (X)->hi_significand |= 0x80000000; \
01013         } \
01014     }
01015 #elif defined(SIZE_INT_64)
01016 # define ADD_ULP_80(X) \
01017     if (++(X)->significand == (((X)->exponent == 0) ? 0x8000000000000000 : 0))) { \
01018         (X)->significand |= 0x8000000000000000; \
01019         ++(X)->exponent; \
01020     }
01021 # define SUB_ULP_80(X) \
01022     { \
01023         --(X)->significand; \
01024         if (((X)->exponent != 0) && \
01025             ((X)->significand == 0x7FFFFFFFFFFFFFFF) && \
01026             (--(X)->exponent != 0)) \
01027         { \
01028             (X)->significand |= 0x8000000000000000; \
01029         } \
01030     }
01031 #endif
01032 
01033 
01034 /* error codes */
01035 
01036 #define DOMAIN     1   /* argument domain error */
01037 #define SING       2   /* argument singularity */
01038 #define OVERFLOW   3   /* overflow range error */
01039 #define UNDERFLOW  4   /* underflow range error */
01040 #define TLOSS      5   /* total loss of precision */
01041 #define PLOSS      6   /* partial loss of precision */
01042 
01043 /* */
01044 
01045 #define VOLATILE_32 /*volatile*/
01046 #define VOLATILE_64 /*volatile*/
01047 #define VOLATILE_80 /*volatile*/
01048 
01049 #define QUAD_TYPE _Quad
01050 
01051 #endif    /*__LIBM_SUPPORT_H_INCLUDED__*/