134126Sbostic /*
2*61309Sbostic  * Copyright (c) 1985, 1993
3*61309Sbostic  *	The Regents of the University of California.  All rights reserved.
434126Sbostic  *
542657Sbostic  * %sccs.include.redist.c%
624604Szliu  */
724604Szliu 
824604Szliu #ifndef lint
9*61309Sbostic static char sccsid[] = "@(#)log__L.c	8.1 (Berkeley) 06/04/93";
1034126Sbostic #endif /* not lint */
1124604Szliu 
1224604Szliu /* log__L(Z)
1324604Szliu  *		LOG(1+X) - 2S			       X
1424604Szliu  * RETURN      ---------------  WHERE Z = S*S,  S = ------- , 0 <= Z <= .0294...
1524604Szliu  *		      S				     2 + X
1624604Szliu  *
1724604Szliu  * DOUBLE PRECISION (VAX D FORMAT 56 bits or IEEE DOUBLE 53 BITS)
1824604Szliu  * KERNEL FUNCTION FOR LOG; TO BE USED IN LOG1P, LOG, AND POW FUNCTIONS
1924604Szliu  * CODED IN C BY K.C. NG, 1/19/85;
2024604Szliu  * REVISED BY K.C. Ng, 2/3/85, 4/16/85.
2124604Szliu  *
2224604Szliu  * Method :
2324604Szliu  *	1. Polynomial approximation: let s = x/(2+x).
2424604Szliu  *	   Based on log(1+x) = log(1+s) - log(1-s)
2524604Szliu  *		 = 2s + 2/3 s**3 + 2/5 s**5 + .....,
2624604Szliu  *
2724604Szliu  *	   (log(1+x) - 2s)/s is computed by
2824604Szliu  *
2924604Szliu  *	       z*(L1 + z*(L2 + z*(... (L7 + z*L8)...)))
3024604Szliu  *
3124604Szliu  *	   where z=s*s. (See the listing below for Lk's values.) The
3224604Szliu  *	   coefficients are obtained by a special Remez algorithm.
3324604Szliu  *
3424604Szliu  * Accuracy:
3524604Szliu  *	Assuming no rounding error, the maximum magnitude of the approximation
3624604Szliu  *	error (absolute) is 2**(-58.49) for IEEE double, and 2**(-63.63)
3724604Szliu  *	for VAX D format.
3824604Szliu  *
3924604Szliu  * Constants:
4024604Szliu  * The hexadecimal values are the intended ones for the following constants.
4124604Szliu  * The decimal values may be used, provided that the compiler will convert
4224604Szliu  * from decimal to binary accurately enough to produce the hexadecimal values
4324604Szliu  * shown.
4424604Szliu  */
4524604Szliu 
4635679Sbostic #include "mathimpl.h"
4724604Szliu 
4835679Sbostic vc(L1, 6.6666666666666703212E-1 ,aaaa,402a,aac5,aaaa,  0, .AAAAAAAAAAAAC5)
4935679Sbostic vc(L2, 3.9999999999970461961E-1 ,cccc,3fcc,2684,cccc, -1, .CCCCCCCCCC2684)
5035679Sbostic vc(L3, 2.8571428579395698188E-1 ,4924,3f92,5782,92f8, -1, .92492492F85782)
5135679Sbostic vc(L4, 2.2222221233634724402E-1 ,8e38,3f63,af2c,39b7, -2, .E38E3839B7AF2C)
5235679Sbostic vc(L5, 1.8181879517064680057E-1 ,2eb4,3f3a,655e,cc39, -2, .BA2EB4CC39655E)
5335679Sbostic vc(L6, 1.5382888777946145467E-1 ,8551,3f1d,781d,e8c5, -2, .9D8551E8C5781D)
5435679Sbostic vc(L7, 1.3338356561139403517E-1 ,95b3,3f08,cd92,907f, -2, .8895B3907FCD92)
5535679Sbostic vc(L8, 1.2500000000000000000E-1 ,0000,3f00,0000,0000, -2, .80000000000000)
5635679Sbostic 
5735679Sbostic ic(L1, 6.6666666666667340202E-1, -1, 1.5555555555592)
5835679Sbostic ic(L2, 3.9999999999416702146E-1, -2, 1.999999997FF24)
5935679Sbostic ic(L3, 2.8571428742008753154E-1, -2, 1.24924941E07B4)
6035679Sbostic ic(L4, 2.2222198607186277597E-1, -3, 1.C71C52150BEA6)
6135679Sbostic ic(L5, 1.8183562745289935658E-1, -3, 1.74663CC94342F)
6235679Sbostic ic(L6, 1.5314087275331442206E-1, -3, 1.39A1EC014045B)
6335679Sbostic ic(L7, 1.4795612545334174692E-1, -3, 1.2F039F0085122)
6435679Sbostic 
6535679Sbostic #ifdef vccast
6635679Sbostic #define	L1	vccast(L1)
6735679Sbostic #define	L2	vccast(L2)
6835679Sbostic #define	L3	vccast(L3)
6935679Sbostic #define	L4	vccast(L4)
7035679Sbostic #define	L5	vccast(L5)
7135679Sbostic #define	L6	vccast(L6)
7235679Sbostic #define	L7	vccast(L7)
7335679Sbostic #define	L8	vccast(L8)
7435679Sbostic #endif
7535679Sbostic 
7657452Sbostic double __log__L(z)
7724604Szliu double z;
7824604Szliu {
7931853Szliu #if defined(vax)||defined(tahoe)
8024604Szliu     return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*(L7+z*L8))))))));
8131853Szliu #else	/* defined(vax)||defined(tahoe) */
8224604Szliu     return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*L7)))))));
8331853Szliu #endif	/* defined(vax)||defined(tahoe) */
8424604Szliu }
85