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