Update.
[glibc.git] / sysdeps / generic / exp__E.c
blobab972477a04b07a0225e9e8518728df505e69786
1 /*
2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #ifndef lint
35 static char sccsid[] = "@(#)exp__E.c 8.1 (Berkeley) 6/4/93";
36 #endif /* not lint */
38 /* exp__E(x,c)
39 * ASSUMPTION: c << x SO THAT fl(x+c)=x.
40 * (c is the correction term for x)
41 * exp__E RETURNS
43 * / exp(x+c) - 1 - x , 1E-19 < |x| < .3465736
44 * exp__E(x,c) = |
45 * \ 0 , |x| < 1E-19.
47 * DOUBLE PRECISION (IEEE 53 bits, VAX D FORMAT 56 BITS)
48 * KERNEL FUNCTION OF EXP, EXPM1, POW FUNCTIONS
49 * CODED IN C BY K.C. NG, 1/31/85;
50 * REVISED BY K.C. NG on 3/16/85, 4/16/85.
52 * Required system supported function:
53 * copysign(x,y)
55 * Method:
56 * 1. Rational approximation. Let r=x+c.
57 * Based on
58 * 2 * sinh(r/2)
59 * exp(r) - 1 = ---------------------- ,
60 * cosh(r/2) - sinh(r/2)
61 * exp__E(r) is computed using
62 * x*x (x/2)*W - ( Q - ( 2*P + x*P ) )
63 * --- + (c + x*[---------------------------------- + c ])
64 * 2 1 - W
65 * where P := p1*x^2 + p2*x^4,
66 * Q := q1*x^2 + q2*x^4 (for 56 bits precision, add q3*x^6)
67 * W := x/2-(Q-x*P),
69 * (See the listing below for the values of p1,p2,q1,q2,q3. The poly-
70 * nomials P and Q may be regarded as the approximations to sinh
71 * and cosh :
72 * sinh(r/2) = r/2 + r * P , cosh(r/2) = 1 + Q . )
74 * The coefficients were obtained by a special Remez algorithm.
76 * Approximation error:
78 * | exp(x) - 1 | 2**(-57), (IEEE double)
79 * | ------------ - (exp__E(x,0)+x)/x | <=
80 * | x | 2**(-69). (VAX D)
82 * Constants:
83 * The hexadecimal values are the intended ones for the following constants.
84 * The decimal values may be used, provided that the compiler will convert
85 * from decimal to binary accurately enough to produce the hexadecimal values
86 * shown.
89 #include "mathimpl.h"
91 vc(p1, 1.5150724356786683059E-2 ,3abe,3d78,066a,67e1, -6, .F83ABE67E1066A)
92 vc(p2, 6.3112487873718332688E-5 ,5b42,3984,0173,48cd, -13, .845B4248CD0173)
93 vc(q1, 1.1363478204690669916E-1 ,b95a,3ee8,ec45,44a2, -3, .E8B95A44A2EC45)
94 vc(q2, 1.2624568129896839182E-3 ,7905,3ba5,f5e7,72e4, -9, .A5790572E4F5E7)
95 vc(q3, 1.5021856115869022674E-6 ,9eb4,36c9,c395,604a, -19, .C99EB4604AC395)
97 ic(p1, 1.3887401997267371720E-2, -7, 1.C70FF8B3CC2CF)
98 ic(p2, 3.3044019718331897649E-5, -15, 1.15317DF4526C4)
99 ic(q1, 1.1110813732786649355E-1, -4, 1.C719538248597)
100 ic(q2, 9.9176615021572857300E-4, -10, 1.03FC4CB8C98E8)
102 #ifdef vccast
103 #define p1 vccast(p1)
104 #define p2 vccast(p2)
105 #define q1 vccast(q1)
106 #define q2 vccast(q2)
107 #define q3 vccast(q3)
108 #endif
110 double __exp__E(x,c)
111 double x,c;
113 const static double zero=0.0, one=1.0, half=1.0/2.0, small=1.0E-19;
114 double z,p,q,xp,xh,w;
115 if(copysign(x,one)>small) {
116 z = x*x ;
117 p = z*( p1 +z* p2 );
118 #if defined(vax)||defined(tahoe)
119 q = z*( q1 +z*( q2 +z* q3 ));
120 #else /* defined(vax)||defined(tahoe) */
121 q = z*( q1 +z* q2 );
122 #endif /* defined(vax)||defined(tahoe) */
123 xp= x*p ;
124 xh= x*half ;
125 w = xh-(q-xp) ;
126 p = p+p;
127 c += x*((xh*w-(q-(p+xp)))/(one-w)+c);
128 return(z*half+c);
130 /* end of |x| > small */
132 else {
133 if(x!=zero) one+small; /* raise the inexact flag */
134 return(copysign(zero,x));