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