1: /*
   2:  * exp - calculate the exponential function of arg.
   3:  *
   4:  *   The coefficients are #1069 from Hart and Cheney. (22.35D)
   5:  */
   6: 
   7: #include <errno.h>
   8: #include <math.h>
   9: 
  10: int   errno;
  11: static double   p0   = .2080384346694663001443843411e7;
  12: static double   p1   = .3028697169744036299076048876e5;
  13: static double   p2   = .6061485330061080841615584556e2;
  14: static double   q0   = .6002720360238832528230907598e7;
  15: static double   q1   = .3277251518082914423057964422e6;
  16: static double   q2   = .1749287689093076403844945335e4;
  17: static double   log2e   = 1.4426950408889634073599247;
  18: static double   sqrt2   = 1.4142135623730950488016887;
  19: static double   maxf   = 10000;
  20: 
  21: double
  22: exp(arg)
  23: double arg;
  24:    {
  25:    double fract;
  26:    double temp1, temp2, xsq;
  27:    int ent;
  28: 
  29:    if(arg == 0.)
  30:       return(1.);
  31:    if(arg < -maxf)
  32:       return(0.);
  33:    if(arg > maxf) {
  34:       errno = ERANGE;
  35:       return(HUGE);
  36:    }
  37:    arg *= log2e;
  38:    ent = floor(arg);
  39:    fract = (arg-ent) - 0.5;
  40:    xsq = fract*fract;
  41:    temp1 = ((p2*xsq+p1)*xsq+p0)*fract;
  42:    temp2 = ((1.0*xsq+q2)*xsq+q1)*xsq + q0;
  43:    return(ldexp(sqrt2*(temp2+temp1)/(temp2-temp1), ent));
  44:    }

Defined functions

exp defined in line 21; used 3 times

Defined variables

errno defined in line 10; used 1 times
  • in line 34
log2e defined in line 17; used 1 times
  • in line 37
maxf defined in line 19; used 2 times
p0 defined in line 11; used 1 times
  • in line 41
p1 defined in line 12; used 1 times
  • in line 41
p2 defined in line 13; used 1 times
  • in line 41
q0 defined in line 14; used 1 times
  • in line 42
q1 defined in line 15; used 1 times
  • in line 42
q2 defined in line 16; used 1 times
  • in line 42
sqrt2 defined in line 18; used 1 times
  • in line 43
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 937
Valid CSS Valid XHTML 1.0 Strict