[flang-commits] [flang] b1a1d4e - [flang][runtime] Don't emit excess digits for ES0.0E0 or EN0.0E0 (#101238)
via flang-commits
flang-commits at lists.llvm.org
Fri Aug 2 12:04:16 PDT 2024
Author: Peter Klausler
Date: 2024-08-02T12:04:12-07:00
New Revision: b1a1d4e08e0dae54a0d60af4784a30f9d6849ebb
URL: https://github.com/llvm/llvm-project/commit/b1a1d4e08e0dae54a0d60af4784a30f9d6849ebb
DIFF: https://github.com/llvm/llvm-project/commit/b1a1d4e08e0dae54a0d60af4784a30f9d6849ebb.diff
LOG: [flang][runtime] Don't emit excess digits for ES0.0E0 or EN0.0E0 (#101238)
Don't emit any digits after the decimal point.
Added:
Modified:
flang/runtime/edit-output.cpp
flang/unittests/Runtime/NumericalFormatTest.cpp
Removed:
################################################################################
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 1a73c85df8404..9d60732258bfb 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -300,10 +300,12 @@ RT_API_ATTRS bool RealOutputEditing<KIND>::EditEorDOutput(
flags |= decimal::AlwaysSign;
}
int scale{edit.modes.scale}; // 'kP' value
+ bool isEN{edit.variation == 'N'};
+ bool isES{edit.variation == 'S'};
if (editWidth == 0) { // "the processor selects the field width"
if (edit.digits.has_value()) { // E0.d
if (editDigits == 0 && scale <= 0) { // E0.0
- significantDigits = 1;
+ significantDigits = isEN || isES ? 0 : 1;
}
} else { // E0
flags |= decimal::Minimize;
@@ -311,8 +313,6 @@ RT_API_ATTRS bool RealOutputEditing<KIND>::EditEorDOutput(
sizeof buffer_ - 5; // sign, NUL, + 3 extra for EN scaling
}
}
- bool isEN{edit.variation == 'N'};
- bool isES{edit.variation == 'S'};
int zeroesAfterPoint{0};
if (isEN) {
scale = IsZero() ? 1 : 3;
diff --git a/flang/unittests/Runtime/NumericalFormatTest.cpp b/flang/unittests/Runtime/NumericalFormatTest.cpp
index 2a9f8f8d1dc4f..f005515320350 100644
--- a/flang/unittests/Runtime/NumericalFormatTest.cpp
+++ b/flang/unittests/Runtime/NumericalFormatTest.cpp
@@ -753,6 +753,8 @@ TEST(IOApiTests, FormatDoubleValues) {
{"(F5.0,';')", 0.49999999999999994, " 0.;"},
{"(F5.0,';')", 0.5, " 0.;"},
{"(F5.0,';')", 0.5000000000000001, " 1.;"},
+ {"(ES0.0E0,';')", 0.666, "7.E-1;"},
+ {"(EN0.0E0,';')", 0.666, "666.E-3;"},
};
for (auto const &[format, value, expect] : individualTestCases) {
More information about the flang-commits
mailing list