Skip to content

Commit 7582109

Browse files
committed
Prelim tgamma 128 and one single test
1 parent 214d730 commit 7582109

File tree

2 files changed

+71
-28
lines changed

2 files changed

+71
-28
lines changed

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

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,35 +75,53 @@ struct tgamma_table_imp
7575
+::boost::decimal::decimal64 { UINT64_C(1'186'692'254'751'600'333), - 19 - 17 }, // * z^27
7676
}};
7777

78-
static constexpr std::array<decimal128, 36> d128_coeffs =
78+
static constexpr std::array<decimal128, 44> d128_coeffs =
7979
{{
8080
// N[Series[1/Gamma[z], {z, 0, 27}], 24]
81-
+::boost::decimal::decimal128 { UINT64_C(5'772'156'649'015'328'606), - 19 - 0 }, // * z^2
82-
-::boost::decimal::decimal128 { UINT64_C(6'558'780'715'202'538'811), - 19 - 0 }, // * z^3
83-
-::boost::decimal::decimal128 { UINT64_C(4'200'263'503'409'523'553), - 19 - 1 }, // * z^4
84-
+::boost::decimal::decimal128 { UINT64_C(1'665'386'113'822'914'895), - 19 - 0 }, // * z^5
85-
-::boost::decimal::decimal128 { UINT64_C(4'219'773'455'554'433'675), - 19 - 1 }, // * z^6
86-
-::boost::decimal::decimal128 { UINT64_C(9'621'971'527'876'973'562), - 19 - 2 }, // * z^7
87-
+::boost::decimal::decimal128 { UINT64_C(7'218'943'246'663'099'542), - 19 - 2 }, // * z^8
88-
-::boost::decimal::decimal128 { UINT64_C(1'165'167'591'859'065'112), - 19 - 2 }, // * z^9
89-
-::boost::decimal::decimal128 { UINT64_C(2'152'416'741'149'509'728), - 19 - 3 }, // * z^10
90-
+::boost::decimal::decimal128 { UINT64_C(1'280'502'823'881'161'862), - 19 - 3 }, // * z^11
91-
-::boost::decimal::decimal128 { UINT64_C(2'013'485'478'078'823'866), - 19 - 4 }, // * z^12
92-
-::boost::decimal::decimal128 { UINT64_C(1'250'493'482'142'670'657), - 19 - 5 }, // * z^13
93-
+::boost::decimal::decimal128 { UINT64_C(1'133'027'231'981'695'882), - 19 - 5 }, // * z^14
94-
-::boost::decimal::decimal128 { UINT64_C(2'056'338'416'977'607'103), - 19 - 6 }, // * z^15
95-
+::boost::decimal::decimal128 { UINT64_C(6'116'095'104'481'415'818), - 19 - 8 }, // * z^16
96-
+::boost::decimal::decimal128 { UINT64_C(5'002'007'644'469'222'930), - 19 - 8 }, // * z^17
97-
-::boost::decimal::decimal128 { UINT64_C(1'181'274'570'487'020'145), - 19 - 8 }, // * z^18
98-
+::boost::decimal::decimal128 { UINT64_C(1'043'426'711'691'100'510), - 19 - 9 }, // * z^19
99-
+::boost::decimal::decimal128 { UINT64_C(7'782'263'439'905'071'254), - 19 - 11 }, // * z^20
100-
-::boost::decimal::decimal128 { UINT64_C(3'696'805'618'642'205'708), - 19 - 11 }, // * z^21
101-
+::boost::decimal::decimal128 { UINT64_C(5'100'370'287'454'475'979), - 19 - 12 }, // * z^22
102-
-::boost::decimal::decimal128 { UINT64_C(2'058'326'053'566'506'783), - 19 - 13 }, // * z^23
103-
-::boost::decimal::decimal128 { UINT64_C(5'348'122'539'423'017'982), - 19 - 14 }, // * z^24
104-
+::boost::decimal::decimal128 { UINT64_C(1'226'778'628'238'260'790), - 19 - 14 }, // * z^25
105-
-::boost::decimal::decimal128 { UINT64_C(1'181'259'301'697'458'770), - 19 - 15 }, // * z^26
106-
+::boost::decimal::decimal128 { UINT64_C(1'186'692'254'751'600'333), - 19 - 17 }, // * z^27
81+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(312909238939453), UINT64_C(7916302232898517972) }, -34 }, // * z^2
82+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(355552215013931), UINT64_C(2875353717947891404) }, -34 }, // * z^3
83+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(227696740770409), UINT64_C(1287992959696612036) }, -35 }, // * z^4
84+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(90280762131699), UINT64_C(14660682722320745466) }, -34 }, // * z^5
85+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(228754377395439), UINT64_C(1086189775515439306) }, -35 }, // * z^6
86+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(521608121705894), UINT64_C(2882773517907923486) }, -36 }, // * z^7
87+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(391339697554084), UINT64_C(12203646426790846826) }, -36 }, // * z^8
88+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(63163861720165), UINT64_C(1793625582468481749) }, -36 }, // * z^9
89+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(116682745342423), UINT64_C(7466931387917530902) }, -37 }, // * z^10
90+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(69416197176288), UINT64_C(17486507952476000235) }, -37 }, // * z^11
91+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(109151266480053), UINT64_C(14157573701904186532) }, -38 }, // * z^12
92+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(67789387500902), UINT64_C(6337242598258275460) }, -39 }, // * z^13
93+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(61421529319989), UINT64_C(11330812743044278521) }, -39 }, // * z^14
94+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(111474328952626), UINT64_C(4349913604764276954) }, -40 }, // * z^15
95+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(331554179970335), UINT64_C(8536598537651543980) }, -42 }, // * z^16
96+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(271159377746131), UINT64_C(11232450780359262294) }, -42 }, // * z^17
97+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(64037022781195), UINT64_C(7729482665838775386) }, -42 }, // * z^18
98+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(56564275382244), UINT64_C(15921046388084405946) }, -43 }, // * z^19
99+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(421877346419979), UINT64_C(12114109382397224706) }, -45 }, // * z^20
100+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(200404234149424), UINT64_C(17191629897693416576) }, -45 }, // * z^21
101+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(276491627306932), UINT64_C(18075235341994261118) }, -46 }, // * z^22
102+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(111582078948016), UINT64_C(1315679057212061374) }, -47 }, // * z^23
103+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(289922303798056), UINT64_C(8236273575746269444) }, -48 }, // * z^24
104+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(66503802694735), UINT64_C(8619931044472680662) }, -48 }, // * z^25
105+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(64036195058454), UINT64_C(13570784405336680634) }, -49 }, // * z^26
106+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(64330716033670), UINT64_C(6228121739584017954) }, -51 }, // * z^27
107+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(76565308743615), UINT64_C(9665163337994634860) }, -51 },
108+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(124615253252825), UINT64_C(5713012462345318490) }, -52 },
109+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(92938152937825), UINT64_C(2160517649493992050) }, -53 },
110+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(72497982578925), UINT64_C(10055707640313829460) }, -55 },
111+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(111360223980902), UINT64_C(528747408384118098) }, -55 },
112+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(148320486134320), UINT64_C(12662323637555269860) }, -56 },
113+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(93911231108772), UINT64_C(8663955293807189228) }, -57 },
114+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(127969413738636), UINT64_C(17978922200959991754) }, -59 },
115+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(101100927852914), UINT64_C(16158702556622869636) }, -59 },
116+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(120243204727301), UINT64_C(13141135468649758444) }, -60 },
117+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(70352901832557), UINT64_C(2975454173305568482) }, -61 },
118+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(64005738370342), UINT64_C(18063645830042937300) }, -63 },
119+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(60963839731470), UINT64_C(14965217315129705920) }, -63 },
120+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(69230926066837), UINT64_C(16656915204960392533) }, -64 },
121+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(400691370795862), UINT64_C(16972369904241895558) }, -66 },
122+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(61514934723438), UINT64_C(5918930041313493498) }, -68 },
123+
+::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(251487992814431), UINT64_C(6680121266003781724) }, -68 },
124+
-::boost::decimal::decimal128 { boost::decimal::detail::uint128 { UINT64_C(289879709778175), UINT64_C(4432551928123929090) }, -69 },
107125
}};
108126
};
109127

@@ -116,7 +134,7 @@ template <bool b>
116134
constexpr std::array<decimal64, 36> tgamma_table_imp<b>::d64_coeffs;
117135

118136
template <bool b>
119-
constexpr std::array<decimal128, 36> tgamma_table_imp<b>::d128_coeffs;
137+
constexpr std::array<decimal128, 44> tgamma_table_imp<b>::d128_coeffs;
120138

121139
#endif
122140

test/test_tgamma.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,31 @@ auto main() -> int
371371
result_is_ok = (result_edge_is_ok && result_is_ok);
372372
}
373373

374+
{
375+
using decimal_type = boost::decimal::decimal128;
376+
377+
const char str_ctrl[] = "12.64819265438397922113369900828315";
378+
379+
const decimal_type x = decimal_type { 456, -2 };
380+
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);
397+
}
398+
374399
result_is_ok = ((boost::report_errors() == 0) && result_is_ok);
375400

376401
return (result_is_ok ? 0 : -1);

0 commit comments

Comments
 (0)