Annotation of 43BSDTahoe/usr.lib/libm/log__L.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1985 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that the above copyright notice and this paragraph are
        !             7:  * duplicated in all such forms and that any documentation,
        !             8:  * advertising materials, and other materials related to such
        !             9:  * distribution and use acknowledge that the software was developed
        !            10:  * by the University of California, Berkeley.  The name of the
        !            11:  * University may not be used to endorse or promote products derived
        !            12:  * from this software without specific prior written permission.
        !            13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            16:  *
        !            17:  * All recipients should regard themselves as participants in an ongoing
        !            18:  * research project and hence should feel obligated to report their
        !            19:  * experiences (good or bad) with these elementary function codes, using
        !            20:  * the sendbug(8) program, to the authors.
        !            21:  */
        !            22: 
        !            23: #ifndef lint
        !            24: static char sccsid[] = "@(#)log__L.c   5.3 (Berkeley) 6/30/88";
        !            25: #endif /* not lint */
        !            26: 
        !            27: /* log__L(Z)
        !            28:  *             LOG(1+X) - 2S                          X
        !            29:  * RETURN      ---------------  WHERE Z = S*S,  S = ------- , 0 <= Z <= .0294...
        !            30:  *                   S                              2 + X
        !            31:  *                  
        !            32:  * DOUBLE PRECISION (VAX D FORMAT 56 bits or IEEE DOUBLE 53 BITS)
        !            33:  * KERNEL FUNCTION FOR LOG; TO BE USED IN LOG1P, LOG, AND POW FUNCTIONS
        !            34:  * CODED IN C BY K.C. NG, 1/19/85; 
        !            35:  * REVISED BY K.C. Ng, 2/3/85, 4/16/85.
        !            36:  *
        !            37:  * Method :
        !            38:  *     1. Polynomial approximation: let s = x/(2+x). 
        !            39:  *        Based on log(1+x) = log(1+s) - log(1-s)
        !            40:  *              = 2s + 2/3 s**3 + 2/5 s**5 + .....,
        !            41:  *
        !            42:  *        (log(1+x) - 2s)/s is computed by
        !            43:  *
        !            44:  *            z*(L1 + z*(L2 + z*(... (L7 + z*L8)...)))
        !            45:  *
        !            46:  *        where z=s*s. (See the listing below for Lk's values.) The 
        !            47:  *        coefficients are obtained by a special Remez algorithm. 
        !            48:  *
        !            49:  * Accuracy:
        !            50:  *     Assuming no rounding error, the maximum magnitude of the approximation 
        !            51:  *     error (absolute) is 2**(-58.49) for IEEE double, and 2**(-63.63)
        !            52:  *     for VAX D format.
        !            53:  *
        !            54:  * Constants:
        !            55:  * The hexadecimal values are the intended ones for the following constants.
        !            56:  * The decimal values may be used, provided that the compiler will convert
        !            57:  * from decimal to binary accurately enough to produce the hexadecimal values
        !            58:  * shown.
        !            59:  */
        !            60: 
        !            61: #if defined(vax)||defined(tahoe)       /* VAX D format (56 bits) */
        !            62: #ifdef vax
        !            63: #define _0x(A,B)       0x/**/A/**/B
        !            64: #else  /* vax */
        !            65: #define _0x(A,B)       0x/**/B/**/A
        !            66: #endif /* vax */
        !            67: /* static double */
        !            68: /* L1     =  6.6666666666666703212E-1    , Hex  2^  0   *  .AAAAAAAAAAAAC5 */
        !            69: /* L2     =  3.9999999999970461961E-1    , Hex  2^ -1   *  .CCCCCCCCCC2684 */
        !            70: /* L3     =  2.8571428579395698188E-1    , Hex  2^ -1   *  .92492492F85782 */
        !            71: /* L4     =  2.2222221233634724402E-1    , Hex  2^ -2   *  .E38E3839B7AF2C */
        !            72: /* L5     =  1.8181879517064680057E-1    , Hex  2^ -2   *  .BA2EB4CC39655E */
        !            73: /* L6     =  1.5382888777946145467E-1    , Hex  2^ -2   *  .9D8551E8C5781D */
        !            74: /* L7     =  1.3338356561139403517E-1    , Hex  2^ -2   *  .8895B3907FCD92 */
        !            75: /* L8     =  1.2500000000000000000E-1    , Hex  2^ -2   *  .80000000000000 */
        !            76: static long        L1x[] = { _0x(aaaa,402a), _0x(aac5,aaaa)};
        !            77: static long        L2x[] = { _0x(cccc,3fcc), _0x(2684,cccc)};
        !            78: static long        L3x[] = { _0x(4924,3f92), _0x(5782,92f8)};
        !            79: static long        L4x[] = { _0x(8e38,3f63), _0x(af2c,39b7)};
        !            80: static long        L5x[] = { _0x(2eb4,3f3a), _0x(655e,cc39)};
        !            81: static long        L6x[] = { _0x(8551,3f1d), _0x(781d,e8c5)};
        !            82: static long        L7x[] = { _0x(95b3,3f08), _0x(cd92,907f)};
        !            83: static long        L8x[] = { _0x(0000,3f00), _0x(0000,0000)};
        !            84: #define       L1    (*(double*)L1x)
        !            85: #define       L2    (*(double*)L2x)
        !            86: #define       L3    (*(double*)L3x)
        !            87: #define       L4    (*(double*)L4x)
        !            88: #define       L5    (*(double*)L5x)
        !            89: #define       L6    (*(double*)L6x)
        !            90: #define       L7    (*(double*)L7x)
        !            91: #define       L8    (*(double*)L8x)
        !            92: #else  /* defined(vax)||defined(tahoe) */
        !            93: static double
        !            94: L1     =  6.6666666666667340202E-1    , /*Hex  2^ -1   *  1.5555555555592 */
        !            95: L2     =  3.9999999999416702146E-1    , /*Hex  2^ -2   *  1.999999997FF24 */
        !            96: L3     =  2.8571428742008753154E-1    , /*Hex  2^ -2   *  1.24924941E07B4 */
        !            97: L4     =  2.2222198607186277597E-1    , /*Hex  2^ -3   *  1.C71C52150BEA6 */
        !            98: L5     =  1.8183562745289935658E-1    , /*Hex  2^ -3   *  1.74663CC94342F */
        !            99: L6     =  1.5314087275331442206E-1    , /*Hex  2^ -3   *  1.39A1EC014045B */
        !           100: L7     =  1.4795612545334174692E-1    ; /*Hex  2^ -3   *  1.2F039F0085122 */
        !           101: #endif /* defined(vax)||defined(tahoe) */
        !           102: 
        !           103: double log__L(z)
        !           104: double z;
        !           105: {
        !           106: #if defined(vax)||defined(tahoe)
        !           107:     return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*(L7+z*L8))))))));
        !           108: #else  /* defined(vax)||defined(tahoe) */
        !           109:     return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*L7)))))));
        !           110: #endif /* defined(vax)||defined(tahoe) */
        !           111: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.