Skip to content

Commit c2b3312

Browse files
committed
Add a few more tgamma at 128 bit tests
1 parent d4bea7a commit c2b3312

File tree

1 file changed

+61
-20
lines changed

1 file changed

+61
-20
lines changed

test/test_tgamma.cpp

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,64 @@ namespace local
316316

317317
return result_is_ok;
318318
}
319+
320+
auto test_tgamma_128(const int tol_factor) -> bool
321+
{
322+
using decimal_type = boost::decimal::decimal128;
323+
324+
using str_ctrl_array_type = std::array<const char*, 9U>;
325+
326+
const str_ctrl_array_type ctrl_strings =
327+
{{
328+
// Table[N[Gamma[(100 n + 10 n + 1)/100], 33], {n, 1, 9, 1}]
329+
"0.947395504039301942134227647281424",
330+
"1.10784755653406415338349971053114",
331+
"2.71139823924390323650711692085896",
332+
"10.2754040920152050479188001843206",
333+
"53.1934282525008207389522379291890",
334+
"350.998609824200588801455504140098",
335+
"2825.09453680418713613816084109635",
336+
"26903.6719467497675679082571845063",
337+
"296439.082102472192334520537379648"
338+
}};
339+
340+
std::array<decimal_type, std::tuple_size<str_ctrl_array_type>::value> tg_values { };
341+
std::array<decimal_type, std::tuple_size<str_ctrl_array_type>::value> ctrl_values { };
342+
343+
int n { 1 };
344+
345+
bool result_is_ok { true };
346+
347+
const decimal_type my_tol { std::numeric_limits<decimal_type>::epsilon() * static_cast<decimal_type>(tol_factor) };
348+
349+
for(auto i = static_cast<std::size_t>(UINT8_C(0)); i < std::tuple_size<str_ctrl_array_type>::value; ++i)
350+
{
351+
decimal_type x_arg =
352+
decimal_type
353+
{
354+
decimal_type { 1, 2 } * n
355+
+ decimal_type { 1, 1 } * n
356+
+ 1
357+
}
358+
/ decimal_type { 1, 2 };
359+
360+
++n;
361+
362+
tg_values[i] = tgamma(x_arg);
363+
364+
static_cast<void>
365+
(
366+
from_chars(ctrl_strings[i], ctrl_strings[i] + std::strlen(ctrl_strings[i]), ctrl_values[i])
367+
);
368+
369+
const auto result_tgamma_is_ok = is_close_fraction(tg_values[i], ctrl_values[i], my_tol);
370+
371+
result_is_ok = (result_tgamma_is_ok && result_is_ok);
372+
}
373+
374+
return result_is_ok;
375+
}
376+
319377
} // namespace local
320378

321379
auto main() -> int
@@ -372,28 +430,11 @@ auto main() -> int
372430
}
373431

374432
{
375-
using decimal_type = boost::decimal::decimal128;
376-
377-
const char str_ctrl[] = "12.64819265438397922113369900828315";
433+
const auto result_tgamma128_is_ok = local::test_tgamma_128(1000000);
378434

379-
const decimal_type x = decimal_type { 456, -2 };
435+
BOOST_TEST(result_tgamma128_is_ok);
380436

381-
// N[Gamma[456/100], 34]
382-
// 12.64819265438397922113369900828315
383-
const auto tg = tgamma(x);
384-
385-
decimal_type ctrl { };
386-
387-
from_chars(str_ctrl, str_ctrl + std::strlen(str_ctrl), ctrl);
388-
389-
//std::cout << std::setprecision(34) << tg << std::endl;
390-
//std::cout << std::setprecision(34) << ctrl << std::endl;
391-
392-
const auto result_tgamma_is_ok = local::is_close_fraction(tg, ctrl, std::numeric_limits<decimal_type>::epsilon() * 1000000);
393-
394-
BOOST_TEST(result_tgamma_is_ok);
395-
396-
result_is_ok = (result_tgamma_is_ok && result_is_ok);
437+
result_is_ok = (result_tgamma128_is_ok && result_is_ok);
397438
}
398439

399440
result_is_ok = ((boost::report_errors() == 0) && result_is_ok);

0 commit comments

Comments
 (0)