134126Sbostic /* 224594Szliu * Copyright (c) 1985 Regents of the University of California. 334126Sbostic * All rights reserved. 434126Sbostic * 5*42657Sbostic * %sccs.include.redist.c% 634126Sbostic * 734126Sbostic * All recipients should regard themselves as participants in an ongoing 834126Sbostic * research project and hence should feel obligated to report their 934126Sbostic * experiences (good or bad) with these elementary function codes, using 1034126Sbostic * the sendbug(8) program, to the authors. 1124594Szliu */ 1224594Szliu 1324594Szliu #ifndef lint 14*42657Sbostic static char sccsid[] = "@(#)exp__E.c 5.5 (Berkeley) 06/01/90"; 1534126Sbostic #endif /* not lint */ 1624594Szliu 1724594Szliu /* exp__E(x,c) 1824594Szliu * ASSUMPTION: c << x SO THAT fl(x+c)=x. 1924594Szliu * (c is the correction term for x) 2024594Szliu * exp__E RETURNS 2124594Szliu * 2224594Szliu * / exp(x+c) - 1 - x , 1E-19 < |x| < .3465736 2324594Szliu * exp__E(x,c) = | 2424594Szliu * \ 0 , |x| < 1E-19. 2524594Szliu * 2624594Szliu * DOUBLE PRECISION (IEEE 53 bits, VAX D FORMAT 56 BITS) 2724594Szliu * KERNEL FUNCTION OF EXP, EXPM1, POW FUNCTIONS 2824594Szliu * CODED IN C BY K.C. NG, 1/31/85; 2924594Szliu * REVISED BY K.C. NG on 3/16/85, 4/16/85. 3024594Szliu * 3124594Szliu * Required system supported function: 3224594Szliu * copysign(x,y) 3324594Szliu * 3424594Szliu * Method: 3524594Szliu * 1. Rational approximation. Let r=x+c. 3624594Szliu * Based on 3724594Szliu * 2 * sinh(r/2) 3824594Szliu * exp(r) - 1 = ---------------------- , 3924594Szliu * cosh(r/2) - sinh(r/2) 4024594Szliu * exp__E(r) is computed using 4124594Szliu * x*x (x/2)*W - ( Q - ( 2*P + x*P ) ) 4224594Szliu * --- + (c + x*[---------------------------------- + c ]) 4324594Szliu * 2 1 - W 4424594Szliu * where P := p1*x^2 + p2*x^4, 4524594Szliu * Q := q1*x^2 + q2*x^4 (for 56 bits precision, add q3*x^6) 4624594Szliu * W := x/2-(Q-x*P), 4724594Szliu * 4824594Szliu * (See the listing below for the values of p1,p2,q1,q2,q3. The poly- 4924594Szliu * nomials P and Q may be regarded as the approximations to sinh 5024594Szliu * and cosh : 5124594Szliu * sinh(r/2) = r/2 + r * P , cosh(r/2) = 1 + Q . ) 5224594Szliu * 5324594Szliu * The coefficients were obtained by a special Remez algorithm. 5424594Szliu * 5524594Szliu * Approximation error: 5624594Szliu * 5724594Szliu * | exp(x) - 1 | 2**(-57), (IEEE double) 5824594Szliu * | ------------ - (exp__E(x,0)+x)/x | <= 5924594Szliu * | x | 2**(-69). (VAX D) 6024594Szliu * 6124594Szliu * Constants: 6224594Szliu * The hexadecimal values are the intended ones for the following constants. 6324594Szliu * The decimal values may be used, provided that the compiler will convert 6424594Szliu * from decimal to binary accurately enough to produce the hexadecimal values 6524594Szliu * shown. 6624594Szliu */ 6724594Szliu 6835679Sbostic #include "mathimpl.h" 6924594Szliu 7035679Sbostic vc(p1, 1.5150724356786683059E-2 ,3abe,3d78,066a,67e1, -6, .F83ABE67E1066A) 7135679Sbostic vc(p2, 6.3112487873718332688E-5 ,5b42,3984,0173,48cd, -13, .845B4248CD0173) 7235679Sbostic vc(q1, 1.1363478204690669916E-1 ,b95a,3ee8,ec45,44a2, -3, .E8B95A44A2EC45) 7335679Sbostic vc(q2, 1.2624568129896839182E-3 ,7905,3ba5,f5e7,72e4, -9, .A5790572E4F5E7) 7435679Sbostic vc(q3, 1.5021856115869022674E-6 ,9eb4,36c9,c395,604a, -19, .C99EB4604AC395) 7535679Sbostic 7635679Sbostic ic(p1, 1.3887401997267371720E-2, -7, 1.C70FF8B3CC2CF) 7735679Sbostic ic(p2, 3.3044019718331897649E-5, -15, 1.15317DF4526C4) 7835679Sbostic ic(q1, 1.1110813732786649355E-1, -4, 1.C719538248597) 7935679Sbostic ic(q2, 9.9176615021572857300E-4, -10, 1.03FC4CB8C98E8) 8035679Sbostic 8135679Sbostic #ifdef vccast 8235679Sbostic #define p1 vccast(p1) 8335679Sbostic #define p2 vccast(p2) 8435679Sbostic #define q1 vccast(q1) 8535679Sbostic #define q2 vccast(q2) 8635679Sbostic #define q3 vccast(q3) 8735679Sbostic #endif 8835679Sbostic 8924594Szliu double exp__E(x,c) 9024594Szliu double x,c; 9124594Szliu { 9235679Sbostic const static double zero=0.0, one=1.0, half=1.0/2.0, small=1.0E-19; 9335679Sbostic double z,p,q,xp,xh,w; 9424594Szliu if(copysign(x,one)>small) { 9524594Szliu z = x*x ; 9624594Szliu p = z*( p1 +z* p2 ); 9731853Szliu #if defined(vax)||defined(tahoe) 9824594Szliu q = z*( q1 +z*( q2 +z* q3 )); 9931853Szliu #else /* defined(vax)||defined(tahoe) */ 10024594Szliu q = z*( q1 +z* q2 ); 10131853Szliu #endif /* defined(vax)||defined(tahoe) */ 10224594Szliu xp= x*p ; 10324594Szliu xh= x*half ; 10424594Szliu w = xh-(q-xp) ; 10524594Szliu p = p+p; 10624594Szliu c += x*((xh*w-(q-(p+xp)))/(one-w)+c); 10724594Szliu return(z*half+c); 10824594Szliu } 10924594Szliu /* end of |x| > small */ 11024594Szliu 11124594Szliu else { 11224594Szliu if(x!=zero) one+small; /* raise the inexact flag */ 11324594Szliu return(copysign(zero,x)); 11424594Szliu } 11524594Szliu } 116