Back to index

glibc  2.9
dla.h
Go to the documentation of this file.
00001 /*
00002  * IBM Accurate Mathematical Library
00003  * Written by International Business Machines Corp.
00004  * Copyright (C) 2001 Free Software Foundation, Inc.
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2.1 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 /***********************************************************************/
00022 /*MODULE_NAME: dla.h                                                   */
00023 /*                                                                     */
00024 /* This file holds C language macros for 'Double Length Floating Point */
00025 /* Arithmetic'. The macros are based on the paper:                     */
00026 /* T.J.Dekker, "A floating-point Technique for extending the           */
00027 /* Available Precision", Number. Math. 18, 224-242 (1971).              */
00028 /* A Double-Length number is defined by a pair (r,s), of IEEE double    */
00029 /* precision floating point numbers that satisfy,                      */
00030 /*                                                                     */
00031 /*              abs(s) <= abs(r+s)*2**(-53)/(1+2**(-53)).              */
00032 /*                                                                     */
00033 /* The computer arithmetic assumed is IEEE double precision in         */
00034 /* round to nearest mode. All variables in the macros must be of type  */
00035 /* IEEE double.                                                        */
00036 /***********************************************************************/
00037 
00038 /* CN = 1+2**27 = '41a0000002000000' IEEE double format */
00039 #define  CN   134217729.0
00040 
00041 
00042 /* Exact addition of two single-length floating point numbers, Dekker. */
00043 /* The macro produces a double-length number (z,zz) that satisfies     */
00044 /* z+zz = x+y exactly.                                                 */
00045 
00046 #define  EADD(x,y,z,zz)  \
00047            z=(x)+(y);  zz=(ABS(x)>ABS(y)) ? (((x)-(z))+(y)) : (((y)-(z))+(x));
00048 
00049 
00050 /* Exact subtraction of two single-length floating point numbers, Dekker. */
00051 /* The macro produces a double-length number (z,zz) that satisfies        */
00052 /* z+zz = x-y exactly.                                                    */
00053 
00054 #define  ESUB(x,y,z,zz)  \
00055            z=(x)-(y);  zz=(ABS(x)>ABS(y)) ? (((x)-(z))-(y)) : ((x)-((y)+(z)));
00056 
00057 
00058 /* Exact multiplication of two single-length floating point numbers,   */
00059 /* Veltkamp. The macro produces a double-length number (z,zz) that     */
00060 /* satisfies z+zz = x*y exactly. p,hx,tx,hy,ty are temporary           */
00061 /* storage variables of type double.                                   */
00062 
00063 #define  EMULV(x,y,z,zz,p,hx,tx,hy,ty)          \
00064            p=CN*(x);  hx=((x)-p)+p;  tx=(x)-hx; \
00065            p=CN*(y);  hy=((y)-p)+p;  ty=(y)-hy; \
00066            z=(x)*(y); zz=(((hx*hy-z)+hx*ty)+tx*hy)+tx*ty;
00067 
00068 
00069 /* Exact multiplication of two single-length floating point numbers, Dekker. */
00070 /* The macro produces a nearly double-length number (z,zz) (see Dekker)      */
00071 /* that satisfies z+zz = x*y exactly. p,hx,tx,hy,ty,q are temporary          */
00072 /* storage variables of type double.                                         */
00073 
00074 #define  MUL12(x,y,z,zz,p,hx,tx,hy,ty,q)        \
00075            p=CN*(x);  hx=((x)-p)+p;  tx=(x)-hx; \
00076            p=CN*(y);  hy=((y)-p)+p;  ty=(y)-hy; \
00077            p=hx*hy;  q=hx*ty+tx*hy; z=p+q;  zz=((p-z)+q)+tx*ty;
00078 
00079 
00080 /* Double-length addition, Dekker. The macro produces a double-length   */
00081 /* number (z,zz) which satisfies approximately   z+zz = x+xx + y+yy.    */
00082 /* An error bound: (abs(x+xx)+abs(y+yy))*4.94e-32. (x,xx), (y,yy)       */
00083 /* are assumed to be double-length numbers. r,s are temporary           */
00084 /* storage variables of type double.                                    */
00085 
00086 #define  ADD2(x,xx,y,yy,z,zz,r,s)                    \
00087            r=(x)+(y);  s=(ABS(x)>ABS(y)) ?           \
00088                        (((((x)-r)+(y))+(yy))+(xx)) : \
00089                        (((((y)-r)+(x))+(xx))+(yy));  \
00090            z=r+s;  zz=(r-z)+s;
00091 
00092 
00093 /* Double-length subtraction, Dekker. The macro produces a double-length  */
00094 /* number (z,zz) which satisfies approximately   z+zz = x+xx - (y+yy).    */
00095 /* An error bound: (abs(x+xx)+abs(y+yy))*4.94e-32. (x,xx), (y,yy)         */
00096 /* are assumed to be double-length numbers. r,s are temporary             */
00097 /* storage variables of type double.                                      */
00098 
00099 #define  SUB2(x,xx,y,yy,z,zz,r,s)                    \
00100            r=(x)-(y);  s=(ABS(x)>ABS(y)) ?           \
00101                        (((((x)-r)-(y))-(yy))+(xx)) : \
00102                        ((((x)-((y)+r))+(xx))-(yy));  \
00103            z=r+s;  zz=(r-z)+s;
00104 
00105 
00106 /* Double-length multiplication, Dekker. The macro produces a double-length  */
00107 /* number (z,zz) which satisfies approximately   z+zz = (x+xx)*(y+yy).       */
00108 /* An error bound: abs((x+xx)*(y+yy))*1.24e-31. (x,xx), (y,yy)               */
00109 /* are assumed to be double-length numbers. p,hx,tx,hy,ty,q,c,cc are         */
00110 /* temporary storage variables of type double.                               */
00111 
00112 #define  MUL2(x,xx,y,yy,z,zz,p,hx,tx,hy,ty,q,c,cc)  \
00113            MUL12(x,y,c,cc,p,hx,tx,hy,ty,q)          \
00114            cc=((x)*(yy)+(xx)*(y))+cc;   z=c+cc;   zz=(c-z)+cc;
00115 
00116 
00117 /* Double-length division, Dekker. The macro produces a double-length        */
00118 /* number (z,zz) which satisfies approximately   z+zz = (x+xx)/(y+yy).       */
00119 /* An error bound: abs((x+xx)/(y+yy))*1.50e-31. (x,xx), (y,yy)               */
00120 /* are assumed to be double-length numbers. p,hx,tx,hy,ty,q,c,cc,u,uu        */
00121 /* are temporary storage variables of type double.                           */
00122 
00123 #define  DIV2(x,xx,y,yy,z,zz,p,hx,tx,hy,ty,q,c,cc,u,uu)  \
00124            c=(x)/(y);   MUL12(c,y,u,uu,p,hx,tx,hy,ty,q)  \
00125            cc=(((((x)-u)-uu)+(xx))-c*(yy))/(y);   z=c+cc;   zz=(c-z)+cc;
00126 
00127 
00128 /* Double-length addition, slower but more accurate than ADD2.               */
00129 /* The macro produces a double-length                                        */
00130 /* number (z,zz) which satisfies approximately   z+zz = (x+xx)+(y+yy).       */
00131 /* An error bound: abs(x+xx + y+yy)*1.50e-31. (x,xx), (y,yy)                 */
00132 /* are assumed to be double-length numbers. r,rr,s,ss,u,uu,w                 */
00133 /* are temporary storage variables of type double.                           */
00134 
00135 #define  ADD2A(x,xx,y,yy,z,zz,r,rr,s,ss,u,uu,w)                        \
00136            r=(x)+(y);                                                  \
00137            if (ABS(x)>ABS(y)) { rr=((x)-r)+(y);  s=(rr+(yy))+(xx); }   \
00138            else               { rr=((y)-r)+(x);  s=(rr+(xx))+(yy); }   \
00139            if (rr!=0.0) {                                              \
00140              z=r+s;  zz=(r-z)+s; }                                     \
00141            else {                                                      \
00142              ss=(ABS(xx)>ABS(yy)) ? (((xx)-s)+(yy)) : (((yy)-s)+(xx)); \
00143              u=r+s;                                                    \
00144              uu=(ABS(r)>ABS(s))   ? ((r-u)+s)   : ((s-u)+r)  ;         \
00145              w=uu+ss;  z=u+w;                                          \
00146              zz=(ABS(u)>ABS(w))   ? ((u-z)+w)   : ((w-z)+u)  ; }
00147 
00148 
00149 /* Double-length subtraction, slower but more accurate than SUB2.            */
00150 /* The macro produces a double-length                                        */
00151 /* number (z,zz) which satisfies approximately   z+zz = (x+xx)-(y+yy).       */
00152 /* An error bound: abs(x+xx - (y+yy))*1.50e-31. (x,xx), (y,yy)               */
00153 /* are assumed to be double-length numbers. r,rr,s,ss,u,uu,w                 */
00154 /* are temporary storage variables of type double.                           */
00155 
00156 #define  SUB2A(x,xx,y,yy,z,zz,r,rr,s,ss,u,uu,w)                        \
00157            r=(x)-(y);                                                  \
00158            if (ABS(x)>ABS(y)) { rr=((x)-r)-(y);  s=(rr-(yy))+(xx); }   \
00159            else               { rr=(x)-((y)+r);  s=(rr+(xx))-(yy); }   \
00160            if (rr!=0.0) {                                              \
00161              z=r+s;  zz=(r-z)+s; }                                     \
00162            else {                                                      \
00163              ss=(ABS(xx)>ABS(yy)) ? (((xx)-s)-(yy)) : ((xx)-((yy)+s)); \
00164              u=r+s;                                                    \
00165              uu=(ABS(r)>ABS(s))   ? ((r-u)+s)   : ((s-u)+r)  ;         \
00166              w=uu+ss;  z=u+w;                                          \
00167              zz=(ABS(u)>ABS(w))   ? ((u-z)+w)   : ((w-z)+u)  ; }
00168 
00169 
00170 
00171 
00172 
00173 
00174