[libc-commits] [libc] [libc][math] fix-exp (PR #148670)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Mon Jul 14 10:37:49 PDT 2025
https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/148670
>From 39eadffb4d35116140b377792446248fd299f501 Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Mon, 14 Jul 2025 20:37:38 +0300
Subject: [PATCH] fix exp
---
libc/src/__support/math/exp.h | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/libc/src/__support/math/exp.h b/libc/src/__support/math/exp.h
index 5c43e753ea687..554cc012f66a6 100644
--- a/libc/src/__support/math/exp.h
+++ b/libc/src/__support/math/exp.h
@@ -36,15 +36,15 @@ using Float128 = typename fputil::DyadicFloat<128>;
using LIBC_NAMESPACE::operator""_u128;
// log2(e)
-static constexpr double LOG2_E = 0x1.71547652b82fep+0;
+static double LOG2_E = 0x1.71547652b82fep+0;
// Error bounds:
// Errors when using double precision.
-static constexpr double ERR_D = 0x1.8p-63;
+static double ERR_D = 0x1.8p-63;
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
// Errors when using double-double precision.
-static constexpr double ERR_DD = 0x1.0p-99;
+static double ERR_DD = 0x1.0p-99;
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
// -2^-12 * log(2)
@@ -53,12 +53,12 @@ static constexpr double ERR_DD = 0x1.0p-99;
// > c = round(a - b, 30, RN);
// > d = round(a - b - c, D, RN);
// Errors < 1.5 * 2^-133
-static constexpr double MLOG_2_EXP2_M12_HI = -0x1.62e42ffp-13;
-static constexpr double MLOG_2_EXP2_M12_MID = 0x1.718432a1b0e26p-47;
+static double MLOG_2_EXP2_M12_HI = -0x1.62e42ffp-13;
+static double MLOG_2_EXP2_M12_MID = 0x1.718432a1b0e26p-47;
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-static constexpr double MLOG_2_EXP2_M12_MID_30 = 0x1.718432ap-47;
-static constexpr double MLOG_2_EXP2_M12_LO = 0x1.b0e2633fe0685p-79;
+static double MLOG_2_EXP2_M12_MID_30 = 0x1.718432ap-47;
+static double MLOG_2_EXP2_M12_LO = 0x1.b0e2633fe0685p-79;
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
namespace {
@@ -67,7 +67,7 @@ namespace {
// Return expm1(dx) / x ~ 1 + dx / 2 + dx^2 / 6 + dx^3 / 24.
// For |dx| < 2^-13 + 2^-30:
// | output - expm1(dx) / dx | < 2^-51.
-static constexpr double poly_approx_d(double dx) {
+static double poly_approx_d(double dx) {
// dx^2
double dx2 = dx * dx;
// c0 = 1 + dx / 2
@@ -85,7 +85,7 @@ static constexpr double poly_approx_d(double dx) {
// Return exp(dx) ~ 1 + dx + dx^2 / 2 + ... + dx^6 / 720
// For |dx| < 2^-13 + 2^-30:
// | output - exp(dx) | < 2^-101
-static constexpr DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
+static DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
// Taylor polynomial.
constexpr DoubleDouble COEFFS[] = {
{0, 0x1p0}, // 1
@@ -106,7 +106,7 @@ static constexpr DoubleDouble poly_approx_dd(const DoubleDouble &dx) {
// Return exp(dx) ~ 1 + dx + dx^2 / 2 + ... + dx^7 / 5040
// For |dx| < 2^-13 + 2^-30:
// | output - exp(dx) | < 2^-126.
-static constexpr Float128 poly_approx_f128(const Float128 &dx) {
+static Float128 poly_approx_f128(const Float128 &dx) {
constexpr Float128 COEFFS_128[]{
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
{Sign::POS, -127, 0x80000000'00000000'00000000'00000000_u128}, // 1.0
@@ -127,7 +127,7 @@ static constexpr Float128 poly_approx_f128(const Float128 &dx) {
// Compute exp(x) using 128-bit precision.
// TODO(lntue): investigate triple-double precision implementation for this
// step.
-static constexpr Float128 exp_f128(double x, double kd, int idx1, int idx2) {
+static Float128 exp_f128(double x, double kd, int idx1, int idx2) {
// Recalculate dx:
double t1 = fputil::multiply_add(kd, MLOG_2_EXP2_M12_HI, x); // exact
@@ -160,7 +160,7 @@ static constexpr Float128 exp_f128(double x, double kd, int idx1, int idx2) {
}
// Compute exp(x) with double-double precision.
-static constexpr DoubleDouble exp_double_double(double x, double kd,
+static DoubleDouble exp_double_double(double x, double kd,
const DoubleDouble &exp_mid) {
// Recalculate dx:
// dx = x - k * 2^-12 * log(2)
@@ -184,7 +184,7 @@ static constexpr DoubleDouble exp_double_double(double x, double kd,
// Check for exceptional cases when
// |x| <= 2^-53 or x < log(2^-1075) or x >= 0x1.6232bdd7abcd3p+9
-static constexpr double set_exceptional(double x) {
+static double set_exceptional(double x) {
using FPBits = typename fputil::FPBits<double>;
FPBits xbits(x);
@@ -234,7 +234,7 @@ static constexpr double set_exceptional(double x) {
namespace math {
-static constexpr double exp(double x) {
+static double exp(double x) {
using FPBits = typename fputil::FPBits<double>;
FPBits xbits(x);
More information about the libc-commits
mailing list