124604Szliu /* 224604Szliu * Copyright (c) 1985 Regents of the University of California. 324604Szliu * 424604Szliu * Use and reproduction of this software are granted in accordance with 524604Szliu * the terms and conditions specified in the Berkeley Software License 624604Szliu * Agreement (in particular, this entails acknowledgement of the programs' 724604Szliu * source, and inclusion of this notice) with the additional understanding 824604Szliu * that all recipients should regard themselves as participants in an 924604Szliu * ongoing research project and hence should feel obligated to report 1024604Szliu * their experiences (good or bad) with these elementary function codes, 1124604Szliu * using "sendbug 4bsd-bugs@BERKELEY", to the authors. 1224604Szliu */ 1324604Szliu 1424604Szliu #ifndef lint 15*24706Selefunt static char sccsid[] = 16*24706Selefunt "@(#)log__L.c 1.2 (Berkeley) 8/21/85; 1.2 (ucb.elefunt) 09/11/85"; 1724604Szliu #endif not lint 1824604Szliu 1924604Szliu /* log__L(Z) 2024604Szliu * LOG(1+X) - 2S X 2124604Szliu * RETURN --------------- WHERE Z = S*S, S = ------- , 0 <= Z <= .0294... 2224604Szliu * S 2 + X 2324604Szliu * 2424604Szliu * DOUBLE PRECISION (VAX D FORMAT 56 bits or IEEE DOUBLE 53 BITS) 2524604Szliu * KERNEL FUNCTION FOR LOG; TO BE USED IN LOG1P, LOG, AND POW FUNCTIONS 2624604Szliu * CODED IN C BY K.C. NG, 1/19/85; 2724604Szliu * REVISED BY K.C. Ng, 2/3/85, 4/16/85. 2824604Szliu * 2924604Szliu * Method : 3024604Szliu * 1. Polynomial approximation: let s = x/(2+x). 3124604Szliu * Based on log(1+x) = log(1+s) - log(1-s) 3224604Szliu * = 2s + 2/3 s**3 + 2/5 s**5 + ....., 3324604Szliu * 3424604Szliu * (log(1+x) - 2s)/s is computed by 3524604Szliu * 3624604Szliu * z*(L1 + z*(L2 + z*(... (L7 + z*L8)...))) 3724604Szliu * 3824604Szliu * where z=s*s. (See the listing below for Lk's values.) The 3924604Szliu * coefficients are obtained by a special Remez algorithm. 4024604Szliu * 4124604Szliu * Accuracy: 4224604Szliu * Assuming no rounding error, the maximum magnitude of the approximation 4324604Szliu * error (absolute) is 2**(-58.49) for IEEE double, and 2**(-63.63) 4424604Szliu * for VAX D format. 4524604Szliu * 4624604Szliu * Constants: 4724604Szliu * The hexadecimal values are the intended ones for the following constants. 4824604Szliu * The decimal values may be used, provided that the compiler will convert 4924604Szliu * from decimal to binary accurately enough to produce the hexadecimal values 5024604Szliu * shown. 5124604Szliu */ 5224604Szliu 5324604Szliu #ifdef VAX /* VAX D format (56 bits) */ 5424604Szliu /* static double */ 5524604Szliu /* L1 = 6.6666666666666703212E-1 , Hex 2^ 0 * .AAAAAAAAAAAAC5 */ 5624604Szliu /* L2 = 3.9999999999970461961E-1 , Hex 2^ -1 * .CCCCCCCCCC2684 */ 5724604Szliu /* L3 = 2.8571428579395698188E-1 , Hex 2^ -1 * .92492492F85782 */ 5824604Szliu /* L4 = 2.2222221233634724402E-1 , Hex 2^ -2 * .E38E3839B7AF2C */ 5924604Szliu /* L5 = 1.8181879517064680057E-1 , Hex 2^ -2 * .BA2EB4CC39655E */ 6024604Szliu /* L6 = 1.5382888777946145467E-1 , Hex 2^ -2 * .9D8551E8C5781D */ 6124604Szliu /* L7 = 1.3338356561139403517E-1 , Hex 2^ -2 * .8895B3907FCD92 */ 6224604Szliu /* L8 = 1.2500000000000000000E-1 , Hex 2^ -2 * .80000000000000 */ 6324604Szliu static long L1x[] = { 0xaaaa402a, 0xaac5aaaa}; 6424604Szliu static long L2x[] = { 0xcccc3fcc, 0x2684cccc}; 6524604Szliu static long L3x[] = { 0x49243f92, 0x578292f8}; 6624604Szliu static long L4x[] = { 0x8e383f63, 0xaf2c39b7}; 6724604Szliu static long L5x[] = { 0x2eb43f3a, 0x655ecc39}; 6824604Szliu static long L6x[] = { 0x85513f1d, 0x781de8c5}; 6924604Szliu static long L7x[] = { 0x95b33f08, 0xcd92907f}; 7024604Szliu static long L8x[] = { 0x00003f00, 0x00000000}; 7124604Szliu #define L1 (*(double*)L1x) 7224604Szliu #define L2 (*(double*)L2x) 7324604Szliu #define L3 (*(double*)L3x) 7424604Szliu #define L4 (*(double*)L4x) 7524604Szliu #define L5 (*(double*)L5x) 7624604Szliu #define L6 (*(double*)L6x) 7724604Szliu #define L7 (*(double*)L7x) 7824604Szliu #define L8 (*(double*)L8x) 7924604Szliu #else /* IEEE double */ 8024604Szliu static double 8124604Szliu L1 = 6.6666666666667340202E-1 , /*Hex 2^ -1 * 1.5555555555592 */ 8224604Szliu L2 = 3.9999999999416702146E-1 , /*Hex 2^ -2 * 1.999999997FF24 */ 8324604Szliu L3 = 2.8571428742008753154E-1 , /*Hex 2^ -2 * 1.24924941E07B4 */ 8424604Szliu L4 = 2.2222198607186277597E-1 , /*Hex 2^ -3 * 1.C71C52150BEA6 */ 8524604Szliu L5 = 1.8183562745289935658E-1 , /*Hex 2^ -3 * 1.74663CC94342F */ 8624604Szliu L6 = 1.5314087275331442206E-1 , /*Hex 2^ -3 * 1.39A1EC014045B */ 8724604Szliu L7 = 1.4795612545334174692E-1 ; /*Hex 2^ -3 * 1.2F039F0085122 */ 8824604Szliu #endif 8924604Szliu 9024604Szliu double log__L(z) 9124604Szliu double z; 9224604Szliu { 9324604Szliu #ifdef VAX 9424604Szliu return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*(L7+z*L8)))))))); 9524604Szliu #else /* IEEE double */ 9624604Szliu return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*L7))))))); 9724604Szliu #endif 9824604Szliu } 99