Skip to content

Commit 20c5daa

Browse files
authored
[libc] Fix conflicting symbols when shared/math.h is included. (#149591)
1 parent 2e67dcf commit 20c5daa

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

libc/src/__support/math/exp.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ static constexpr double LOG2_E = 0x1.71547652b82fep+0;
4040

4141
// Error bounds:
4242
// Errors when using double precision.
43-
static constexpr double ERR_D = 0x1.8p-63;
43+
static constexpr double EXP_ERR_D = 0x1.8p-63;
4444

4545
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
4646
// Errors when using double-double precision.
47-
static constexpr double ERR_DD = 0x1.0p-99;
47+
static constexpr double EXP_ERR_DD = 0x1.0p-99;
4848
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
4949

5050
// -2^-12 * log(2)
@@ -387,7 +387,8 @@ static double exp(double x) {
387387

388388
#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
389389
if (LIBC_UNLIKELY(denorm)) {
390-
return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo, ERR_D)
390+
return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo,
391+
EXP_ERR_D)
391392
.value();
392393
} else {
393394
// 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) {
399400
}
400401
#else
401402
if (LIBC_UNLIKELY(denorm)) {
402-
if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, ERR_D);
403+
if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, EXP_ERR_D);
403404
LIBC_LIKELY(r.has_value()))
404405
return r.value();
405406
} else {
406-
double upper = exp_mid.hi + (lo + ERR_D);
407-
double lower = exp_mid.hi + (lo - ERR_D);
407+
double upper = exp_mid.hi + (lo + EXP_ERR_D);
408+
double lower = exp_mid.hi + (lo - EXP_ERR_D);
408409

409410
if (LIBC_LIKELY(upper == lower)) {
410411
// 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) {
419420
DoubleDouble r_dd = exp_double_double(x, kd, exp_mid);
420421

421422
if (LIBC_UNLIKELY(denorm)) {
422-
if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, ERR_DD);
423+
if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, EXP_ERR_DD);
423424
LIBC_LIKELY(r.has_value()))
424425
return r.value();
425426
} else {
426-
double upper_dd = r_dd.hi + (r_dd.lo + ERR_DD);
427-
double lower_dd = r_dd.hi + (r_dd.lo - ERR_DD);
427+
double upper_dd = r_dd.hi + (r_dd.lo + EXP_ERR_DD);
428+
double lower_dd = r_dd.hi + (r_dd.lo - EXP_ERR_DD);
428429

429430
if (LIBC_LIKELY(upper_dd == lower_dd)) {
430431
int64_t exp_hi = static_cast<int64_t>(hi) << FPBits::FRACTION_LEN;

libc/src/__support/math/exp10.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ static constexpr double MLOG10_2_EXP2_M12_LO = 0x1.da994fd20dba2p-87;
5454

5555
// Error bounds:
5656
// Errors when using double precision.
57-
constexpr double ERR_D = 0x1.8p-63;
57+
constexpr double EXP10_ERR_D = 0x1.8p-63;
5858

5959
#ifndef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
6060
// Errors when using double-double precision.
61-
static constexpr double ERR_DD = 0x1.8p-99;
61+
static constexpr double EXP10_ERR_DD = 0x1.8p-99;
6262
#endif // LIBC_MATH_HAS_SKIP_ACCURATE_PASS
6363

6464
// Polynomial approximations with double precision. Generated by Sollya with:
@@ -207,17 +207,18 @@ static double exp10_denorm(double x) {
207207
double lo = fputil::multiply_add(p, mid_lo, exp_mid.lo);
208208

209209
#ifdef LIBC_MATH_HAS_SKIP_ACCURATE_PASS
210-
return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo, ERR_D)
210+
return ziv_test_denorm</*SKIP_ZIV_TEST=*/true>(hi, exp_mid.hi, lo,
211+
EXP10_ERR_D)
211212
.value();
212213
#else
213-
if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, ERR_D);
214+
if (auto r = ziv_test_denorm(hi, exp_mid.hi, lo, EXP10_ERR_D);
214215
LIBC_LIKELY(r.has_value()))
215216
return r.value();
216217

217218
// Use double-double
218219
DoubleDouble r_dd = exp10_double_double(x, kd, exp_mid);
219220

220-
if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, ERR_DD);
221+
if (auto r = ziv_test_denorm(hi, r_dd.hi, r_dd.lo, EXP10_ERR_DD);
221222
LIBC_LIKELY(r.has_value()))
222223
return r.value();
223224

@@ -409,8 +410,8 @@ static constexpr double exp10(double x) {
409410
cpp::bit_cast<double>(exp_hi + cpp::bit_cast<int64_t>(exp_mid.hi + lo));
410411
return r;
411412
#else
412-
double upper = exp_mid.hi + (lo + ERR_D);
413-
double lower = exp_mid.hi + (lo - ERR_D);
413+
double upper = exp_mid.hi + (lo + EXP10_ERR_D);
414+
double lower = exp_mid.hi + (lo - EXP10_ERR_D);
414415

415416
if (LIBC_LIKELY(upper == lower)) {
416417
// 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) {
476477
// Use double-double
477478
DoubleDouble r_dd = exp10_double_double(x, kd, exp_mid);
478479

479-
double upper_dd = r_dd.hi + (r_dd.lo + ERR_DD);
480-
double lower_dd = r_dd.hi + (r_dd.lo - ERR_DD);
480+
double upper_dd = r_dd.hi + (r_dd.lo + EXP10_ERR_DD);
481+
double lower_dd = r_dd.hi + (r_dd.lo - EXP10_ERR_DD);
481482

482483
if (LIBC_LIKELY(upper_dd == lower_dd)) {
483484
// To multiply by 2^hi, a fast way is to simply add hi to the exponent

libc/src/__support/math/exp10f_utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP_FLOAT_CONSTANTS_H
10-
#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP_FLOAT_CONSTANTS_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_MATH_EXP10F_UTILS_H
10+
#define LLVM_LIBC_SRC___SUPPORT_MATH_EXP10F_UTILS_H
1111

1212
#include "src/__support/FPUtil/FPBits.h"
1313
#include "src/__support/FPUtil/PolyEval.h"
@@ -154,4 +154,4 @@ LIBC_INLINE static constexpr exp_b_reduc_t exp_b_range_reduc(float x) {
154154

155155
} // namespace LIBC_NAMESPACE_DECL
156156

157-
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP_FLOAT_CONSTANTS_H
157+
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_EXP10F_UTILS_H

0 commit comments

Comments
 (0)