]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/ieee754/dbl-64/dla.h
Merge branch 'master' of ssh://sourceware.org/git/glibc
[thirdparty/glibc.git] / sysdeps / ieee754 / dbl-64 / dla.h
CommitLineData
e4d82761
UD
1/*
2 * IBM Accurate Mathematical Library
c6c6dd48
RM
3 * Written by International Business Machines Corp.
4 * Copyright (C) 2001 Free Software Foundation, Inc.
e4d82761
UD
5 *
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
cc7375ce 8 * the Free Software Foundation; either version 2.1 of the License, or
e4d82761 9 * (at your option) any later version.
c6c6dd48 10 *
e4d82761
UD
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
c6c6dd48 14 * GNU Lesser General Public License for more details.
e4d82761
UD
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
c6c6dd48 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
e4d82761 19 */
c6c6dd48 20
e4d82761
UD
21/***********************************************************************/
22/*MODULE_NAME: dla.h */
23/* */
24/* This file holds C language macros for 'Double Length Floating Point */
25/* Arithmetic'. The macros are based on the paper: */
26/* T.J.Dekker, "A floating-point Technique for extending the */
27/* Available Precision", Number. Math. 18, 224-242 (1971). */
28/* A Double-Length number is defined by a pair (r,s), of IEEE double */
29/* precision floating point numbers that satisfy, */
30/* */
31/* abs(s) <= abs(r+s)*2**(-53)/(1+2**(-53)). */
32/* */
33/* The computer arithmetic assumed is IEEE double precision in */
34/* round to nearest mode. All variables in the macros must be of type */
35/* IEEE double. */
36/***********************************************************************/
37
38/* CN = 1+2**27 = '41a0000002000000' IEEE double format */
39#define CN 134217729.0
40
41
42/* Exact addition of two single-length floating point numbers, Dekker. */
43/* The macro produces a double-length number (z,zz) that satisfies */
44/* z+zz = x+y exactly. */
45
46#define EADD(x,y,z,zz) \
47 z=(x)+(y); zz=(ABS(x)>ABS(y)) ? (((x)-(z))+(y)) : (((y)-(z))+(x));
48
49
50/* Exact subtraction of two single-length floating point numbers, Dekker. */
51/* The macro produces a double-length number (z,zz) that satisfies */
52/* z+zz = x-y exactly. */
53
54#define ESUB(x,y,z,zz) \
55 z=(x)-(y); zz=(ABS(x)>ABS(y)) ? (((x)-(z))-(y)) : ((x)-((y)+(z)));
56
57
58/* Exact multiplication of two single-length floating point numbers, */
59/* Veltkamp. The macro produces a double-length number (z,zz) that */
60/* satisfies z+zz = x*y exactly. p,hx,tx,hy,ty are temporary */
61/* storage variables of type double. */
62
63#define EMULV(x,y,z,zz,p,hx,tx,hy,ty) \
64 p=CN*(x); hx=((x)-p)+p; tx=(x)-hx; \
65 p=CN*(y); hy=((y)-p)+p; ty=(y)-hy; \
66 z=(x)*(y); zz=(((hx*hy-z)+hx*ty)+tx*hy)+tx*ty;
67
68
69/* Exact multiplication of two single-length floating point numbers, Dekker. */
70/* The macro produces a nearly double-length number (z,zz) (see Dekker) */
71/* that satisfies z+zz = x*y exactly. p,hx,tx,hy,ty,q are temporary */
72/* storage variables of type double. */
73
74#define MUL12(x,y,z,zz,p,hx,tx,hy,ty,q) \
75 p=CN*(x); hx=((x)-p)+p; tx=(x)-hx; \
76 p=CN*(y); hy=((y)-p)+p; ty=(y)-hy; \
77 p=hx*hy; q=hx*ty+tx*hy; z=p+q; zz=((p-z)+q)+tx*ty;
78
79
80/* Double-length addition, Dekker. The macro produces a double-length */
81/* number (z,zz) which satisfies approximately z+zz = x+xx + y+yy. */
82/* An error bound: (abs(x+xx)+abs(y+yy))*4.94e-32. (x,xx), (y,yy) */
83/* are assumed to be double-length numbers. r,s are temporary */
84/* storage variables of type double. */
85
86#define ADD2(x,xx,y,yy,z,zz,r,s) \
87 r=(x)+(y); s=(ABS(x)>ABS(y)) ? \
88 (((((x)-r)+(y))+(yy))+(xx)) : \
89 (((((y)-r)+(x))+(xx))+(yy)); \
90 z=r+s; zz=(r-z)+s;
91
92
93/* Double-length subtraction, Dekker. The macro produces a double-length */
94/* number (z,zz) which satisfies approximately z+zz = x+xx - (y+yy). */
95/* An error bound: (abs(x+xx)+abs(y+yy))*4.94e-32. (x,xx), (y,yy) */
96/* are assumed to be double-length numbers. r,s are temporary */
97/* storage variables of type double. */
98
99#define SUB2(x,xx,y,yy,z,zz,r,s) \
100 r=(x)-(y); s=(ABS(x)>ABS(y)) ? \
101 (((((x)-r)-(y))-(yy))+(xx)) : \
102 ((((x)-((y)+r))+(xx))-(yy)); \
103 z=r+s; zz=(r-z)+s;
104
105
106/* Double-length multiplication, Dekker. The macro produces a double-length */
107/* number (z,zz) which satisfies approximately z+zz = (x+xx)*(y+yy). */
108/* An error bound: abs((x+xx)*(y+yy))*1.24e-31. (x,xx), (y,yy) */
109/* are assumed to be double-length numbers. p,hx,tx,hy,ty,q,c,cc are */
110/* temporary storage variables of type double. */
111
112#define MUL2(x,xx,y,yy,z,zz,p,hx,tx,hy,ty,q,c,cc) \
113 MUL12(x,y,c,cc,p,hx,tx,hy,ty,q) \
114 cc=((x)*(yy)+(xx)*(y))+cc; z=c+cc; zz=(c-z)+cc;
115
116
117/* Double-length division, Dekker. The macro produces a double-length */
118/* number (z,zz) which satisfies approximately z+zz = (x+xx)/(y+yy). */
119/* An error bound: abs((x+xx)/(y+yy))*1.50e-31. (x,xx), (y,yy) */
120/* are assumed to be double-length numbers. p,hx,tx,hy,ty,q,c,cc,u,uu */
121/* are temporary storage variables of type double. */
122
123#define DIV2(x,xx,y,yy,z,zz,p,hx,tx,hy,ty,q,c,cc,u,uu) \
124 c=(x)/(y); MUL12(c,y,u,uu,p,hx,tx,hy,ty,q) \
125 cc=(((((x)-u)-uu)+(xx))-c*(yy))/(y); z=c+cc; zz=(c-z)+cc;
126
127
128/* Double-length addition, slower but more accurate than ADD2. */
129/* The macro produces a double-length */
130/* number (z,zz) which satisfies approximately z+zz = (x+xx)+(y+yy). */
131/* An error bound: abs(x+xx + y+yy)*1.50e-31. (x,xx), (y,yy) */
132/* are assumed to be double-length numbers. r,rr,s,ss,u,uu,w */
133/* are temporary storage variables of type double. */
134
135#define ADD2A(x,xx,y,yy,z,zz,r,rr,s,ss,u,uu,w) \
136 r=(x)+(y); \
137 if (ABS(x)>ABS(y)) { rr=((x)-r)+(y); s=(rr+(yy))+(xx); } \
138 else { rr=((y)-r)+(x); s=(rr+(xx))+(yy); } \
139 if (rr!=0.0) { \
140 z=r+s; zz=(r-z)+s; } \
141 else { \
142 ss=(ABS(xx)>ABS(yy)) ? (((xx)-s)+(yy)) : (((yy)-s)+(xx)); \
143 u=r+s; \
144 uu=(ABS(r)>ABS(s)) ? ((r-u)+s) : ((s-u)+r) ; \
145 w=uu+ss; z=u+w; \
146 zz=(ABS(u)>ABS(w)) ? ((u-z)+w) : ((w-z)+u) ; }
147
148
149/* Double-length subtraction, slower but more accurate than SUB2. */
150/* The macro produces a double-length */
151/* number (z,zz) which satisfies approximately z+zz = (x+xx)-(y+yy). */
152/* An error bound: abs(x+xx - (y+yy))*1.50e-31. (x,xx), (y,yy) */
153/* are assumed to be double-length numbers. r,rr,s,ss,u,uu,w */
154/* are temporary storage variables of type double. */
155
156#define SUB2A(x,xx,y,yy,z,zz,r,rr,s,ss,u,uu,w) \
157 r=(x)-(y); \
158 if (ABS(x)>ABS(y)) { rr=((x)-r)-(y); s=(rr-(yy))+(xx); } \
159 else { rr=(x)-((y)+r); s=(rr+(xx))-(yy); } \
160 if (rr!=0.0) { \
161 z=r+s; zz=(r-z)+s; } \
162 else { \
163 ss=(ABS(xx)>ABS(yy)) ? (((xx)-s)-(yy)) : ((xx)-((yy)+s)); \
164 u=r+s; \
165 uu=(ABS(r)>ABS(s)) ? ((r-u)+s) : ((s-u)+r) ; \
166 w=uu+ss; z=u+w; \
167 zz=(ABS(u)>ABS(w)) ? ((u-z)+w) : ((w-z)+u) ; }
168
169
170
171
172
173
174