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