Skip to content

Commit 10ecbcc

Browse files
committed
Omit declarations when LLVM_INTEGRATE_LIBC is off and fix default rounding mode declaration.
1 parent c200fbb commit 10ecbcc

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

llvm/include/llvm/ADT/APFloat.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,9 +1523,12 @@ class APFloat : public APFloatBase {
15231523
friend int ilogb(const APFloat &Arg) { return ilogb(Arg.getIEEE()); }
15241524
friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
15251525
friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
1526-
friend APFloat exp(const APFloat &X, roundingMode RM);
15271526
friend IEEEFloat;
15281527
friend DoubleAPFloat;
1528+
1529+
#ifdef LLVM_INTEGRATE_LIBC
1530+
friend APFloat exp(const APFloat &X, roundingMode RM);
1531+
#endif // LLVM_INTEGRATE_LIBC)
15291532
};
15301533

15311534
static_assert(sizeof(APFloat) == sizeof(detail::IEEEFloat),
@@ -1659,9 +1662,11 @@ inline APFloat maximumnum(const APFloat &A, const APFloat &B) {
16591662
return A < B ? B : A;
16601663
}
16611664

1665+
#ifdef LLVM_INTEGRATE_LIBC
16621666
/// Implement IEEE 754-2019 exp functions.
16631667
LLVM_READONLY
1664-
APFloat exp(const APFloat &X, RoundingMode RM);
1668+
APFloat exp(const APFloat &X, RoundingMode RM = APFloat::rmNearestTiesToEven);
1669+
#endif // LLVM_INTEGRATE_LIBC
16651670

16661671
inline raw_ostream &operator<<(raw_ostream &OS, const APFloat &V) {
16671672
V.print(OS);

llvm/lib/Support/APFloat.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5621,8 +5621,7 @@ static constexpr int getFEnvRoundingMode(llvm::RoundingMode rm) {
56215621
};
56225622
}
56235623

5624-
APFloat exp(const APFloat &X,
5625-
RoundingMode rounding_mode = APFloat::rmNearestTiesToEven) {
5624+
APFloat exp(const APFloat &X, RoundingMode rounding_mode) {
56265625
assert((&X.getSemantics() == (const llvm::fltSemantics *)&semIEEEsingle) &&
56275626
"Float semantics is not IEEEsingle");
56285627
if (&X.getSemantics() == (const llvm::fltSemantics *)&semIEEEsingle) {

llvm/unittests/ADT/APFloatTest.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8409,7 +8409,7 @@ TEST(APFloatTest, expf) {
84098409
EXPECT_EQ(1.0f, llvm::exp(APFloat::getSmallest(APFloat::IEEEsingle(), false),
84108410
APFloat::rmNearestTiesToEven)
84118411
.convertToFloat());
8412-
EXPECT_EQ(0x1.000002p0,
8412+
EXPECT_EQ(0x1.000002p0f,
84138413
llvm::exp(APFloat::getSmallest(APFloat::IEEEsingle(), false),
84148414
APFloat::rmTowardPositive)
84158415
.convertToFloat());
@@ -8419,6 +8419,17 @@ TEST(APFloatTest, expf) {
84198419
EXPECT_EQ(1.0f, llvm::exp(APFloat::getSmallest(APFloat::IEEEsingle(), false),
84208420
APFloat::rmTowardZero)
84218421
.convertToFloat());
8422+
// Default rounding mode.
8423+
// exp(-1)
8424+
EXPECT_EQ(0x1.78b564p-2f, llvm::exp(APFloat(-1.0f)).convertToFloat());
8425+
EXPECT_EQ(
8426+
0x1.78b564p-2f,
8427+
llvm::exp(APFloat(-1.0f), APFloat::rmTowardPositive).convertToFloat());
8428+
EXPECT_EQ(
8429+
0x1.78b562p-2f,
8430+
llvm::exp(APFloat(-1.0f), APFloat::rmTowardNegative).convertToFloat());
8431+
EXPECT_EQ(0x1.78b562p-2f,
8432+
llvm::exp(APFloat(-1.0f), APFloat::rmTowardZero).convertToFloat());
84228433
}
84238434
#endif // LLVM_INTEGRATE_LIBC
84248435

0 commit comments

Comments
 (0)