rational_horner3_6.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // (C) Copyright John Maddock 2007.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. // This file is machine generated, do not edit by hand
  7. // Polynomial evaluation using second order Horners rule
  8. #ifndef BOOST_MATH_TOOLS_RAT_EVAL_6_HPP
  9. #define BOOST_MATH_TOOLS_RAT_EVAL_6_HPP
  10. namespace boost{ namespace math{ namespace tools{ namespace detail{
  11. template <class T, class U, class V>
  12. inline V evaluate_rational_c_imp(const T*, const U*, const V&, const mpl::int_<0>*) BOOST_MATH_NOEXCEPT(V)
  13. {
  14. return static_cast<V>(0);
  15. }
  16. template <class T, class U, class V>
  17. inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const mpl::int_<1>*) BOOST_MATH_NOEXCEPT(V)
  18. {
  19. return static_cast<V>(a[0]) / static_cast<V>(b[0]);
  20. }
  21. template <class T, class U, class V>
  22. inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<2>*) BOOST_MATH_NOEXCEPT(V)
  23. {
  24. return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0]));
  25. }
  26. template <class T, class U, class V>
  27. inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<3>*) BOOST_MATH_NOEXCEPT(V)
  28. {
  29. return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0]));
  30. }
  31. template <class T, class U, class V>
  32. inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<4>*) BOOST_MATH_NOEXCEPT(V)
  33. {
  34. return static_cast<V>((((a[3] * x + a[2]) * x + a[1]) * x + a[0]) / (((b[3] * x + b[2]) * x + b[1]) * x + b[0]));
  35. }
  36. template <class T, class U, class V>
  37. inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<5>*) BOOST_MATH_NOEXCEPT(V)
  38. {
  39. if(x <= 1)
  40. {
  41. V x2 = x * x;
  42. V t[4];
  43. t[0] = a[4] * x2 + a[2];
  44. t[1] = a[3] * x2 + a[1];
  45. t[2] = b[4] * x2 + b[2];
  46. t[3] = b[3] * x2 + b[1];
  47. t[0] *= x2;
  48. t[2] *= x2;
  49. t[0] += static_cast<V>(a[0]);
  50. t[2] += static_cast<V>(b[0]);
  51. t[1] *= x;
  52. t[3] *= x;
  53. return (t[0] + t[1]) / (t[2] + t[3]);
  54. }
  55. else
  56. {
  57. V z = 1 / x;
  58. V z2 = 1 / (x * x);
  59. V t[4];
  60. t[0] = a[0] * z2 + a[2];
  61. t[1] = a[1] * z2 + a[3];
  62. t[2] = b[0] * z2 + b[2];
  63. t[3] = b[1] * z2 + b[3];
  64. t[0] *= z2;
  65. t[2] *= z2;
  66. t[0] += static_cast<V>(a[4]);
  67. t[2] += static_cast<V>(b[4]);
  68. t[1] *= z;
  69. t[3] *= z;
  70. return (t[0] + t[1]) / (t[2] + t[3]);
  71. }
  72. }
  73. template <class T, class U, class V>
  74. inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const mpl::int_<6>*) BOOST_MATH_NOEXCEPT(V)
  75. {
  76. if(x <= 1)
  77. {
  78. V x2 = x * x;
  79. V t[4];
  80. t[0] = a[5] * x2 + a[3];
  81. t[1] = a[4] * x2 + a[2];
  82. t[2] = b[5] * x2 + b[3];
  83. t[3] = b[4] * x2 + b[2];
  84. t[0] *= x2;
  85. t[1] *= x2;
  86. t[2] *= x2;
  87. t[3] *= x2;
  88. t[0] += static_cast<V>(a[1]);
  89. t[1] += static_cast<V>(a[0]);
  90. t[2] += static_cast<V>(b[1]);
  91. t[3] += static_cast<V>(b[0]);
  92. t[0] *= x;
  93. t[2] *= x;
  94. return (t[0] + t[1]) / (t[2] + t[3]);
  95. }
  96. else
  97. {
  98. V z = 1 / x;
  99. V z2 = 1 / (x * x);
  100. V t[4];
  101. t[0] = a[0] * z2 + a[2];
  102. t[1] = a[1] * z2 + a[3];
  103. t[2] = b[0] * z2 + b[2];
  104. t[3] = b[1] * z2 + b[3];
  105. t[0] *= z2;
  106. t[1] *= z2;
  107. t[2] *= z2;
  108. t[3] *= z2;
  109. t[0] += static_cast<V>(a[4]);
  110. t[1] += static_cast<V>(a[5]);
  111. t[2] += static_cast<V>(b[4]);
  112. t[3] += static_cast<V>(b[5]);
  113. t[0] *= z;
  114. t[2] *= z;
  115. return (t[0] + t[1]) / (t[2] + t[3]);
  116. }
  117. }
  118. }}}} // namespaces
  119. #endif // include guard