https://gcc.gnu.org/g:a3a4735070882b6f179b30050615b0b344fc9a45
commit r17-1382-ga3a4735070882b6f179b30050615b0b344fc9a45 Author: Robert Dubner <[email protected]> Date: Fri Jun 5 15:16:06 2026 -0400 cobol: Update tests for IBM COMP-1/2 formatting. gcc/testsuite/ChangeLog: * cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob: Tests for "DISPLAY 1.23" as ".123 01". * cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out: Likewise. Diff: --- .../DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob | 62 ++++++++++++++-------- .../DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out | 13 +++-- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob b/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob index 5be9ea221999..f7927e7c3b1e 100644 --- a/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob +++ b/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.cob @@ -1,25 +1,45 @@ *> { dg-do run } *> { dg-options "-dialect ibm" } *> { dg-output-file "group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out" } - identification division. - program-id. prog. - data division. - working-storage section. - 01 f1 comp-1 value 1.5. - 01 f2 comp-1 value 0.1. - 01 f3 comp-1 value -2.75. - 01 f4 comp-1 value 1500. - 01 f5 comp-1 value 0.001500. - 01 d1 comp-2 value 2.71828. - 01 d2 comp-2 value -0.0000271828. - procedure division. - display f1 - display f2 - display f3 - display f4 - display f5 - display d1 - display d2 - goback. - end program prog. + * gcobol bug reproducer: DISPLAY of a COMP-1 / COMP-2 (internal floating-point) + * item does not use the IBM external floating-point form. + * + * Per IBM Enterprise COBOL, DISPLAY of an internal floating-point item converts it + * to external floating-point: a COMP-1 displays "as if it had an external + * floating-point PICTURE clause of -.9(8)E-99", and a COMP-2 as -.9(17)E-99 + * (Language Reference SC27-8713-04, "DISPLAY statement", p.340). The value is shown as + * <sign>.<mantissa>E<expsign><2-digit exponent> + * with the mantissa normalized to a leading non-zero digit, and the sign / exponent + * sign blank for non-negative. + * + * Observed (gcobol 15.2.0) Expected (IBM LR external floating-point) + * 1.5 " .15000000E 01" + * 0.1000000015 " .10000000E 00" + * -2.75 "-.27500000E 01" + * 1500 " .15000000E 04" + * 2.71828000000000003 " .27182800000000000E 01" + * + * gcobol prints the plain decimal value (with binary-float artifacts) instead of the + * documented external floating-point layout. This reproduces with the default + * dialect and also with "-dialect ibm" specified explicitly: + * gcobol -dialect ibm -o fltdisp float-display-not-external.cob && ./fltdisp + * produces the same (non-conforming) output. + IDENTIFICATION DIVISION. + PROGRAM-ID. FLTDISP. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 F1 COMP-1 VALUE 1.5. + 01 F2 COMP-1 VALUE 0.1. + 01 F3 COMP-1 VALUE -2.75. + 01 F4 COMP-1 VALUE 1500. + 01 D1 COMP-2 VALUE 2.71828. + 01 D2 COMP-2 VALUE -.0000314159. + PROCEDURE DIVISION. + DISPLAY F1 + DISPLAY F2 + DISPLAY F3 + DISPLAY F4 + DISPLAY D1 + DISPLAY D2 + STOP RUN. diff --git a/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out b/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out index 9c7d7775cb6f..15ac657fb438 100644 --- a/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out +++ b/gcc/testsuite/cobol.dg/group2/DISPLAY_IBM-formatted_COMP-1_and_COMP-2.out @@ -1,8 +1,7 @@ - 1.50000000E 00 - 1.00000001E-01 --2.75000000E 00 - 1.50000000E 03 - 1.50000001E-03 - 2.71828000000000003E 00 --2.71828000000000000E-05 + .15000000E 01 + .10000000E 00 +-.27500000E 01 + .15000000E 04 + .27182800000000000E 01 +-.31415900000000000E-04
