[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).
This commit is contained in:
Peter Klausler
2024-03-15 13:56:47 -07:00
committed by GitHub
parent ca4c4a6758
commit 5e21fa23bb

View File

@@ -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)};