Annotation of 43BSDTahoe/cci/libM/logd.c, revision 1.1

1.1     ! root        1: /*     @(#)log.c       4.1     12/25/82        */
        !             2: 
        !             3: /*
        !             4:  * log returns the natural logarithm of its floating
        !             5:  * point argument.
        !             6:  *
        !             7:  * New version by Les Powers (3/31/85).
        !             8:  */
        !             9: 
        !            10: 
        !            11: #include <errno.h>
        !            12: #include <math.h>
        !            13: #include "logd.h"
        !            14: 
        !            15: 
        !            16: static double  log2    = 0.693147180559945309e0;
        !            17: static double  recip_ln10      = 1./2.302585092994045684;
        !            18: static double  p1      = 1.;
        !            19: static double  p2      = -.5;
        !            20: static double  p3      = 1./3.;
        !            21: static double  p4      = -1./4.;
        !            22: 
        !            23: int    errno;
        !            24: 
        !            25: 
        !            26: double
        !            27: log(arg)
        !            28: double arg;
        !            29: {
        !            30:        double z;
        !            31:        union {
        !            32:          double d;
        !            33:          struct {
        !            34:            unsigned i0;
        !            35:            unsigned i1;
        !            36:          } i;
        !            37:          struct {
        !            38:            unsigned char b0;
        !            39:            unsigned char b1;
        !            40:            unsigned char b2;
        !            41:            unsigned char b3;
        !            42:          } b;
        !            43:        } f0,f1,a0;
        !            44:        register int ta1;
        !            45:        if (arg <= 0.) {
        !            46:                errno = EDOM;
        !            47:                return(-HUGE);
        !            48:        }
        !            49:        f1.d  = arg;
        !            50:        f0.i.i0 = f1.i.i0 + f1.i.i0;
        !            51:        if ( f1.i.i0 >= 0x40800000 ) {
        !            52:          f1.i.i0 = (f1.i.i0 & 0x007fffff) | 0x40800000;
        !            53:          a0.i.i0 =  f1.i.i0 & 0x40ff8000;
        !            54:          a0.i.i1 = 0;
        !            55:          f1.d    =  (f1.d - a0.d) * rp0[f0.b.b1];
        !            56:          ta1 = f1.d;
        !            57:          z  = (f1.d - ta1) * rp1[ta1];
        !            58:          return( z*(p1+z*(p2+z*(p3+z*p4))) +
        !            59:                lp1[ta1] + lp0[f0.b.b1] + le[f0.b.b0] );
        !            60:        }
        !            61:        else {
        !            62:          f1.i.i0 = (f1.i.i0 & 0x007fffff) | 0x40000000;
        !            63:          a0.i.i0 = (f1.i.i0 & 0x40ff8000) + 0x00008000;
        !            64:          a0.i.i1 = 0;
        !            65:          f1.d    = (a0.d - f1.d) * rn0[f0.b.b1];
        !            66:          ta1 = f1.d;
        !            67:          z  = (ta1-f1.d) * rn1[ta1];
        !            68:          return( z*(p1+z*(p2+z*(p3+z*p4))) +
        !            69:                ln1[ta1] + ln0[f0.b.b1] + le[f0.b.b0] );
        !            70:        }
        !            71: }
        !            72: 
        !            73: double
        !            74: log10(arg)
        !            75: double arg;
        !            76: {
        !            77:        return(log(arg)*recip_ln10);
        !            78: }

unix.superglobalmegacorp.com

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