exp10f.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* exp10f.c
  2. *
  3. * Base 10 exponential function
  4. * (Common antilogarithm)
  5. *
  6. *
  7. *
  8. * SYNOPSIS:
  9. *
  10. * float x, y, exp10f();
  11. *
  12. * y = exp10f( x );
  13. *
  14. *
  15. *
  16. * DESCRIPTION:
  17. *
  18. * Returns 10 raised to the x power.
  19. *
  20. * Range reduction is accomplished by expressing the argument
  21. * as 10**x = 2**n 10**f, with |f| < 0.5 log10(2).
  22. * A polynomial approximates 10**f.
  23. *
  24. *
  25. *
  26. * ACCURACY:
  27. *
  28. * Relative error:
  29. * arithmetic domain # trials peak rms
  30. * IEEE -38,+38 100000 9.8e-8 2.8e-8
  31. *
  32. * ERROR MESSAGES:
  33. *
  34. * message condition value returned
  35. * exp10 underflow x < -MAXL10 0.0
  36. * exp10 overflow x > MAXL10 MAXNUM
  37. *
  38. * IEEE single arithmetic: MAXL10 = 38.230809449325611792.
  39. *
  40. */
  41. /*
  42. Cephes Math Library Release 2.2: June, 1992
  43. Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
  44. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  45. */
  46. #include <math.h>
  47. static float P[] = {
  48. 2.063216740311022E-001,
  49. 5.420251702225484E-001,
  50. 1.171292686296281E+000,
  51. 2.034649854009453E+000,
  52. 2.650948748208892E+000,
  53. 2.302585167056758E+000
  54. };
  55. /*static float LOG102 = 3.01029995663981195214e-1;*/
  56. static float LOG210 = 3.32192809488736234787e0;
  57. static float LG102A = 3.00781250000000000000E-1;
  58. static float LG102B = 2.48745663981195213739E-4;
  59. static float MAXL10 = 38.230809449325611792;
  60. extern float MAXNUMF;
  61. float floorf(float), ldexpf(float, int), polevlf(float, float *, int);
  62. float exp10f(float xx)
  63. {
  64. float x, px, qx;
  65. short n;
  66. x = xx;
  67. if( x > MAXL10 )
  68. {
  69. mtherr( "exp10f", OVERFLOW );
  70. return( MAXNUMF );
  71. }
  72. if( x < -MAXL10 ) /* Would like to use MINLOG but can't */
  73. {
  74. mtherr( "exp10f", UNDERFLOW );
  75. return(0.0);
  76. }
  77. /* The following is necessary because range reduction blows up: */
  78. if( x == 0 )
  79. return(1.0);
  80. /* Express 10**x = 10**g 2**n
  81. * = 10**g 10**( n log10(2) )
  82. * = 10**( g + n log10(2) )
  83. */
  84. px = x * LOG210;
  85. qx = floorf( px + 0.5 );
  86. n = qx;
  87. x -= qx * LG102A;
  88. x -= qx * LG102B;
  89. /* rational approximation for exponential
  90. * of the fractional part:
  91. * 10**x - 1 = 2x P(x**2)/( Q(x**2) - P(x**2) )
  92. */
  93. px = 1.0 + x * polevlf( x, P, 5 );
  94. /* multiply by power of 2 */
  95. x = ldexpf( px, n );
  96. return(x);
  97. }