Skip to content

Commit

Permalink
[flang][runtime] Underflow real input to -0. when negative (#82443)
Browse files Browse the repository at this point in the history
When the result of real input editing underflows to zero, return -0.
when the input field had a minus sign.
  • Loading branch information
klausler committed Mar 1, 2024
1 parent 7a2d934 commit 4762c65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion flang/lib/Decimal/decimal-to-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cinttypes>
#include <cstring>
#include <ctype.h>
#include <utility>

namespace Fortran::decimal {

Expand Down Expand Up @@ -275,7 +276,12 @@ ConversionToBinaryResult<PREC> IntermediateFloat<PREC>::ToBinary(
if (guard != 0) {
flags |= Underflow;
}
return {Binary{}, static_cast<enum ConversionResultFlags>(flags)};
Binary zero;
if (isNegative) {
zero.Negate();
}
return {
std::move(zero), static_cast<enum ConversionResultFlags>(flags)};
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion flang/unittests/Runtime/NumericalFormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ TEST(IOApiTests, EditDoubleInputValues) {
{"(RU,F7.0)", "-1.e999", 0xffefffffffffffff, 0}, // -HUGE()
{"(E9.1)", " 1.0E-325", 0x0, 0},
{"(RU,E9.1)", " 1.0E-325", 0x1, 0},
{"(E9.1)", "-1.0E-325", 0x0, 0},
{"(E9.1)", "-1.0E-325", 0x8000000000000000, 0},
{"(RD,E9.1)", "-1.0E-325", 0x8000000000000001, 0},
};
for (auto const &[format, data, want, iostat] : testCases) {
Expand Down

0 comments on commit 4762c65

Please sign in to comment.