File indexing completed on 2025-01-18 09:40:39
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_MATH_TOOLS_RAT_EVAL_6_HPP
0010 #define BOOST_MATH_TOOLS_RAT_EVAL_6_HPP
0011
0012 namespace boost{ namespace math{ namespace tools{ namespace detail{
0013
0014 template <class T, class U, class V>
0015 inline V evaluate_rational_c_imp(const T*, const U*, const V&, const std::integral_constant<int, 0>*) BOOST_MATH_NOEXCEPT(V)
0016 {
0017 return static_cast<V>(0);
0018 }
0019
0020 template <class T, class U, class V>
0021 inline V evaluate_rational_c_imp(const T* a, const U* b, const V&, const std::integral_constant<int, 1>*) BOOST_MATH_NOEXCEPT(V)
0022 {
0023 return static_cast<V>(a[0]) / static_cast<V>(b[0]);
0024 }
0025
0026 template <class T, class U, class V>
0027 inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const std::integral_constant<int, 2>*) BOOST_MATH_NOEXCEPT(V)
0028 {
0029 return static_cast<V>((a[1] * x + a[0]) / (b[1] * x + b[0]));
0030 }
0031
0032 template <class T, class U, class V>
0033 inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const std::integral_constant<int, 3>*) BOOST_MATH_NOEXCEPT(V)
0034 {
0035 return static_cast<V>(((a[2] * x + a[1]) * x + a[0]) / ((b[2] * x + b[1]) * x + b[0]));
0036 }
0037
0038 template <class T, class U, class V>
0039 inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const std::integral_constant<int, 4>*) BOOST_MATH_NOEXCEPT(V)
0040 {
0041 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]));
0042 }
0043
0044 template <class T, class U, class V>
0045 inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const std::integral_constant<int, 5>*) BOOST_MATH_NOEXCEPT(V)
0046 {
0047 if(x <= 1)
0048 {
0049 V x2 = x * x;
0050 V t[4];
0051 t[0] = a[4] * x2 + a[2];
0052 t[1] = a[3] * x2 + a[1];
0053 t[2] = b[4] * x2 + b[2];
0054 t[3] = b[3] * x2 + b[1];
0055 t[0] *= x2;
0056 t[2] *= x2;
0057 t[0] += static_cast<V>(a[0]);
0058 t[2] += static_cast<V>(b[0]);
0059 t[1] *= x;
0060 t[3] *= x;
0061 return (t[0] + t[1]) / (t[2] + t[3]);
0062 }
0063 else
0064 {
0065 V z = 1 / x;
0066 V z2 = 1 / (x * x);
0067 V t[4];
0068 t[0] = a[0] * z2 + a[2];
0069 t[1] = a[1] * z2 + a[3];
0070 t[2] = b[0] * z2 + b[2];
0071 t[3] = b[1] * z2 + b[3];
0072 t[0] *= z2;
0073 t[2] *= z2;
0074 t[0] += static_cast<V>(a[4]);
0075 t[2] += static_cast<V>(b[4]);
0076 t[1] *= z;
0077 t[3] *= z;
0078 return (t[0] + t[1]) / (t[2] + t[3]);
0079 }
0080 }
0081
0082 template <class T, class U, class V>
0083 inline V evaluate_rational_c_imp(const T* a, const U* b, const V& x, const std::integral_constant<int, 6>*) BOOST_MATH_NOEXCEPT(V)
0084 {
0085 if(x <= 1)
0086 {
0087 V x2 = x * x;
0088 V t[4];
0089 t[0] = a[5] * x2 + a[3];
0090 t[1] = a[4] * x2 + a[2];
0091 t[2] = b[5] * x2 + b[3];
0092 t[3] = b[4] * x2 + b[2];
0093 t[0] *= x2;
0094 t[1] *= x2;
0095 t[2] *= x2;
0096 t[3] *= x2;
0097 t[0] += static_cast<V>(a[1]);
0098 t[1] += static_cast<V>(a[0]);
0099 t[2] += static_cast<V>(b[1]);
0100 t[3] += static_cast<V>(b[0]);
0101 t[0] *= x;
0102 t[2] *= x;
0103 return (t[0] + t[1]) / (t[2] + t[3]);
0104 }
0105 else
0106 {
0107 V z = 1 / x;
0108 V z2 = 1 / (x * x);
0109 V t[4];
0110 t[0] = a[0] * z2 + a[2];
0111 t[1] = a[1] * z2 + a[3];
0112 t[2] = b[0] * z2 + b[2];
0113 t[3] = b[1] * z2 + b[3];
0114 t[0] *= z2;
0115 t[1] *= z2;
0116 t[2] *= z2;
0117 t[3] *= z2;
0118 t[0] += static_cast<V>(a[4]);
0119 t[1] += static_cast<V>(a[5]);
0120 t[2] += static_cast<V>(b[4]);
0121 t[3] += static_cast<V>(b[5]);
0122 t[0] *= z;
0123 t[2] *= z;
0124 return (t[0] + t[1]) / (t[2] + t[3]);
0125 }
0126 }
0127
0128
0129 }}}}
0130
0131 #endif
0132