Skip to content

Commit 170dab9

Browse files
authored
[libc][math] Fix signed zeros for powf when underflow happens. (#112601)
1 parent 629a182 commit 170dab9

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

libc/src/math/generic/powf.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,9 +855,9 @@ 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+
860+
return static_cast<float>(r_dd);
861861
}
862862

863863
} // namespace LIBC_NAMESPACE_DECL

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

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

0 commit comments

Comments
 (0)