1 /* 2 * Copyright (c) 1985 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * All recipients should regard themselves as participants in an ongoing 8 * research project and hence should feel obligated to report their 9 * experiences (good or bad) with these elementary function codes, using 10 * the sendbug(8) program, to the authors. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)exp__E.c 5.5 (Berkeley) 06/01/90"; 15 #endif /* not lint */ 16 17 /* exp__E(x,c) 18 * ASSUMPTION: c << x SO THAT fl(x+c)=x. 19 * (c is the correction term for x) 20 * exp__E RETURNS 21 * 22 * / exp(x+c) - 1 - x , 1E-19 < |x| < .3465736 23 * exp__E(x,c) = | 24 * \ 0 , |x| < 1E-19. 25 * 26 * DOUBLE PRECISION (IEEE 53 bits, VAX D FORMAT 56 BITS) 27 * KERNEL FUNCTION OF EXP, EXPM1, POW FUNCTIONS 28 * CODED IN C BY K.C. NG, 1/31/85; 29 * REVISED BY K.C. NG on 3/16/85, 4/16/85. 30 * 31 * Required system supported function: 32 * copysign(x,y) 33 * 34 * Method: 35 * 1. Rational approximation. Let r=x+c. 36 * Based on 37 * 2 * sinh(r/2) 38 * exp(r) - 1 = ---------------------- , 39 * cosh(r/2) - sinh(r/2) 40 * exp__E(r) is computed using 41 * x*x (x/2)*W - ( Q - ( 2*P + x*P ) ) 42 * --- + (c + x*[---------------------------------- + c ]) 43 * 2 1 - W 44 * where P := p1*x^2 + p2*x^4, 45 * Q := q1*x^2 + q2*x^4 (for 56 bits precision, add q3*x^6) 46 * W := x/2-(Q-x*P), 47 * 48 * (See the listing below for the values of p1,p2,q1,q2,q3. The poly- 49 * nomials P and Q may be regarded as the approximations to sinh 50 * and cosh : 51 * sinh(r/2) = r/2 + r * P , cosh(r/2) = 1 + Q . ) 52 * 53 * The coefficients were obtained by a special Remez algorithm. 54 * 55 * Approximation error: 56 * 57 * | exp(x) - 1 | 2**(-57), (IEEE double) 58 * | ------------ - (exp__E(x,0)+x)/x | <= 59 * | x | 2**(-69). (VAX D) 60 * 61 * Constants: 62 * The hexadecimal values are the intended ones for the following constants. 63 * The decimal values may be used, provided that the compiler will convert 64 * from decimal to binary accurately enough to produce the hexadecimal values 65 * shown. 66 */ 67 68 #include "mathimpl.h" 69 70 vc(p1, 1.5150724356786683059E-2 ,3abe,3d78,066a,67e1, -6, .F83ABE67E1066A) 71 vc(p2, 6.3112487873718332688E-5 ,5b42,3984,0173,48cd, -13, .845B4248CD0173) 72 vc(q1, 1.1363478204690669916E-1 ,b95a,3ee8,ec45,44a2, -3, .E8B95A44A2EC45) 73 vc(q2, 1.2624568129896839182E-3 ,7905,3ba5,f5e7,72e4, -9, .A5790572E4F5E7) 74 vc(q3, 1.5021856115869022674E-6 ,9eb4,36c9,c395,604a, -19, .C99EB4604AC395) 75 76 ic(p1, 1.3887401997267371720E-2, -7, 1.C70FF8B3CC2CF) 77 ic(p2, 3.3044019718331897649E-5, -15, 1.15317DF4526C4) 78 ic(q1, 1.1110813732786649355E-1, -4, 1.C719538248597) 79 ic(q2, 9.9176615021572857300E-4, -10, 1.03FC4CB8C98E8) 80 81 #ifdef vccast 82 #define p1 vccast(p1) 83 #define p2 vccast(p2) 84 #define q1 vccast(q1) 85 #define q2 vccast(q2) 86 #define q3 vccast(q3) 87 #endif 88 89 double exp__E(x,c) 90 double x,c; 91 { 92 const static double zero=0.0, one=1.0, half=1.0/2.0, small=1.0E-19; 93 double z,p,q,xp,xh,w; 94 if(copysign(x,one)>small) { 95 z = x*x ; 96 p = z*( p1 +z* p2 ); 97 #if defined(vax)||defined(tahoe) 98 q = z*( q1 +z*( q2 +z* q3 )); 99 #else /* defined(vax)||defined(tahoe) */ 100 q = z*( q1 +z* q2 ); 101 #endif /* defined(vax)||defined(tahoe) */ 102 xp= x*p ; 103 xh= x*half ; 104 w = xh-(q-xp) ; 105 p = p+p; 106 c += x*((xh*w-(q-(p+xp)))/(one-w)+c); 107 return(z*half+c); 108 } 109 /* end of |x| > small */ 110 111 else { 112 if(x!=zero) one+small; /* raise the inexact flag */ 113 return(copysign(zero,x)); 114 } 115 } 116