CompareAKMathAgainstMPFR: Add support for the lgamma function

This commit is contained in:
Lucas Chollet committed 2026-10-12 18:39:50 +02:00
1 parent f788e89ffb
commit e126a950c3
3 files changed
+20

No files matched your search

@@ -74,6 +74,8 @@ Array g_edge_cases = to_array<double>({ // Denormals
Array g_exp_perf_ranges = to_array<Range>({ { 0, 1 }, { -10, 10 }, { -745, 709 } });
Array g_log_perf_ranges = to_array<Range>({ { 0.01, 1 }, { 1, 100 }, { 1, 1e5 } });
Array g_lgamma_perf_ranges = to_array<Range>({ { -100, 0 }, { 0.001, 1 }, { 1, 100 }, { 1, 1e5 } });
Array g_hyperbolic_perf_ranges = to_array<Range>({ { -1, 1 }, { -10, 10 }, { 100, 1e5 } });
Array g_sinh_perf_ranges = g_hyperbolic_perf_ranges;
Array g_cosh_perf_ranges = g_hyperbolic_perf_ranges;
@@ -86,6 +88,8 @@ struct RangeWithCount : Range {
Array g_exp_test_ranges = to_array<RangeWithCount>({ { { -10, 10 }, 150 }, { { -745, 709 }, 50 }, { { -1e-10, 1e-10 }, 50 } });
Array g_log_test_ranges = to_array<RangeWithCount>({ { { 1e-300, 1 }, 100 }, { { 1, 10 }, 100 }, { { 10, 1e300 }, 50 } });
Array g_lgamma_test_ranges = to_array<RangeWithCount>({ { { -100, 0 }, 150 }, { { 1e-300, 1 }, 100 }, { { 1, 10 }, 100 }, { { 10, 1e300 }, 50 } });
Array g_hyperbolic_test_ranges = to_array<RangeWithCount>({ { { -10, 10 }, 150 }, { { -700, 700 }, 50 }, { { -1e-10, 1e-10 }, 50 } });
Array g_cosh_test_ranges = g_hyperbolic_test_ranges;
Array g_sinh_test_ranges = g_hyperbolic_test_ranges;
@@ -117,6 +121,8 @@ Array g_functions = to_array({
DEFINE_MATH_FUNC(exp),
DEFINE_MATH_FUNC(log),
DEFINE_MATH_FUNC(lgamma),
DEFINE_MATH_FUNC(cosh),
DEFINE_MATH_FUNC(sinh),
DEFINE_MATH_FUNC(tanh),
@@ -42,6 +42,18 @@ double log(double x)
return ret;
}
double lgamma(double x)
{
mpfr_t y;
mpfr_init2(y, 53);
mpfr_set_d(y, x, MPFR_RNDN);
int inex = mpfr_lgamma(y, &signgam, y, MPFR_RNDN);
mpfr_subnormalize(y, inex, MPFR_RNDN);
double ret = mpfr_get_d(y, MPFR_RNDN);
mpfr_clear(y);
return ret;
}
double cosh(double x)
{
mpfr_t y;
@@ -13,6 +13,8 @@ void set_exponent_limits();
double exp(double x);
double log(double x);
double lgamma(double x);
double cosh(double x);
double sinh(double x);
double tanh(double x);