1
0

__polevll.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* origin: OpenBSD /usr/src/lib/libm/src/polevll.c */
  2. /*
  3. * Copyright (c) 2008 Stephen L. Moshier <[email protected]>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /*
  18. * Evaluate polynomial
  19. *
  20. *
  21. * SYNOPSIS:
  22. *
  23. * int N;
  24. * long double x, y, coef[N+1], polevl[];
  25. *
  26. * y = polevll( x, coef, N );
  27. *
  28. *
  29. * DESCRIPTION:
  30. *
  31. * Evaluates polynomial of degree N:
  32. *
  33. * 2 N
  34. * y = C + C x + C x +...+ C x
  35. * 0 1 2 N
  36. *
  37. * Coefficients are stored in reverse order:
  38. *
  39. * coef[0] = C , ..., coef[N] = C .
  40. * N 0
  41. *
  42. * The function p1evll() assumes that coef[N] = 1.0 and is
  43. * omitted from the array. Its calling arguments are
  44. * otherwise the same as polevll().
  45. *
  46. *
  47. * SPEED:
  48. *
  49. * In the interest of speed, there are no checks for out
  50. * of bounds arithmetic. This routine is used by most of
  51. * the functions in the library. Depending on available
  52. * equipment features, the user may wish to rewrite the
  53. * program in microcode or assembly language.
  54. *
  55. */
  56. #include "libm.h"
  57. /*
  58. * Polynomial evaluator:
  59. * P[0] x^n + P[1] x^(n-1) + ... + P[n]
  60. */
  61. long double __polevll(long double x, const long double *P, int n)
  62. {
  63. long double y;
  64. y = *P++;
  65. do {
  66. y = y * x + *P++;
  67. } while (--n);
  68. return y;
  69. }
  70. /*
  71. * Polynomial evaluator:
  72. * x^n + P[0] x^(n-1) + P[1] x^(n-2) + ... + P[n]
  73. */
  74. long double __p1evll(long double x, const long double *P, int n)
  75. {
  76. long double y;
  77. n -= 1;
  78. y = x + *P++;
  79. do {
  80. y = y * x + *P++;
  81. } while (--n);
  82. return y;
  83. }