[flang-commits] [flang] 061df07 - [flang][runtime] Fix directed UP/DOWN rounding edge case for Fw.d output
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Jul 6 17:39:12 PDT 2022
Author: Peter Klausler
Date: 2022-07-06T17:35:34-07:00
New Revision: 061df07389f3389ac9f7df06b96c0856cc726825
URL: https://github.com/llvm/llvm-project/commit/061df07389f3389ac9f7df06b96c0856cc726825
DIFF: https://github.com/llvm/llvm-project/commit/061df07389f3389ac9f7df06b96c0856cc726825.diff
LOG: [flang][runtime] Fix directed UP/DOWN rounding edge case for Fw.d output
When Fw.d output editing takes place with directed rounding, make sure that
nonzero values that would normally be converted to zero round up (or down,
depending on the sign) to a scaled 1.
Differential Revision: https://reviews.llvm.org/D129021
Added:
Modified:
flang/runtime/edit-output.cpp
Removed:
################################################################################
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index 57641dd4da8c..6ccaa00a1630 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -419,15 +419,22 @@ bool RealOutputEditing<binaryPrecision>::EditFOutput(const DataEdit &edit) {
canIncrease = false; // only once
continue;
} else if (expo == -fracDigits && convertedDigits > 0) {
- if (rounding != decimal::FortranRounding::RoundToZero) {
- // Convert again without rounding so that we can round here
- rounding = decimal::FortranRounding::RoundToZero;
- continue;
- } else if (converted.str[signLength] >= '5') {
- // Value rounds up to a scaled 1 (e.g., 0.06 for F5.1 -> 0.1)
+ if ((rounding == decimal::FortranRounding::RoundUp &&
+ *converted.str != '-') ||
+ (rounding == decimal::FortranRounding::RoundDown &&
+ *converted.str == '-') ||
+ (rounding == decimal::FortranRounding::RoundToZero &&
+ rounding != edit.modes.round && // it changed below
+ converted.str[signLength] >= '5')) {
+ // Round up/down to a scaled 1
++expo;
convertedDigits = 0;
trailingOnes = 1;
+ } else if (rounding != decimal::FortranRounding::RoundToZero) {
+ // Convert again with truncation so first digit can be checked
+ // on the next iteration by the code above
+ rounding = decimal::FortranRounding::RoundToZero;
+ continue;
} else {
// Value rounds down to zero
expo = 0;
More information about the flang-commits
mailing list