polevl.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* polevl.c
  2. * p1evl.c
  3. *
  4. * Evaluate polynomial
  5. *
  6. *
  7. *
  8. * SYNOPSIS:
  9. *
  10. * int N;
  11. * double x, y, coef[N+1], polevl[];
  12. *
  13. * y = polevl( 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. double polevl( x, coef, N )
  50. double x;
  51. double coef[];
  52. int N;
  53. {
  54. double ans;
  55. int i;
  56. double *p;
  57. p = coef;
  58. ans = *p++;
  59. i = N;
  60. do
  61. ans = ans * x + *p++;
  62. while( --i );
  63. return( ans );
  64. }
  65. /* p1evl() */
  66. /* N
  67. * Evaluate polynomial when coefficient of x is 1.0.
  68. * Otherwise same as polevl.
  69. */
  70. double p1evl( x, coef, N )
  71. double x;
  72. double coef[];
  73. int N;
  74. {
  75. double ans;
  76. double *p;
  77. int i;
  78. p = coef;
  79. ans = x + *p++;
  80. i = N-1;
  81. do
  82. ans = ans * x + *p++;
  83. while( --i );
  84. return( ans );
  85. }