[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.
This commit is contained in:
Peter Klausler
2024-03-01 14:15:48 -08:00
committed by GitHub
parent 7a2d9347d3
commit 4762c6557d
2 changed files with 8 additions and 2 deletions

View File

@@ -14,6 +14,7 @@
#include <cinttypes>
#include <cstring>
#include <ctype.h>
#include <utility>
namespace Fortran::decimal {
@@ -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 {

View File

@@ -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) {