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