1: /*
   2:  * log - calculate the natural logarithm of arg.
   3:  *
   4:  * The coefficients are #2705 from Hart & Cheney. (19.38D)
   5:  */
   6: 
   7: #include <errno.h>
   8: #include <math.h>
   9: 
  10: int   errno;
  11: double   frexp();
  12: static double   log2   = 0.693147180559945309e0;
  13: static double   ln10   = 2.302585092994045684;
  14: static double   sqrto2   = 0.707106781186547524e0;
  15: static double   p0   = -.240139179559210510e2;
  16: static double   p1   = 0.309572928215376501e2;
  17: static double   p2   = -.963769093368686593e1;
  18: static double   p3   = 0.421087371217979714e0;
  19: static double   q0   = -.120069589779605255e2;
  20: static double   q1   = 0.194809660700889731e2;
  21: static double   q2   = -.891110902798312337e1;
  22: 
  23: double
  24: log(arg)
  25: double arg;
  26:    {
  27:    double x, z, zsq, temp;
  28:    int exp;
  29: 
  30:    if(arg <= 0.) {
  31:       errno = EDOM;
  32:       return(-HUGE);
  33:    }
  34:    x = frexp(arg,&exp);
  35:    while(x<0.5) {
  36:       x = x*2;
  37:       exp = exp-1;
  38:    }
  39:    if(x<sqrto2) {
  40:       x = 2*x;
  41:       exp = exp-1;
  42:    }
  43: 
  44:    z = (x-1)/(x+1);
  45:    zsq = z*z;
  46: 
  47:    temp = ((p3*zsq + p2)*zsq + p1)*zsq + p0;
  48:    temp = temp/(((1.0*zsq + q2)*zsq + q1)*zsq + q0);
  49:    temp = temp*z + exp*log2;
  50:    return(temp);
  51:    }
  52: 
  53: double
  54: log10(arg)
  55: double arg;
  56:    {
  57: 
  58:    return(log(arg)/ln10);
  59:    }

Defined functions

log defined in line 23; used 4 times
log10 defined in line 53; never used

Defined variables

errno defined in line 10; used 1 times
  • in line 31
ln10 defined in line 13; used 1 times
  • in line 58
log2 defined in line 12; used 1 times
  • in line 49
p0 defined in line 15; used 1 times
  • in line 47
p1 defined in line 16; used 1 times
  • in line 47
p2 defined in line 17; used 1 times
  • in line 47
p3 defined in line 18; used 1 times
  • in line 47
q0 defined in line 19; used 1 times
  • in line 48
q1 defined in line 20; used 1 times
  • in line 48
q2 defined in line 21; used 1 times
  • in line 48
sqrto2 defined in line 14; used 1 times
  • in line 39
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 883
Valid CSS Valid XHTML 1.0 Strict