Skip to content

Commit

Permalink
[libc][math] Fix signed zeros for powf when underflow happens. (llvm#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lntue authored Oct 18, 2024
1 parent 629a182 commit 170dab9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libc/src/math/generic/powf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,9 @@ LLVM_LIBC_FUNCTION(float, powf, (float x, float y)) {
: 0.0;
exp2_hi_mid_dd.hi = exp2_hi_mid;

return static_cast<float>(
powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd)) +
0.0f;
double r_dd = powf_double_double(idx_x, dx, y6, lo6_hi, exp2_hi_mid_dd);

return static_cast<float>(r_dd);
}

} // namespace LIBC_NAMESPACE_DECL
3 changes: 3 additions & 0 deletions libc/test/src/math/smoke/powf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,7 @@ TEST_F(LlvmLibcPowfTest, SpecialNumbers) {
FE_UNDERFLOW);
}
}

EXPECT_FP_EQ(-0.0f, LIBC_NAMESPACE::powf(-0.015625f, 25.0f));
EXPECT_FP_EQ(0.0f, LIBC_NAMESPACE::powf(-0.015625f, 26.0f));
}

0 comments on commit 170dab9

Please sign in to comment.