CompareAKMathAgainstMPFR: Set exponent limits globally

In the CORE-MATH codebase, not all mpfr-based math functions set the
exponents limits, some assume it is done before calling them. So let's
set it globally and remove the call to mpfr_set_emin code in exp().
This commit is contained in:
Lucas Chollet committed 2026-09-27 22:09:41 +02:00
1 parent 6d42b13c1a
commit c9753b4d3f
3 files changed
+12 -3

No files matched your search

@@ -362,6 +362,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
u32 ruler_width = 72 + w + w2;
outln("{}", MUST(String::repeated('-', ruler_width)));
// FIXME: Don't forget to update this when adding support for testing float functions.
CORE_MATH::set_exponent_limits();
double log_sum = 0.0;
int score_count = 0;
@@ -9,21 +9,25 @@
#include <mpfr.h>
namespace CORE_MATH {
void set_exponent_limits()
{
mpfr_set_emin(-1073);
mpfr_set_emax(1024);
}
// These functions are taken from the CORE-MATH project.
// https://gitlab.inria.fr/core-math/core-math/-/blob/master/src/binary64/
double exp(double x)
{
mpfr_t y;
mpfr_exp_t emin = mpfr_get_emin();
mpfr_set_emin(-1073);
mpfr_init2(y, 53);
mpfr_set_d(y, x, MPFR_RNDN);
int inex = mpfr_exp(y, y, MPFR_RNDN);
mpfr_subnormalize(y, inex, MPFR_RNDN);
double ret = mpfr_get_d(y, MPFR_RNDN);
mpfr_clear(y);
mpfr_set_emin(emin);
return ret;
}
@@ -8,6 +8,8 @@
namespace CORE_MATH {
void set_exponent_limits();
double exp(double x);
double log(double x);