Skip to content

[libc][math] Fix division by infinity in fputil::div #152092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/div.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ div(InType x, InType y) {
}

if (y_bits.is_inf())
return OutFPBits::inf(result_sign).get_val();
return OutFPBits::zero(result_sign).get_val();

if (y_bits.is_zero()) {
if (x_bits.is_zero()) {
Expand Down
5 changes: 5 additions & 0 deletions libc/test/src/math/smoke/DivTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class DivTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
EXPECT_FP_EQ(neg_inf, func(in.neg_inf, in.zero));
EXPECT_FP_EQ(neg_inf, func(in.inf, in.neg_zero));
EXPECT_FP_EQ(inf, func(in.neg_inf, in.neg_zero));
EXPECT_FP_EQ(zero, func(in.min_normal, in.inf));
EXPECT_FP_EQ(zero, func(in.zero, in.inf));
EXPECT_FP_EQ(zero, func(in.neg_zero, in.neg_inf));
EXPECT_FP_EQ(neg_zero, func(in.min_normal, in.neg_inf));
EXPECT_FP_EQ(neg_zero, func(in.zero, in.neg_inf));
}

void test_division_by_zero(DivFunc func) {
Expand Down
Loading