[flang-commits] [flang] 5e21fa2 - [flang][runtime] Fix off-by-one error in EX0.0 output editing (#85428)
via flang-commits
flang-commits at lists.llvm.org
Fri Mar 15 13:56:50 PDT 2024
Author: Peter Klausler
Date: 2024-03-15T13:56:47-07:00
New Revision: 5e21fa23bb242d6e0575c1ca630e4d293413aed6
URL: https://github.com/llvm/llvm-project/commit/5e21fa23bb242d6e0575c1ca630e4d293413aed6
DIFF: https://github.com/llvm/llvm-project/commit/5e21fa23bb242d6e0575c1ca630e4d293413aed6.diff
LOG: [flang][runtime] Fix off-by-one error in EX0.0 output editing (#85428)
The maximum number of significant hexadecimal digits in EX0.0 REAL
output editing is 29, not 28. Fix by computing it at build time from the
precision of REAL(16).
Added:
Modified:
flang/runtime/edit-output.cpp
Removed:
################################################################################
diff --git a/flang/runtime/edit-output.cpp b/flang/runtime/edit-output.cpp
index b474c8cd91bae4..7267540370fc07 100644
--- a/flang/runtime/edit-output.cpp
+++ b/flang/runtime/edit-output.cpp
@@ -9,6 +9,7 @@
#include "edit-output.h"
#include "emit-encoded.h"
#include "utf.h"
+#include "flang/Common/real.h"
#include "flang/Common/uint128.h"
#include <algorithm>
@@ -700,7 +701,9 @@ bool RealOutputEditing<KIND>::EditEXOutput(const DataEdit &edit) {
if ((editWidth == 0 && !edit.digits) || editDigits == 0) {
// EX0 or EXw.0
flags |= decimal::Minimize;
- significantDigits = 28; // enough for 128-bit F.P.
+ static constexpr int maxSigHexDigits{
+ (common::PrecisionOfRealKind(16) + 3) / 4};
+ significantDigits = maxSigHexDigits;
}
auto converted{
ConvertToHexadecimal(significantDigits, edit.modes.round, flags)};
More information about the flang-commits
mailing list