xref: /onnv-gate/usr/src/lib/libast/common/uwin/log__L.c (revision 4887:feebf9260c2e)
1*4887Schin #include "FEATURE/uwin"
2*4887Schin 
3*4887Schin #if !_UWIN
4*4887Schin 
_STUB_log__L()5*4887Schin void _STUB_log__L(){}
6*4887Schin 
7*4887Schin #else
8*4887Schin 
9*4887Schin /*
10*4887Schin  * Copyright (c) 1985, 1993
11*4887Schin  *	The Regents of the University of California.  All rights reserved.
12*4887Schin  *
13*4887Schin  * Redistribution and use in source and binary forms, with or without
14*4887Schin  * modification, are permitted provided that the following conditions
15*4887Schin  * are met:
16*4887Schin  * 1. Redistributions of source code must retain the above copyright
17*4887Schin  *    notice, this list of conditions and the following disclaimer.
18*4887Schin  * 2. Redistributions in binary form must reproduce the above copyright
19*4887Schin  *    notice, this list of conditions and the following disclaimer in the
20*4887Schin  *    documentation and/or other materials provided with the distribution.
21*4887Schin  * 3. Neither the name of the University nor the names of its contributors
22*4887Schin  *    may be used to endorse or promote products derived from this software
23*4887Schin  *    without specific prior written permission.
24*4887Schin  *
25*4887Schin  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26*4887Schin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27*4887Schin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28*4887Schin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29*4887Schin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30*4887Schin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31*4887Schin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32*4887Schin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33*4887Schin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34*4887Schin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35*4887Schin  * SUCH DAMAGE.
36*4887Schin  */
37*4887Schin 
38*4887Schin #ifndef lint
39*4887Schin static char sccsid[] = "@(#)log__L.c	8.1 (Berkeley) 6/4/93";
40*4887Schin #endif /* not lint */
41*4887Schin 
42*4887Schin /* log__L(Z)
43*4887Schin  *		LOG(1+X) - 2S			       X
44*4887Schin  * RETURN      ---------------  WHERE Z = S*S,  S = ------- , 0 <= Z <= .0294...
45*4887Schin  *		      S				     2 + X
46*4887Schin  *
47*4887Schin  * DOUBLE PRECISION (VAX D FORMAT 56 bits or IEEE DOUBLE 53 BITS)
48*4887Schin  * KERNEL FUNCTION FOR LOG; TO BE USED IN LOG1P, LOG, AND POW FUNCTIONS
49*4887Schin  * CODED IN C BY K.C. NG, 1/19/85;
50*4887Schin  * REVISED BY K.C. Ng, 2/3/85, 4/16/85.
51*4887Schin  *
52*4887Schin  * Method :
53*4887Schin  *	1. Polynomial approximation: let s = x/(2+x).
54*4887Schin  *	   Based on log(1+x) = log(1+s) - log(1-s)
55*4887Schin  *		 = 2s + 2/3 s**3 + 2/5 s**5 + .....,
56*4887Schin  *
57*4887Schin  *	   (log(1+x) - 2s)/s is computed by
58*4887Schin  *
59*4887Schin  *	       z*(L1 + z*(L2 + z*(... (L7 + z*L8)...)))
60*4887Schin  *
61*4887Schin  *	   where z=s*s. (See the listing below for Lk's values.) The
62*4887Schin  *	   coefficients are obtained by a special Remez algorithm.
63*4887Schin  *
64*4887Schin  * Accuracy:
65*4887Schin  *	Assuming no rounding error, the maximum magnitude of the approximation
66*4887Schin  *	error (absolute) is 2**(-58.49) for IEEE double, and 2**(-63.63)
67*4887Schin  *	for VAX D format.
68*4887Schin  *
69*4887Schin  * Constants:
70*4887Schin  * The hexadecimal values are the intended ones for the following constants.
71*4887Schin  * The decimal values may be used, provided that the compiler will convert
72*4887Schin  * from decimal to binary accurately enough to produce the hexadecimal values
73*4887Schin  * shown.
74*4887Schin  */
75*4887Schin 
76*4887Schin #include "mathimpl.h"
77*4887Schin 
78*4887Schin vc(L1, 6.6666666666666703212E-1 ,aaaa,402a,aac5,aaaa,  0, .AAAAAAAAAAAAC5)
79*4887Schin vc(L2, 3.9999999999970461961E-1 ,cccc,3fcc,2684,cccc, -1, .CCCCCCCCCC2684)
80*4887Schin vc(L3, 2.8571428579395698188E-1 ,4924,3f92,5782,92f8, -1, .92492492F85782)
81*4887Schin vc(L4, 2.2222221233634724402E-1 ,8e38,3f63,af2c,39b7, -2, .E38E3839B7AF2C)
82*4887Schin vc(L5, 1.8181879517064680057E-1 ,2eb4,3f3a,655e,cc39, -2, .BA2EB4CC39655E)
83*4887Schin vc(L6, 1.5382888777946145467E-1 ,8551,3f1d,781d,e8c5, -2, .9D8551E8C5781D)
84*4887Schin vc(L7, 1.3338356561139403517E-1 ,95b3,3f08,cd92,907f, -2, .8895B3907FCD92)
85*4887Schin vc(L8, 1.2500000000000000000E-1 ,0000,3f00,0000,0000, -2, .80000000000000)
86*4887Schin 
87*4887Schin ic(L1, 6.6666666666667340202E-1, -1, 1.5555555555592)
88*4887Schin ic(L2, 3.9999999999416702146E-1, -2, 1.999999997FF24)
89*4887Schin ic(L3, 2.8571428742008753154E-1, -2, 1.24924941E07B4)
90*4887Schin ic(L4, 2.2222198607186277597E-1, -3, 1.C71C52150BEA6)
91*4887Schin ic(L5, 1.8183562745289935658E-1, -3, 1.74663CC94342F)
92*4887Schin ic(L6, 1.5314087275331442206E-1, -3, 1.39A1EC014045B)
93*4887Schin ic(L7, 1.4795612545334174692E-1, -3, 1.2F039F0085122)
94*4887Schin 
95*4887Schin #ifdef vccast
96*4887Schin #define	L1	vccast(L1)
97*4887Schin #define	L2	vccast(L2)
98*4887Schin #define	L3	vccast(L3)
99*4887Schin #define	L4	vccast(L4)
100*4887Schin #define	L5	vccast(L5)
101*4887Schin #define	L6	vccast(L6)
102*4887Schin #define	L7	vccast(L7)
103*4887Schin #define	L8	vccast(L8)
104*4887Schin #endif
105*4887Schin 
106*4887Schin double __log__L(z)
107*4887Schin double z;
108*4887Schin {
109*4887Schin #if defined(vax)||defined(tahoe)
110*4887Schin     return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*(L7+z*L8))))))));
111*4887Schin #else	/* defined(vax)||defined(tahoe) */
112*4887Schin     return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*L7)))))));
113*4887Schin #endif	/* defined(vax)||defined(tahoe) */
114*4887Schin }
115*4887Schin 
116*4887Schin #endif
117