home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / math / cephes / ldouble / exp2l.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-17  |  2.7 KB  |  148 lines

  1. /*                            exp2l.c
  2.  *
  3.  *    Base 2 exponential function, long double precision
  4.  *
  5.  *
  6.  *
  7.  * SYNOPSIS:
  8.  *
  9.  * long double x, y, exp2l();
  10.  *
  11.  * y = exp2l( x );
  12.  *
  13.  *
  14.  *
  15.  * DESCRIPTION:
  16.  *
  17.  * Returns 2 raised to the x power.
  18.  *
  19.  * Range reduction is accomplished by separating the argument
  20.  * into an integer k and fraction f such that
  21.  *     x    k  f
  22.  *    2  = 2  2.
  23.  *
  24.  * A Pade' form
  25.  *
  26.  *   1 + 2x P(x**2) / (Q(x**2) - x P(x**2) )
  27.  *
  28.  * approximates 2**x in the basic range [-0.5, 0.5].
  29.  *
  30.  *
  31.  * ACCURACY:
  32.  *
  33.  *                      Relative error:
  34.  * arithmetic   domain     # trials      peak         rms
  35.  *    IEEE      +-16300     300000      9.1e-20     2.6e-20
  36.  *
  37.  *
  38.  * See exp.c for comments on error amplification.
  39.  *
  40.  *
  41.  * ERROR MESSAGES:
  42.  *
  43.  *   message         condition      value returned
  44.  * exp2l underflow   x < -16382        0.0
  45.  * exp2l overflow    x >= 16384       MAXNUM
  46.  *
  47.  */
  48.  
  49.  
  50. /*
  51. Cephes Math Library Release 2.2:  January, 1991
  52. Copyright 1984, 1991 by Stephen L. Moshier
  53. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  54. */
  55.  
  56.  
  57.  
  58. #include "mconf.h"
  59. static char fname[] = {"exp2l"};
  60.  
  61. #ifdef UNK
  62. static long double P[] = {
  63.  6.0614853552242266094567E1L,
  64.  3.0286971917562792508623E4L,
  65.  2.0803843631901852422887E6L,
  66. };
  67. static long double Q[] = {
  68. /* 1.0000000000000000000000E0,*/
  69.  1.7492876999891839021063E3L,
  70.  3.2772515434906797273099E5L,
  71.  6.0027204078348487957118E6L,
  72. };
  73. #endif
  74.  
  75.  
  76. #ifdef IBMPC
  77. static short P[] = {
  78. 0xffd8,0x6ad6,0x9c2b,0xf275,0x4004,
  79. 0x3426,0x2dc5,0xf19f,0xec9d,0x400d,
  80. 0x7ec0,0xd041,0x02e7,0xfdf4,0x4013,
  81. };
  82. static short Q[] = {
  83. /*0x0000,0x0000,0x0000,0x8000,0x3fff,*/
  84. 0x575b,0x9b93,0x34d6,0xdaa9,0x4009,
  85. 0xe38d,0x6d74,0xa4f0,0xa005,0x4011,
  86. 0xb37e,0xcfba,0x40d0,0xb730,0x4015,
  87. };
  88. #endif
  89.  
  90. #ifdef MIEEE
  91. static long P[] = {
  92. 0x40040000,0xf2759c2b,0x6ad6ffd8,
  93. 0x400d0000,0xec9df19f,0x2dc53426,
  94. 0x40130000,0xfdf402e7,0xd0417ec0,
  95. };
  96. static long Q[] = {
  97. /*0x3fff0000,0x80000000,0x00000000,*/
  98. 0x40090000,0xdaa934d6,0x9b93575b,
  99. 0x40110000,0xa005a4f0,0x6d74e38d,
  100. 0x40150000,0xb73040d0,0xcfbab37e,
  101. };
  102. #endif
  103.  
  104. #define MAXL2 16384.0L
  105. #define MINL2 -16382.0L
  106.  
  107.  
  108. extern long double MAXNUML;
  109.  
  110. long double exp2l(x)
  111. long double x;
  112. {
  113. long double px, xx;
  114. int n;
  115. long double polevll(), p1evll(), floorl(), ldexpl();
  116.  
  117. if( x >= MAXL2)
  118.     {
  119.     mtherr( fname, OVERFLOW );
  120.     return( MAXNUML );
  121.     }
  122.  
  123. if( x < MINL2 )
  124.     {
  125.     mtherr( fname, UNDERFLOW );
  126.     return(0.0L);
  127.     }
  128.  
  129. xx = x;    /* save x */
  130. /* separate into integer and fractional parts */
  131. px = floorl(x+0.5L);
  132. n = px;
  133. x = x - px;
  134.  
  135. /* rational approximation
  136.  * exp2(x) = 1.0 +  2xP(xx)/(Q(xx) - P(xx))
  137.  * where xx = x**2
  138.  */
  139. xx = x * x;
  140. px = x * polevll( xx, P, 2 );
  141. x =  px / ( p1evll( xx, Q, 3 ) - px );
  142. x = 1.0 + ldexpl( x, 1 );
  143.  
  144. /* scale by power of 2 */
  145. x = ldexpl( x, n );
  146. return(x);
  147. }
  148.