mirror of
https://github.com/SerenityOS/serenity.git
synced 2026-11-07 04:29:30 -10:00
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:
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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user