|
7 | 7 | #define BOOST_DECIMAL_DETAIL_CMATH_EXPM1_HPP |
8 | 8 |
|
9 | 9 | #include <boost/decimal/fwd.hpp> // NOLINT(llvm-include-order) |
10 | | -#include <boost/decimal/detail/type_traits.hpp> |
| 10 | +#include <boost/decimal/detail/cmath/impl/expm1_impl.hpp> |
11 | 11 | #include <boost/decimal/detail/concepts.hpp> |
12 | 12 | #include <boost/decimal/detail/config.hpp> |
| 13 | +#include <boost/decimal/detail/type_traits.hpp> |
13 | 14 | #include <boost/decimal/numbers.hpp> |
14 | 15 |
|
15 | 16 | #ifndef BOOST_DECIMAL_BUILD_MODULE |
16 | | -#include <array> |
| 17 | +#include <cmath> |
17 | 18 | #include <type_traits> |
18 | 19 | #endif |
19 | 20 |
|
@@ -70,66 +71,7 @@ constexpr auto expm1_impl(T x) noexcept |
70 | 71 | } |
71 | 72 | else |
72 | 73 | { |
73 | | - // Specifically derive a polynomial expansion for Exp[x] - 1 for this work. |
74 | | - // Table[{x, Exp[x] - 1}, {x, -Log[2], Log[2], 1/60}] |
75 | | - // N[%, 48] |
76 | | - // Fit[%, {x, x^2, x^3, x^4, x^5, x^6, x^7, x^8, x^9, x^10, x^11, x^12, x^13, x^14}, x] |
77 | | - |
78 | | - // 0.1000000000000000003213692169066381945529176657E+01 x |
79 | | - // + 0.4999999999999999998389405741198241227273662223E+00 x^2 |
80 | | - // + 0.1666666666666664035765593562709186076539985328E+00 x^3 |
81 | | - // + 0.4166666666666666934614928838666442575683452206E-01 x^4 |
82 | | - // + 0.8333333333339521841328202617206868796855583809E-02 x^5 |
83 | | - // + 0.1388888888888953513176946682731620625302469979E-02 x^6 |
84 | | - // + 0.1984126983488689186859793276462049624439889135E-03 x^7 |
85 | | - // + 0.2480158730001499149369647648735612017495156006E-04 x^8 |
86 | | - // + 0.2755732258782898252481007286813761544775538366E-05 x^9 |
87 | | - // + 0.2755732043147979013276287368071846972098889744E-06 x^10 |
88 | | - // + 0.2505116286861719378770371641094067075234027345E-07 x^11 |
89 | | - // + 0.2087632598463662328337672597832718168295672334E-08 x^12 |
90 | | - // + 0.1619385892296180390338553597911165126625722485E-09 x^13 |
91 | | - // + 0.1154399218598221557485183048765404442959841646E-10 x^14 |
92 | | - |
93 | | - using coefficient_array_type = std::array<T, static_cast<std::size_t>(UINT8_C(14))>; |
94 | | - |
95 | | - #if (defined(__clang__) && (__clang__ < 6)) |
96 | | - # pragma clang diagnostic push |
97 | | - # pragma clang diagnostic ignored "-Wmissing-braces" |
98 | | - #endif |
99 | | - |
100 | | - constexpr auto coefficient_table = |
101 | | - coefficient_array_type |
102 | | - { |
103 | | - T { UINT64_C(100000000000000000), -17 - 0 }, // * x |
104 | | - T { UINT64_C(500000000000000000), -18 - 0 }, // * x^2 |
105 | | - T { UINT64_C(166666666666666404), -18 - 0 }, // * x^3 |
106 | | - T { UINT64_C(416666666666666693), -18 - 1 }, // * x^4 |
107 | | - T { UINT64_C(833333333333952184), -18 - 2 }, // * x^5 |
108 | | - T { UINT64_C(138888888888895351), -18 - 2 }, // * x^6 |
109 | | - T { UINT64_C(198412698348868919), -18 - 3 }, // * x^7 |
110 | | - T { UINT64_C(248015873000149915), -18 - 4 }, // * x^8 |
111 | | - T { UINT64_C(275573225878289825), -18 - 5 }, // * x^9 |
112 | | - T { UINT64_C(275573204314797901), -18 - 6 }, // * x^10 |
113 | | - T { UINT64_C(250511628686171938), -18 - 7 }, // * x^11 |
114 | | - T { UINT64_C(208763259846366233), -18 - 8 }, // * x^12 |
115 | | - T { UINT64_C(161938589229618039), -18 - 9 }, // * x^13 |
116 | | - T { UINT64_C(115439921859822156), -18 - 10 } // * x^14 |
117 | | - }; |
118 | | - |
119 | | - #if (defined(__clang__) && (__clang__ < 6)) |
120 | | - # pragma clang diagnostic pop |
121 | | - #endif |
122 | | - |
123 | | - auto rit = coefficient_table.crbegin() + static_cast<std::size_t>((sizeof(T) == 4U) ? 5U : 0U); |
124 | | - |
125 | | - result = *rit; |
126 | | - |
127 | | - while(rit != coefficient_table.crend()) |
128 | | - { |
129 | | - result = fma(result, x, *rit++); |
130 | | - } |
131 | | - |
132 | | - result *= x; |
| 74 | + result = x * detail::expm1_series_expansion(x); |
133 | 75 | } |
134 | 76 | } |
135 | 77 |
|
|
0 commit comments