Skip to content

Commit 2de3757

Browse files
committed
Add sinh 64/128 impl/tests and fix typos
1 parent 08df489 commit 2de3757

File tree

3 files changed

+103
-32
lines changed

3 files changed

+103
-32
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,24 @@ struct sinh_table_imp
6060
static constexpr d128_coeffs_t d128_coeffs =
6161
{{
6262
// Series[Cosh[x], {x, 0, 34}]
63-
// (1), // * 1
64-
::boost::decimal::decimal128 { 5, -1 }, // * x^2
65-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(225875452601146), UINT64_C(13965751134118914724) }, -35 }, // * x^4
66-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(75291817533715), UINT64_C(10804165069276155440) }, -36 }, // * x^6
67-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(134449674167349), UINT64_C(4799281565792772746) }, -38 }, // * x^8
68-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(149388526852610), UINT64_C(5332535073103080820) }, -40 }, // * x^10
69-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(113173126403492), UINT64_C(11865690723015477068) }, -42 }, // * x^12
70-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(62183036485435), UINT64_C(9560282387433155251) }, -44 }, // * x^14
71-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(259095985355981), UINT64_C(6015479145837302244) }, -47 }, // * x^16
72-
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(84671890639209), UINT64_C(10767230553416093986) }, -49 }, // * x^18
73-
::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-
::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
63+
// (1), // * x
64+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(90350181040458), UINT64_C(12964998083131386532) }, -34 }, // * x^3
65+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(451750905202293), UINT64_C(9484758194528277842) }, -36 }, // * x^5
66+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(107559739333879), UINT64_C(7528774067376128516) }, -37 }, // * x^7
67+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(149388526852610), UINT64_C(5332535073103080820) }, -39 }, // * x^9
68+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(135807751684191), UINT64_C(3170782423392841514) }, -41 }, // * x^11
69+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(87056251079609), UINT64_C(13384395342406417346) }, -43 }, // * x^13
70+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(414553576569570), UINT64_C(2246069003855862950) }, -46 }, // * x^15
71+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(152409403150577), UINT64_C(4623619737181327888) }, -48 }, // * x^17
72+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(445641529680050), UINT64_C(8125571139796411480) }, -51 }, // * x^19
73+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(106105126114297), UINT64_C(13354072793200296588) }, -53 }, // * x^21
74+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(209693925127070), UINT64_C(11079921506407677690) }, -56 }, // * x^23
75+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(349489875211784), UINT64_C(6168706461539761736) }, -59 }, // * x^25
76+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(497848825088011), UINT64_C(16092452014289198134) }, -62 }, // * x^27
77+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(61311431661085), UINT64_C(3799242275031630472) }, -64 }, // * x^29
78+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(65926270603317), UINT64_C(7853896396813382020) }, -67 }, // * x^31
79+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(62430180495565), UINT64_C(13726064643322746782) }, -70 }, // * x^33
80+
::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(524623365508955), UINT64_C(15360627863698201590) }, -74 }, // * x^35
8181
}};
8282
};
8383

test/test_cosh.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ namespace local
272272
{
273273
using decimal_type = boost::decimal::decimal128;
274274

275-
using str_ctrl_array_type = std::array<const char*, 9U>;
275+
using str_ctrl_array_type = std::array<const char*, 19U>;
276276

277277
const str_ctrl_array_type ctrl_strings =
278278
{{
@@ -285,17 +285,17 @@ namespace local
285285
"1.22582183444686537963701508470572944",
286286
"1.31138966104807154082141166943546113",
287287
"1.41284130904939560893504431681606722",
288-
"1.53140558168565398981570176198960768"
289-
"1.66851855382225633267362743000999396"
290-
"1.82584096598945552946759518887583756"
291-
"2.00527833961335646927038567671483767"
292-
"2.20900405708350034304962730687406799"
293-
"2.43948568620755192849077658896354304"
294-
"2.69951486790030142594792594194283348"
295-
"2.99224112911281958915144028653782015"
296-
"3.32121003055092127036355857556155319"
297-
"3.69040611123595250949497414647005637"
298-
"4.10430115006125749566868477118593588"
288+
"1.53140558168565398981570176198960768",
289+
"1.66851855382225633267362743000999396",
290+
"1.82584096598945552946759518887583756",
291+
"2.00527833961335646927038567671483767",
292+
"2.20900405708350034304962730687406799",
293+
"2.43948568620755192849077658896354304",
294+
"2.69951486790030142594792594194283348",
295+
"2.99224112911281958915144028653782015",
296+
"3.32121003055092127036355857556155319",
297+
"3.69040611123595250949497414647005637",
298+
"4.10430115006125749566868477118593588",
299299
}};
300300

301301
std::array<decimal_type, std::tuple_size<str_ctrl_array_type>::value> cosh_values { };
@@ -325,9 +325,9 @@ namespace local
325325
from_chars(ctrl_strings[i], ctrl_strings[i] + std::strlen(ctrl_strings[i]), ctrl_values[i])
326326
);
327327

328-
const auto result_tgamma_is_ok = is_close_fraction(cosh_values[i], ctrl_values[i], my_tol);
328+
const auto result_cosh_is_ok = is_close_fraction(cosh_values[i], ctrl_values[i], my_tol);
329329

330-
result_is_ok = (result_tgamma_is_ok && result_is_ok);
330+
result_is_ok = (result_cosh_is_ok && result_is_ok);
331331
}
332332

333333
return result_is_ok;

test/test_sinh.cpp

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

271+
auto test_sinh_128(const int tol_factor) -> bool
272+
{
273+
using decimal_type = boost::decimal::decimal128;
274+
275+
using str_ctrl_array_type = std::array<const char*, 19U>;
276+
277+
const str_ctrl_array_type ctrl_strings =
278+
{{
279+
// Table[N[Sinh[n/10 + n/100], 36], {n, 1, 19, 1}]
280+
"0.110221967581171520411941593088236059",
281+
"0.221778966312451168268004699999644624",
282+
"0.336022197515927048343664664421348663",
283+
"0.454335398714097341758947808091367454",
284+
"0.578151603743454270751273401127877909",
285+
"0.708970499955166142056110066313962238",
286+
"0.848376592736843467566140720904565722",
287+
"0.998058397367814241955840599316835579",
288+
"1.15982889066360829928417764208140629",
289+
"1.33564747012417677938478052357867844",
290+
"1.52764368655956815153599423849987448",
291+
"1.73814303764750609928767015311103557",
292+
"1.96969513483974581353076445747887002",
293+
"2.22510458478057397430261017728023479",
294+
"2.50746495927954731170938115076950165",
295+
"2.82019626528976906072890033791187430",
296+
"3.16708636873578984466547274878757638",
297+
"3.55233687392505969901746060667469125",
298+
"3.98061401424380267930475594525594567",
299+
}};
300+
301+
std::array<decimal_type, std::tuple_size<str_ctrl_array_type>::value> sinh_values { };
302+
std::array<decimal_type, std::tuple_size<str_ctrl_array_type>::value> ctrl_values { };
303+
304+
int nx { 1 };
305+
306+
bool result_is_ok { true };
307+
308+
const decimal_type my_tol { std::numeric_limits<decimal_type>::epsilon() * static_cast<decimal_type>(tol_factor) };
309+
310+
for(auto i = static_cast<std::size_t>(UINT8_C(0)); i < std::tuple_size<str_ctrl_array_type>::value; ++i)
311+
{
312+
const decimal_type
313+
x_arg
314+
{
315+
decimal_type { nx, -1 }
316+
+ decimal_type { nx, -2 }
317+
};
318+
319+
++nx;
320+
321+
sinh_values[i] = sinh(x_arg);
322+
323+
static_cast<void>
324+
(
325+
from_chars(ctrl_strings[i], ctrl_strings[i] + std::strlen(ctrl_strings[i]), ctrl_values[i])
326+
);
327+
328+
const auto result_sinh_is_ok = is_close_fraction(sinh_values[i], ctrl_values[i], my_tol);
329+
330+
result_is_ok = (result_sinh_is_ok && result_is_ok);
331+
}
332+
333+
return result_is_ok;
334+
}
335+
271336
} // namespace local
272337

273338
auto main() -> int
@@ -287,6 +352,8 @@ auto main() -> int
287352

288353
const auto result_pos64_is_ok = local::test_sinh_64(64);
289354

355+
const auto result_pos128_is_ok = local::test_sinh_128(500000);
356+
290357
BOOST_TEST(result_pos_is_ok);
291358
BOOST_TEST(result_neg_is_ok);
292359

@@ -298,6 +365,8 @@ auto main() -> int
298365

299366
BOOST_TEST(result_pos64_is_ok);
300367

368+
BOOST_TEST(result_pos128_is_ok);
369+
301370
result_is_ok = (result_pos_is_ok && result_is_ok);
302371
result_is_ok = (result_neg_is_ok && result_is_ok);
303372

@@ -311,6 +380,8 @@ auto main() -> int
311380

312381
result_is_ok = (result_pos64_is_ok && result_is_ok);
313382

383+
result_is_ok = (result_pos128_is_ok && result_is_ok);
384+
314385
result_is_ok = ((boost::report_errors() == 0) && result_is_ok);
315386

316387
return (result_is_ok ? 0 : -1);

0 commit comments

Comments
 (0)