134126Sbostic /* 2*61285Sbostic * Copyright (c) 1985, 1993 3*61285Sbostic * The Regents of the University of California. All rights reserved. 434126Sbostic * 542657Sbostic * %sccs.include.redist.c% 624594Szliu */ 724594Szliu 824594Szliu #ifndef lint 9*61285Sbostic static char sccsid[] = "@(#)exp__E.c 8.1 (Berkeley) 06/04/93"; 1034126Sbostic #endif /* not lint */ 1124594Szliu 1224594Szliu /* exp__E(x,c) 1324594Szliu * ASSUMPTION: c << x SO THAT fl(x+c)=x. 1424594Szliu * (c is the correction term for x) 1524594Szliu * exp__E RETURNS 1624594Szliu * 1724594Szliu * / exp(x+c) - 1 - x , 1E-19 < |x| < .3465736 1824594Szliu * exp__E(x,c) = | 1924594Szliu * \ 0 , |x| < 1E-19. 2024594Szliu * 2124594Szliu * DOUBLE PRECISION (IEEE 53 bits, VAX D FORMAT 56 BITS) 2224594Szliu * KERNEL FUNCTION OF EXP, EXPM1, POW FUNCTIONS 2324594Szliu * CODED IN C BY K.C. NG, 1/31/85; 2424594Szliu * REVISED BY K.C. NG on 3/16/85, 4/16/85. 2524594Szliu * 2624594Szliu * Required system supported function: 2724594Szliu * copysign(x,y) 2824594Szliu * 2924594Szliu * Method: 3024594Szliu * 1. Rational approximation. Let r=x+c. 3124594Szliu * Based on 3224594Szliu * 2 * sinh(r/2) 3324594Szliu * exp(r) - 1 = ---------------------- , 3424594Szliu * cosh(r/2) - sinh(r/2) 3524594Szliu * exp__E(r) is computed using 3624594Szliu * x*x (x/2)*W - ( Q - ( 2*P + x*P ) ) 3724594Szliu * --- + (c + x*[---------------------------------- + c ]) 3824594Szliu * 2 1 - W 3924594Szliu * where P := p1*x^2 + p2*x^4, 4024594Szliu * Q := q1*x^2 + q2*x^4 (for 56 bits precision, add q3*x^6) 4124594Szliu * W := x/2-(Q-x*P), 4224594Szliu * 4324594Szliu * (See the listing below for the values of p1,p2,q1,q2,q3. The poly- 4424594Szliu * nomials P and Q may be regarded as the approximations to sinh 4524594Szliu * and cosh : 4624594Szliu * sinh(r/2) = r/2 + r * P , cosh(r/2) = 1 + Q . ) 4724594Szliu * 4824594Szliu * The coefficients were obtained by a special Remez algorithm. 4924594Szliu * 5024594Szliu * Approximation error: 5124594Szliu * 5224594Szliu * | exp(x) - 1 | 2**(-57), (IEEE double) 5324594Szliu * | ------------ - (exp__E(x,0)+x)/x | <= 5424594Szliu * | x | 2**(-69). (VAX D) 5524594Szliu * 5624594Szliu * Constants: 5724594Szliu * The hexadecimal values are the intended ones for the following constants. 5824594Szliu * The decimal values may be used, provided that the compiler will convert 5924594Szliu * from decimal to binary accurately enough to produce the hexadecimal values 6024594Szliu * shown. 6124594Szliu */ 6224594Szliu 6335679Sbostic #include "mathimpl.h" 6424594Szliu 6535679Sbostic vc(p1, 1.5150724356786683059E-2 ,3abe,3d78,066a,67e1, -6, .F83ABE67E1066A) 6635679Sbostic vc(p2, 6.3112487873718332688E-5 ,5b42,3984,0173,48cd, -13, .845B4248CD0173) 6735679Sbostic vc(q1, 1.1363478204690669916E-1 ,b95a,3ee8,ec45,44a2, -3, .E8B95A44A2EC45) 6835679Sbostic vc(q2, 1.2624568129896839182E-3 ,7905,3ba5,f5e7,72e4, -9, .A5790572E4F5E7) 6935679Sbostic vc(q3, 1.5021856115869022674E-6 ,9eb4,36c9,c395,604a, -19, .C99EB4604AC395) 7035679Sbostic 7135679Sbostic ic(p1, 1.3887401997267371720E-2, -7, 1.C70FF8B3CC2CF) 7235679Sbostic ic(p2, 3.3044019718331897649E-5, -15, 1.15317DF4526C4) 7335679Sbostic ic(q1, 1.1110813732786649355E-1, -4, 1.C719538248597) 7435679Sbostic ic(q2, 9.9176615021572857300E-4, -10, 1.03FC4CB8C98E8) 7535679Sbostic 7635679Sbostic #ifdef vccast 7735679Sbostic #define p1 vccast(p1) 7835679Sbostic #define p2 vccast(p2) 7935679Sbostic #define q1 vccast(q1) 8035679Sbostic #define q2 vccast(q2) 8135679Sbostic #define q3 vccast(q3) 8235679Sbostic #endif 8335679Sbostic 8457452Sbostic double __exp__E(x,c) 8524594Szliu double x,c; 8624594Szliu { 8735679Sbostic const static double zero=0.0, one=1.0, half=1.0/2.0, small=1.0E-19; 8835679Sbostic double z,p,q,xp,xh,w; 8924594Szliu if(copysign(x,one)>small) { 9024594Szliu z = x*x ; 9124594Szliu p = z*( p1 +z* p2 ); 9231853Szliu #if defined(vax)||defined(tahoe) 9324594Szliu q = z*( q1 +z*( q2 +z* q3 )); 9431853Szliu #else /* defined(vax)||defined(tahoe) */ 9524594Szliu q = z*( q1 +z* q2 ); 9631853Szliu #endif /* defined(vax)||defined(tahoe) */ 9724594Szliu xp= x*p ; 9824594Szliu xh= x*half ; 9924594Szliu w = xh-(q-xp) ; 10024594Szliu p = p+p; 10124594Szliu c += x*((xh*w-(q-(p+xp)))/(one-w)+c); 10224594Szliu return(z*half+c); 10324594Szliu } 10424594Szliu /* end of |x| > small */ 10524594Szliu 10624594Szliu else { 10724594Szliu if(x!=zero) one+small; /* raise the inexact flag */ 10824594Szliu return(copysign(zero,x)); 10924594Szliu } 11024594Szliu } 111