Skip to content

Commit 5e21fa2

Browse files
authored
[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).
1 parent ca4c4a6 commit 5e21fa2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

flang/runtime/edit-output.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "edit-output.h"
1010
#include "emit-encoded.h"
1111
#include "utf.h"
12+
#include "flang/Common/real.h"
1213
#include "flang/Common/uint128.h"
1314
#include <algorithm>
1415

@@ -700,7 +701,9 @@ bool RealOutputEditing<KIND>::EditEXOutput(const DataEdit &edit) {
700701
if ((editWidth == 0 && !edit.digits) || editDigits == 0) {
701702
// EX0 or EXw.0
702703
flags |= decimal::Minimize;
703-
significantDigits = 28; // enough for 128-bit F.P.
704+
static constexpr int maxSigHexDigits{
705+
(common::PrecisionOfRealKind(16) + 3) / 4};
706+
significantDigits = maxSigHexDigits;
704707
}
705708
auto converted{
706709
ConvertToHexadecimal(significantDigits, edit.modes.round, flags)};

0 commit comments

Comments
 (0)