Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / ieee754 / dbl-64 / dla.h
blobc92fcfe348ca44cc38360ff1aa7765dace942e3c
1 /*
2 * IBM Accurate Mathematical Library
3 * Written by International Business Machines Corp.
4 * Copyright (C) 2001, 2011 Free Software Foundation, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /***********************************************************************/
21 /*MODULE_NAME: dla.h */
22 /* */
23 /* This file holds C language macros for 'Double Length Floating Point */
24 /* Arithmetic'. The macros are based on the paper: */
25 /* T.J.Dekker, "A floating-point Technique for extending the */
26 /* Available Precision", Number. Math. 18, 224-242 (1971). */
27 /* A Double-Length number is defined by a pair (r,s), of IEEE double */
28 /* precision floating point numbers that satisfy, */
29 /* */
30 /* abs(s) <= abs(r+s)*2**(-53)/(1+2**(-53)). */
31 /* */
32 /* The computer arithmetic assumed is IEEE double precision in */
33 /* round to nearest mode. All variables in the macros must be of type */
34 /* IEEE double. */
35 /***********************************************************************/
37 /* CN = 1+2**27 = '41a0000002000000' IEEE double format */
38 #define CN 134217729.0
41 /* Exact addition of two single-length floating point numbers, Dekker. */
42 /* The macro produces a double-length number (z,zz) that satisfies */
43 /* z+zz = x+y exactly. */
45 #define EADD(x,y,z,zz) \
46 z=(x)+(y); zz=(ABS(x)>ABS(y)) ? (((x)-(z))+(y)) : (((y)-(z))+(x));
49 /* Exact subtraction of two single-length floating point numbers, Dekker. */
50 /* The macro produces a double-length number (z,zz) that satisfies */
51 /* z+zz = x-y exactly. */
53 #define ESUB(x,y,z,zz) \
54 z=(x)-(y); zz=(ABS(x)>ABS(y)) ? (((x)-(z))-(y)) : ((x)-((y)+(z)));
57 /* Exact multiplication of two single-length floating point numbers, */
58 /* Veltkamp. The macro produces a double-length number (z,zz) that */
59 /* satisfies z+zz = x*y exactly. p,hx,tx,hy,ty are temporary */
60 /* storage variables of type double. */
62 #ifdef DLA_FMS
63 # define EMULV(x,y,z,zz,p,hx,tx,hy,ty) \
64 z=x*y; zz=DLA_FMS(x,y,z);
65 #else
66 # define EMULV(x,y,z,zz,p,hx,tx,hy,ty) \
67 p=CN*(x); hx=((x)-p)+p; tx=(x)-hx; \
68 p=CN*(y); hy=((y)-p)+p; ty=(y)-hy; \
69 z=(x)*(y); zz=(((hx*hy-z)+hx*ty)+tx*hy)+tx*ty;
70 #endif
73 /* Exact multiplication of two single-length floating point numbers, Dekker. */
74 /* The macro produces a nearly double-length number (z,zz) (see Dekker) */
75 /* that satisfies z+zz = x*y exactly. p,hx,tx,hy,ty,q are temporary */
76 /* storage variables of type double. */
78 #ifdef DLA_FMS
79 # define MUL12(x,y,z,zz,p,hx,tx,hy,ty,q) \
80 EMULV(x,y,z,zz,p,hx,tx,hy,ty)
81 #else
82 # define MUL12(x,y,z,zz,p,hx,tx,hy,ty,q) \
83 p=CN*(x); hx=((x)-p)+p; tx=(x)-hx; \
84 p=CN*(y); hy=((y)-p)+p; ty=(y)-hy; \
85 p=hx*hy; q=hx*ty+tx*hy; z=p+q; zz=((p-z)+q)+tx*ty;
86 #endif
89 /* Double-length addition, Dekker. The macro produces a double-length */
90 /* number (z,zz) which satisfies approximately z+zz = x+xx + y+yy. */
91 /* An error bound: (abs(x+xx)+abs(y+yy))*4.94e-32. (x,xx), (y,yy) */
92 /* are assumed to be double-length numbers. r,s are temporary */
93 /* storage variables of type double. */
95 #define ADD2(x,xx,y,yy,z,zz,r,s) \
96 r=(x)+(y); s=(ABS(x)>ABS(y)) ? \
97 (((((x)-r)+(y))+(yy))+(xx)) : \
98 (((((y)-r)+(x))+(xx))+(yy)); \
99 z=r+s; zz=(r-z)+s;
102 /* Double-length subtraction, Dekker. The macro produces a double-length */
103 /* number (z,zz) which satisfies approximately z+zz = x+xx - (y+yy). */
104 /* An error bound: (abs(x+xx)+abs(y+yy))*4.94e-32. (x,xx), (y,yy) */
105 /* are assumed to be double-length numbers. r,s are temporary */
106 /* storage variables of type double. */
108 #define SUB2(x,xx,y,yy,z,zz,r,s) \
109 r=(x)-(y); s=(ABS(x)>ABS(y)) ? \
110 (((((x)-r)-(y))-(yy))+(xx)) : \
111 ((((x)-((y)+r))+(xx))-(yy)); \
112 z=r+s; zz=(r-z)+s;
115 /* Double-length multiplication, Dekker. The macro produces a double-length */
116 /* number (z,zz) which satisfies approximately z+zz = (x+xx)*(y+yy). */
117 /* An error bound: abs((x+xx)*(y+yy))*1.24e-31. (x,xx), (y,yy) */
118 /* are assumed to be double-length numbers. p,hx,tx,hy,ty,q,c,cc are */
119 /* temporary storage variables of type double. */
121 #define MUL2(x,xx,y,yy,z,zz,p,hx,tx,hy,ty,q,c,cc) \
122 MUL12(x,y,c,cc,p,hx,tx,hy,ty,q) \
123 cc=((x)*(yy)+(xx)*(y))+cc; z=c+cc; zz=(c-z)+cc;
126 /* Double-length division, Dekker. The macro produces a double-length */
127 /* number (z,zz) which satisfies approximately z+zz = (x+xx)/(y+yy). */
128 /* An error bound: abs((x+xx)/(y+yy))*1.50e-31. (x,xx), (y,yy) */
129 /* are assumed to be double-length numbers. p,hx,tx,hy,ty,q,c,cc,u,uu */
130 /* are temporary storage variables of type double. */
132 #define DIV2(x,xx,y,yy,z,zz,p,hx,tx,hy,ty,q,c,cc,u,uu) \
133 c=(x)/(y); MUL12(c,y,u,uu,p,hx,tx,hy,ty,q) \
134 cc=(((((x)-u)-uu)+(xx))-c*(yy))/(y); z=c+cc; zz=(c-z)+cc;
137 /* Double-length addition, slower but more accurate than ADD2. */
138 /* The macro produces a double-length */
139 /* number (z,zz) which satisfies approximately z+zz = (x+xx)+(y+yy). */
140 /* An error bound: abs(x+xx + y+yy)*1.50e-31. (x,xx), (y,yy) */
141 /* are assumed to be double-length numbers. r,rr,s,ss,u,uu,w */
142 /* are temporary storage variables of type double. */
144 #define ADD2A(x,xx,y,yy,z,zz,r,rr,s,ss,u,uu,w) \
145 r=(x)+(y); \
146 if (ABS(x)>ABS(y)) { rr=((x)-r)+(y); s=(rr+(yy))+(xx); } \
147 else { rr=((y)-r)+(x); s=(rr+(xx))+(yy); } \
148 if (rr!=0.0) { \
149 z=r+s; zz=(r-z)+s; } \
150 else { \
151 ss=(ABS(xx)>ABS(yy)) ? (((xx)-s)+(yy)) : (((yy)-s)+(xx)); \
152 u=r+s; \
153 uu=(ABS(r)>ABS(s)) ? ((r-u)+s) : ((s-u)+r) ; \
154 w=uu+ss; z=u+w; \
155 zz=(ABS(u)>ABS(w)) ? ((u-z)+w) : ((w-z)+u) ; }
158 /* Double-length subtraction, slower but more accurate than SUB2. */
159 /* The macro produces a double-length */
160 /* number (z,zz) which satisfies approximately z+zz = (x+xx)-(y+yy). */
161 /* An error bound: abs(x+xx - (y+yy))*1.50e-31. (x,xx), (y,yy) */
162 /* are assumed to be double-length numbers. r,rr,s,ss,u,uu,w */
163 /* are temporary storage variables of type double. */
165 #define SUB2A(x,xx,y,yy,z,zz,r,rr,s,ss,u,uu,w) \
166 r=(x)-(y); \
167 if (ABS(x)>ABS(y)) { rr=((x)-r)-(y); s=(rr-(yy))+(xx); } \
168 else { rr=(x)-((y)+r); s=(rr+(xx))-(yy); } \
169 if (rr!=0.0) { \
170 z=r+s; zz=(r-z)+s; } \
171 else { \
172 ss=(ABS(xx)>ABS(yy)) ? (((xx)-s)-(yy)) : ((xx)-((yy)+s)); \
173 u=r+s; \
174 uu=(ABS(r)>ABS(s)) ? ((r-u)+s) : ((s-u)+r) ; \
175 w=uu+ss; z=u+w; \
176 zz=(ABS(u)>ABS(w)) ? ((u-z)+w) : ((w-z)+u) ; }