Skip to content

Commit 4762c65

Browse files
authored
[flang][runtime] Underflow real input to -0. when negative (#82443)
When the result of real input editing underflows to zero, return -0. when the input field had a minus sign.
1 parent 7a2d934 commit 4762c65

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

flang/lib/Decimal/decimal-to-binary.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <cinttypes>
1515
#include <cstring>
1616
#include <ctype.h>
17+
#include <utility>
1718

1819
namespace Fortran::decimal {
1920

@@ -275,7 +276,12 @@ ConversionToBinaryResult<PREC> IntermediateFloat<PREC>::ToBinary(
275276
if (guard != 0) {
276277
flags |= Underflow;
277278
}
278-
return {Binary{}, static_cast<enum ConversionResultFlags>(flags)};
279+
Binary zero;
280+
if (isNegative) {
281+
zero.Negate();
282+
}
283+
return {
284+
std::move(zero), static_cast<enum ConversionResultFlags>(flags)};
279285
}
280286
}
281287
} else {

flang/unittests/Runtime/NumericalFormatTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ TEST(IOApiTests, EditDoubleInputValues) {
916916
{"(RU,F7.0)", "-1.e999", 0xffefffffffffffff, 0}, // -HUGE()
917917
{"(E9.1)", " 1.0E-325", 0x0, 0},
918918
{"(RU,E9.1)", " 1.0E-325", 0x1, 0},
919-
{"(E9.1)", "-1.0E-325", 0x0, 0},
919+
{"(E9.1)", "-1.0E-325", 0x8000000000000000, 0},
920920
{"(RD,E9.1)", "-1.0E-325", 0x8000000000000001, 0},
921921
};
922922
for (auto const &[format, data, want, iostat] : testCases) {

0 commit comments

Comments
 (0)