[flang-commits] [flang] [flang][runtime] Don't emit excess digits for ES0.0E0 or EN0.0E0 (PR #101238)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Jul 30 13:45:18 PDT 2024
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/101238
Don't emit any digits after the decimal point.
>From 8faf998952bb4769405701de2e0592c874cce882 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 30 Jul 2024 13:35:10 -0700
Subject: [PATCH] [flang][runtime] Don't emit excess digits for ES0.0E0 or
EN0.0E0
Don't emit any digits after the decimal point.
---
flang/runtime/edit-output.cpp | 6 +++---
flang/unittests/Runtime/NumericalFormatTest.cpp | 2 ++
2 files changed, 5 insertions(+), 3 deletions(-)
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