rational_horner3_5.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_5_HPP
  9. #define BOOST_MATH_TOOLS_RAT_EVAL_5_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. }}}} // namespaces
  74. #endif // include guard