polevll.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* $OpenBSD: polevll.c,v 1.2 2013/11/12 20:35:09 martynas Exp $ */
  2. /*
  3. * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
  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. /* polevll.c
  18. * p1evll.c
  19. *
  20. * Evaluate polynomial
  21. *
  22. *
  23. *
  24. * SYNOPSIS:
  25. *
  26. * int N;
  27. * long double x, y, coef[N+1], polevl[];
  28. *
  29. * y = polevll( x, coef, N );
  30. *
  31. *
  32. *
  33. * DESCRIPTION:
  34. *
  35. * Evaluates polynomial of degree N:
  36. *
  37. * 2 N
  38. * y = C + C x + C x +...+ C x
  39. * 0 1 2 N
  40. *
  41. * Coefficients are stored in reverse order:
  42. *
  43. * coef[0] = C , ..., coef[N] = C .
  44. * N 0
  45. *
  46. * The function p1evll() assumes that coef[N] = 1.0 and is
  47. * omitted from the array. Its calling arguments are
  48. * otherwise the same as polevll().
  49. *
  50. *
  51. * SPEED:
  52. *
  53. * In the interest of speed, there are no checks for out
  54. * of bounds arithmetic. This routine is used by most of
  55. * the functions in the library. Depending on available
  56. * equipment features, the user may wish to rewrite the
  57. * program in microcode or assembly language.
  58. *
  59. */
  60. #include <openlibm_math.h>
  61. #include "math_private.h"
  62. /*
  63. * Polynomial evaluator:
  64. * P[0] x^n + P[1] x^(n-1) + ... + P[n]
  65. */
  66. long double
  67. __polevll(long double x, void *PP, int n)
  68. {
  69. long double y;
  70. long double *P;
  71. P = (long double *)PP;
  72. y = *P++;
  73. do {
  74. y = y * x + *P++;
  75. } while (--n);
  76. return (y);
  77. }
  78. /*
  79. * Polynomial evaluator:
  80. * x^n + P[0] x^(n-1) + P[1] x^(n-2) + ... + P[n]
  81. */
  82. long double
  83. __p1evll(long double x, void *PP, int n)
  84. {
  85. long double y;
  86. long double *P;
  87. P = (long double *)PP;
  88. n -= 1;
  89. y = x + *P++;
  90. do {
  91. y = y * x + *P++;
  92. } while (--n);
  93. return (y);
  94. }