Annotation of 43BSDReno/lib/libm/common_source/exp__E.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: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  *
        !            19:  * All recipients should regard themselves as participants in an ongoing
        !            20:  * research project and hence should feel obligated to report their
        !            21:  * experiences (good or bad) with these elementary function codes, using
        !            22:  * the sendbug(8) program, to the authors.
        !            23:  */
        !            24: 
        !            25: #ifndef lint
        !            26: static char sccsid[] = "@(#)exp__E.c   5.5 (Berkeley) 6/1/90";
        !            27: #endif /* not lint */
        !            28: 
        !            29: /* exp__E(x,c)
        !            30:  * ASSUMPTION: c << x  SO THAT  fl(x+c)=x.
        !            31:  * (c is the correction term for x)
        !            32:  * exp__E RETURNS
        !            33:  *
        !            34:  *                      /  exp(x+c) - 1 - x ,  1E-19 < |x| < .3465736
        !            35:  *       exp__E(x,c) =         |                    
        !            36:  *                      \  0 ,  |x| < 1E-19.
        !            37:  *
        !            38:  * DOUBLE PRECISION (IEEE 53 bits, VAX D FORMAT 56 BITS)
        !            39:  * KERNEL FUNCTION OF EXP, EXPM1, POW FUNCTIONS
        !            40:  * CODED IN C BY K.C. NG, 1/31/85;
        !            41:  * REVISED BY K.C. NG on 3/16/85, 4/16/85.
        !            42:  *
        !            43:  * Required system supported function:
        !            44:  *     copysign(x,y)   
        !            45:  *
        !            46:  * Method:
        !            47:  *     1. Rational approximation. Let r=x+c.
        !            48:  *        Based on
        !            49:  *                                   2 * sinh(r/2)     
        !            50:  *                exp(r) - 1 =   ----------------------   ,
        !            51:  *                               cosh(r/2) - sinh(r/2)
        !            52:  *        exp__E(r) is computed using
        !            53:  *                   x*x            (x/2)*W - ( Q - ( 2*P  + x*P ) )
        !            54:  *                   --- + (c + x*[---------------------------------- + c ])
        !            55:  *                    2                          1 - W
        !            56:  *        where  P := p1*x^2 + p2*x^4,
        !            57:  *               Q := q1*x^2 + q2*x^4 (for 56 bits precision, add q3*x^6)
        !            58:  *               W := x/2-(Q-x*P),
        !            59:  *
        !            60:  *        (See the listing below for the values of p1,p2,q1,q2,q3. The poly-
        !            61:  *         nomials P and Q may be regarded as the approximations to sinh
        !            62:  *         and cosh :
        !            63:  *             sinh(r/2) =  r/2 + r * P  ,  cosh(r/2) =  1 + Q . )
        !            64:  *
        !            65:  *         The coefficients were obtained by a special Remez algorithm.
        !            66:  *
        !            67:  * Approximation error:
        !            68:  *
        !            69:  *   | exp(x) - 1                         |        2**(-57),  (IEEE double)
        !            70:  *   | ------------  -  (exp__E(x,0)+x)/x  |  <= 
        !            71:  *   |      x                             |        2**(-69).  (VAX D)
        !            72:  *
        !            73:  * Constants:
        !            74:  * The hexadecimal values are the intended ones for the following constants.
        !            75:  * The decimal values may be used, provided that the compiler will convert
        !            76:  * from decimal to binary accurately enough to produce the hexadecimal values
        !            77:  * shown.
        !            78:  */
        !            79: 
        !            80: #include "mathimpl.h"
        !            81: 
        !            82: vc(p1, 1.5150724356786683059E-2 ,3abe,3d78,066a,67e1,  -6, .F83ABE67E1066A)
        !            83: vc(p2, 6.3112487873718332688E-5 ,5b42,3984,0173,48cd, -13, .845B4248CD0173)
        !            84: vc(q1, 1.1363478204690669916E-1 ,b95a,3ee8,ec45,44a2,  -3, .E8B95A44A2EC45)
        !            85: vc(q2, 1.2624568129896839182E-3 ,7905,3ba5,f5e7,72e4,  -9, .A5790572E4F5E7)
        !            86: vc(q3, 1.5021856115869022674E-6 ,9eb4,36c9,c395,604a, -19, .C99EB4604AC395)
        !            87: 
        !            88: ic(p1, 1.3887401997267371720E-2,  -7, 1.C70FF8B3CC2CF)
        !            89: ic(p2, 3.3044019718331897649E-5, -15, 1.15317DF4526C4)
        !            90: ic(q1, 1.1110813732786649355E-1,  -4, 1.C719538248597)
        !            91: ic(q2, 9.9176615021572857300E-4, -10, 1.03FC4CB8C98E8)
        !            92: 
        !            93: #ifdef vccast
        !            94: #define       p1    vccast(p1)
        !            95: #define       p2    vccast(p2)
        !            96: #define       q1    vccast(q1)
        !            97: #define       q2    vccast(q2)
        !            98: #define       q3    vccast(q3)
        !            99: #endif
        !           100: 
        !           101: double exp__E(x,c)
        !           102: double x,c;
        !           103: {
        !           104:        const static double zero=0.0, one=1.0, half=1.0/2.0, small=1.0E-19;
        !           105:        double z,p,q,xp,xh,w;
        !           106:        if(copysign(x,one)>small) {
        !           107:            z = x*x  ;
        !           108:           p = z*( p1 +z* p2 );
        !           109: #if defined(vax)||defined(tahoe)
        !           110:            q = z*( q1 +z*( q2 +z* q3 ));
        !           111: #else  /* defined(vax)||defined(tahoe) */
        !           112:            q = z*( q1 +z*  q2 );
        !           113: #endif /* defined(vax)||defined(tahoe) */
        !           114:            xp= x*p     ; 
        !           115:           xh= x*half  ;
        !           116:            w = xh-(q-xp)  ;
        !           117:           p = p+p;
        !           118:           c += x*((xh*w-(q-(p+xp)))/(one-w)+c);
        !           119:           return(z*half+c);
        !           120:        }
        !           121:        /* end of |x| > small */
        !           122: 
        !           123:        else {
        !           124:            if(x!=zero) one+small;      /* raise the inexact flag */
        !           125:            return(copysign(zero,x));
        !           126:        }
        !           127: }

unix.superglobalmegacorp.com

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