polevlf.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* polevlf.c
  2. * p1evlf.c
  3. *
  4. * Evaluate polynomial
  5. *
  6. *
  7. *
  8. * SYNOPSIS:
  9. *
  10. * int N;
  11. * float x, y, coef[N+1], polevlf[];
  12. *
  13. * y = polevlf( x, coef, N );
  14. *
  15. *
  16. *
  17. * DESCRIPTION:
  18. *
  19. * Evaluates polynomial of degree N:
  20. *
  21. * 2 N
  22. * y = C + C x + C x +...+ C x
  23. * 0 1 2 N
  24. *
  25. * Coefficients are stored in reverse order:
  26. *
  27. * coef[0] = C , ..., coef[N] = C .
  28. * N 0
  29. *
  30. * The function p1evl() assumes that coef[N] = 1.0 and is
  31. * omitted from the array. Its calling arguments are
  32. * otherwise the same as polevl().
  33. *
  34. *
  35. * SPEED:
  36. *
  37. * In the interest of speed, there are no checks for out
  38. * of bounds arithmetic. This routine is used by most of
  39. * the functions in the library. Depending on available
  40. * equipment features, the user may wish to rewrite the
  41. * program in microcode or assembly language.
  42. *
  43. */
  44. /*
  45. Cephes Math Library Release 2.1: December, 1988
  46. Copyright 1984, 1987, 1988 by Stephen L. Moshier
  47. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  48. */
  49. #include <math.h>
  50. float polevlf( float xx, float *coef, int N )
  51. {
  52. float ans, x;
  53. float *p;
  54. int i;
  55. x = xx;
  56. p = coef;
  57. ans = *p++;
  58. /*
  59. for( i=0; i<N; i++ )
  60. ans = ans * x + *p++;
  61. */
  62. i = N;
  63. do
  64. ans = ans * x + *p++;
  65. while( --i );
  66. return( ans );
  67. }
  68. /* p1evl() */
  69. /* N
  70. * Evaluate polynomial when coefficient of x is 1.0.
  71. * Otherwise same as polevl.
  72. */
  73. float p1evlf( float xx, float *coef, int N )
  74. {
  75. float ans, x;
  76. float *p;
  77. int i;
  78. x = xx;
  79. p = coef;
  80. ans = x + *p++;
  81. i = N-1;
  82. do
  83. ans = ans * x + *p++;
  84. while( --i );
  85. return( ans );
  86. }