Skip to content

Commit bed5228

Browse files
committed
[libc][math] Fix signed zeros for powf when underflow happens.
1 parent ae68d53 commit bed5228

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

libc/src/math/generic/powf.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,11 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
855855
: 0.0;
856856
exp2_hi_mid_dd.hi = exp2_hi_mid;
857857

858-
return static_cast<float>(
859-
powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd)) +
860-
0.0f;
858+
double r_dd = powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd);
859+
float r_f = static_cast<float>(r_dd);
860+
861+
// Only fix signed zeros for exact zeros results.
862+
return r_dd != 0 ? r_f : r_f + 0.0f;
861863
}
862864

863865
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/math/smoke/powf_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,6 @@ TEST_F(LlvmLibcPowfTest, SpecialNumbers) {
190190
FE_UNDERFLOW);
191191
}
192192
}
193+
194+
EXPECT_FP_EQ(-0.0f, LIBC_NAMESPACE::powf(-0.015625f, 25.0f));
193195
}

0 commit comments

Comments
 (0)