Skip to content

Commit 49486d5

Browse files
committed
Improve tolerances on impls and tests
1 parent a887a24 commit 49486d5

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

include/boost/decimal/detail/cmath/exp.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ constexpr auto exp_impl(T x) noexcept
7676
x -= numbers::ln2_v<T> * nf2;
7777
}
7878

79-
// TODO: Chris: At 32-bit, reduce the number of coefficients in the Pade appxorimant of the exp() function.
80-
// TODO: Chris: At 128-bit, add more coefficients to the Pade appxorimant of the exp() function.
8179
result = detail::exp_pade_appxroximant(x);
8280

8381
if (nf2 > 0)

include/boost/decimal/detail/cmath/impl/cosh_impl.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct cosh_table_imp
2727
private:
2828
using d32_coeffs_t = std::array<decimal32, 6>;
2929
using d64_coeffs_t = std::array<decimal64, 9>;
30-
using d128_coeffs_t = std::array<decimal128, 11>;
30+
using d128_coeffs_t = std::array<decimal128, 17>;
3131

3232
public:
3333
static constexpr d32_coeffs_t d32_coeffs =
@@ -59,7 +59,7 @@ struct cosh_table_imp
5959

6060
static constexpr d128_coeffs_t d128_coeffs =
6161
{{
62-
// Series[Cosh[x], {x, 0, 22}]
62+
// Series[Cosh[x], {x, 0, 34}]
6363
// (1), // * 1
6464
::boost::decimal::decimal128 { 5, -1 }, // * x^2
6565
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(225875452601146), UINT64_C(13965751134118914724) }, -35 }, // * x^4
@@ -71,8 +71,14 @@ struct cosh_table_imp
7171
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(259095985355981), UINT64_C(6015479145837302244) }, -47 }, // * x^16
7272
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(84671890639209), UINT64_C(10767230553416093986) }, -49 }, // * x^18
7373
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(222820764840025), UINT64_C(4062785569898205740) }, -52 }, // * x^20
74-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(482296027792262), UINT64_C(7037075391028107068) }, -55 } // * x^22
75-
}};
74+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(482296027792262), UINT64_C(7037075391028107068) }, -55 }, // * x^22
75+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(87372468802946), UINT64_C(1542176615384940434) }, -57 }, // * x^24
76+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(134419182773763), UINT64_C(3791559721646796942) }, -60 }, // * x^26
77+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(177803151817147), UINT64_C(1794430560736952558) }, -63 }, // * x^28
78+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(204371438870284), UINT64_C(366311534299067156) }, -66 }, // * x^30
79+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(206019595635366), UINT64_C(17625897212400736954) }, -69 }, // * x^32
80+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(183618177928134), UINT64_C(9987905770721758456) }, -72 }, // * x^34
81+
}};
7682
};
7783

7884
#if !(defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L) && (!defined(_MSC_VER) || _MSC_VER != 1900)

include/boost/decimal/detail/cmath/impl/exp_impl.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ constexpr auto exp_pade_appxroximant<decimal64>(decimal64 x) noexcept
6464
template <>
6565
constexpr auto exp_pade_appxroximant<decimal128>(decimal128 x) noexcept
6666
{
67-
// TODO: Chris: At 128-bit, add more coefficients to the Pade appxorimant of the exp() function.
68-
6967
// Compute exp(x) - 1 for x small.
7068

7169
// Use an order-12 Pade approximation of the exponential function.
7270
// PadeApproximant[Exp[x] - 1, {x, 0, 12, 12}].
7371

7472
using local_float_t = decimal128;
7573

74+
// Rescale the argument even further (and note the three squarings below).
75+
x /= 8;
76+
7677
const local_float_t x2 = (x * x);
7778

7879
const local_float_t top = ((((( local_float_t { boost::decimal::detail::uint128 { UINT64_C(130576843339991), UINT64_C(2348781707059460614) }, -46 } * x2
@@ -98,7 +99,13 @@ constexpr auto exp_pade_appxroximant<decimal128>(decimal128 x) noexcept
9899
+ local_float_t( +boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(54210108624275), UINT64_C(4089650035136921600) }, -33 } ))
99100
;
100101

101-
return local_float_t { 1 } + ((x * top) / bot);
102+
local_float_t result { local_float_t { 1 } + ((x * top) / bot) };
103+
104+
result *= result;
105+
result *= result;
106+
result *= result;
107+
108+
return result;
102109
}
103110

104111
} //namespace detail

test/test_cosh.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ namespace local
268268
return result_is_ok;
269269
}
270270

271-
auto test_cosh_128(const float tol_factor) -> bool
271+
auto test_cosh_128(const int tol_factor) -> bool
272272
{
273273
using decimal_type = boost::decimal::decimal128;
274274

275275
using str_ctrl_array_type = std::array<const char*, 9U>;
276276

277277
const str_ctrl_array_type ctrl_strings =
278278
{{
279-
// Table[N[Cosh[n/10 + n/100], 32], {n, 1, 19, 1}]
279+
// Table[N[Cosh[n/10 + n/100], 36], {n, 1, 19, 1}]
280280
"1.00605610287769977108879617596474784",
281281
"1.02429776427492965125226008299305162",
282282
"1.05494593094785321789908314053177016",
@@ -352,9 +352,7 @@ auto main() -> int
352352

353353
const auto result_pos64_is_ok = local::test_cosh_64(64);
354354

355-
// TODO: Chris: At 32-bit, reduce the number of coefficients in the Pade appxorimant of the exp() function.
356-
// TODO: Chris: At 128-bit, add more coefficients to the Pade appxorimant of the exp() function.
357-
const auto result_pos128_is_ok = local::test_cosh_128(1.0E10F);
355+
const auto result_pos128_is_ok = local::test_cosh_128(500000);
358356

359357
BOOST_TEST(result_pos_is_ok);
360358
BOOST_TEST(result_neg_is_ok);

test/test_sqrt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ auto main() -> int
230230
using decimal_type = boost::decimal::decimal32;
231231
using float_type = float;
232232

233-
const auto result_small_is_ok = local::test_sqrt<decimal_type, float_type>(static_cast<std::int32_t>(INT32_C(16)), 1.0E-26L, 1.0E-01L);
233+
const auto result_small_is_ok = local::test_sqrt<decimal_type, float_type>(static_cast<std::int32_t>(INT32_C(64)), 1.0E-26L, 1.0E-01L);
234234
const auto result_medium_is_ok = local::test_sqrt<decimal_type, float_type>(static_cast<std::int32_t>(INT32_C(16)), 0.9E-01L, 1.1E+01L);
235235
const auto result_large_is_ok = local::test_sqrt<decimal_type, float_type>(static_cast<std::int32_t>(INT32_C(16)), 1.0E+01L, 1.0E+26L);
236236

0 commit comments

Comments
 (0)