Skip to content

Conversation

@lntue
Copy link
Contributor

@lntue lntue commented Jul 18, 2025

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jul 18, 2025

@llvm/pr-subscribers-libc

Author: None (lntue)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/149591.diff

3 Files Affected:

  • (modified) libc/src/__support/math/exp.h (+10-9)
  • (modified) libc/src/__support/math/exp10.h (+10-9)
  • (modified) libc/src/__support/math/exp10f_utils.h (+3-3)
diff --git a/libc/src/__support/math/exp.h b/libc/src/__support/math/exp.h
index a538df1e825dc..ff59ff79e3381 100644
--- a/libc/src/__support/math/exp.h
+++ b/libc/src/__support/math/exp.h
@@ -40,11 +40,11 @@ static constexpr double LOG2_E = 0x1.71547652b82fep+0;
 
 // Error bounds:
 // Errors when using double precision.
-static constexpr double ERR_D = 0x1.8p-63;
+static constexpr double EXP_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 constexpr double EXP_ERR_DD = 0x1.0p-99;
 #endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
 // -2^-12 * log(2)
@@ -387,7 +387,8 @@ static double exp(double x) {
 
 #ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
   if (LIBC_UNLIKELY(denorm)) {
-    return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo, ERR_D)
+    return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo,
+                                                   EXP_ERR_D)
         .value();
   } else {
     // to multiply by 2^hi, a fast way is to simply add hi to the exponent
@@ -399,12 +400,12 @@ static double exp(double x) {
   }
 #else
   if (LIBC_UNLIKELY(denorm)) {
-    if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, ERR_D);
+    if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, EXP_ERR_D);
         LIBC_LIKELY(r.has_value()))
       return r.value();
   } else {
-    double upper = exp_mid.hi + (lo + ERR_D);
-    double lower = exp_mid.hi + (lo - ERR_D);
+    double upper = exp_mid.hi + (lo + EXP_ERR_D);
+    double lower = exp_mid.hi + (lo - EXP_ERR_D);
 
     if (LIBC_LIKELY(upper == lower)) {
       // to multiply by 2^hi, a fast way is to simply add hi to the exponent
@@ -419,12 +420,12 @@ static double exp(double x) {
   DoubleDouble r_dd = exp_double_double(x, kd, exp_mid);
 
   if (LIBC_UNLIKELY(denorm)) {
-    if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, ERR_DD);
+    if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, EXP_ERR_DD);
         LIBC_LIKELY(r.has_value()))
       return r.value();
   } else {
-    double upper_dd = r_dd.hi + (r_dd.lo + ERR_DD);
-    double lower_dd = r_dd.hi + (r_dd.lo - ERR_DD);
+    double upper_dd = r_dd.hi + (r_dd.lo + EXP_ERR_DD);
+    double lower_dd = r_dd.hi + (r_dd.lo - EXP_ERR_DD);
 
     if (LIBC_LIKELY(upper_dd == lower_dd)) {
       int64_t exp_hi = static_cast<int64_t>(hi) << FPBits::FRACTION_LEN;
diff --git a/libc/src/__support/math/exp10.h b/libc/src/__support/math/exp10.h
index 88748523deb3d..fa60e40c43e5d 100644
--- a/libc/src/__support/math/exp10.h
+++ b/libc/src/__support/math/exp10.h
@@ -54,11 +54,11 @@ static constexpr double MLOG10_2_EXP2_M12_LO = 0x1.da994fd20dba2p-87;
 
 // Error bounds:
 // Errors when using double precision.
-constexpr double ERR_D = 0x1.8p-63;
+constexpr double EXP10_ERR_D = 0x1.8p-63;
 
 #ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 // Errors when using double-double precision.
-static constexpr double ERR_DD = 0x1.8p-99;
+static constexpr double EXP10_ERR_DD = 0x1.8p-99;
 #endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
 
 // Polynomial approximations with double precision.  Generated by Sollya with:
@@ -207,17 +207,18 @@ static double exp10_denorm(double x) {
   double lo = fputil::multiply_add(p, mid_lo, exp_mid.lo);
 
 #ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
-  return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo, ERR_D)
+  return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo,
+                                                 EXP10_ERR_D)
       .value();
 #else
-  if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, ERR_D);
+  if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, EXP10_ERR_D);
       LIBC_LIKELY(r.has_value()))
     return r.value();
 
   // Use double-double
   DoubleDouble r_dd = exp10_double_double(x, kd, exp_mid);
 
-  if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, ERR_DD);
+  if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, EXP10_ERR_DD);
       LIBC_LIKELY(r.has_value()))
     return r.value();
 
@@ -409,8 +410,8 @@ static constexpr double exp10(double x) {
       cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(exp_mid.hi + lo));
   return r;
 #else
-  double upper = exp_mid.hi + (lo + ERR_D);
-  double lower = exp_mid.hi + (lo - ERR_D);
+  double upper = exp_mid.hi + (lo + EXP10_ERR_D);
+  double lower = exp_mid.hi + (lo - EXP10_ERR_D);
 
   if (LIBC_LIKELY(upper == lower)) {
     // To multiply by 2^hi, a fast way is to simply add hi to the exponent
@@ -476,8 +477,8 @@ static constexpr double exp10(double x) {
   // Use double-double
   DoubleDouble r_dd = exp10_double_double(x, kd, exp_mid);
 
-  double upper_dd = r_dd.hi + (r_dd.lo + ERR_DD);
-  double lower_dd = r_dd.hi + (r_dd.lo - ERR_DD);
+  double upper_dd = r_dd.hi + (r_dd.lo + EXP10_ERR_DD);
+  double lower_dd = r_dd.hi + (r_dd.lo - EXP10_ERR_DD);
 
   if (LIBC_LIKELY(upper_dd == lower_dd)) {
     // To multiply by 2^hi, a fast way is to simply add hi to the exponent
diff --git a/libc/src/__support/math/exp10f_utils.h b/libc/src/__support/math/exp10f_utils.h
index 0493e1b993e0c..c30def9d62db2 100644
--- a/libc/src/__support/math/exp10f_utils.h
+++ b/libc/src/__support/math/exp10f_utils.h
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP_FLOAT_CONSTANTS_H
-#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP_FLOAT_CONSTANTS_H
+#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP10F_UTILS_H
+#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP10F_UTILS_H
 
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/PolyEval.h"
@@ -154,4 +154,4 @@ LIBC_INLINE static constexpr exp_b_reduc_t exp_b_range_reduc(float x) {
 
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP_FLOAT_CONSTANTS_H
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP10F_UTILS_H

@lntue lntue requested review from sribee8 and uzairnawaz July 18, 2025 21:24
Copy link
Contributor

@uzairnawaz uzairnawaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lntue lntue merged commit 20c5daa into llvm:main Jul 18, 2025
20 of 21 checks passed
@lntue lntue deleted the shared_exp branch July 18, 2025 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants