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