https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125616
Bug ID: 125616
Summary: [cobol] DISPLAY of a COMP-1/COMP-2 float omits the
external floating-point form
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: cobol
Assignee: unassigned at gcc dot gnu.org
Reporter: peeterjoot at protonmail dot com
Target Milestone: ---
Created attachment 64631
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64631&action=edit
cobol float (COMP-1/2) display reproducer.
## Summary
`DISPLAY` of an internal floating-point item (`COMP-1` / `COMP-2`) prints the
plain
decimal value (including binary-float artifacts) rather than the IBM external
floating-point layout. IBM Enterprise COBOL converts the item to external
floating-point for display: a `COMP-1` displays as if it had `PICTURE
-.9(8)E-99`, a
`COMP-2` as `-.9(17)E-99`.
## Environment
- Compiler: `gcobol (Ubuntu 15.2.0-16ubuntu1) 15.2.0` (GCC COBOL front end)
- Platform: Linux x86-64 / aarch64
- Reproduces with the default dialect **and** with `-dialect ibm` specified
explicitly
(the IBM dialect option does not restore the IBM external floating-point
layout).
## Reproducer
`float-display-not-external.cob` (in this directory):
```cobol
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.
...
DISPLAY F1
DISPLAY F2
DISPLAY F3
DISPLAY F4
DISPLAY D1
```
```
gcobol -o fltdisp float-display-not-external.cob && ./fltdisp
```
The same output is produced when the IBM dialect is selected explicitly:
```
gcobol -dialect ibm -o fltdisp float-display-not-external.cob && ./fltdisp
```
## Observed (gcobol 15.2.0, default dialect or `-dialect ibm`)
```
1.5
0.1000000015
-2.75
1500
2.71828000000000003
```
## Expected (IBM Enterprise COBOL)
```
.15000000E 01
.10000000E 00
-.27500000E 01
.15000000E 04
.27182800000000000E 01
```
The value is converted to external floating-point:
`<sign>.<mantissa>E<expsign><2-digit
exponent>`, mantissa normalized (leading non-zero digit), with the
mantissa-sign and
exponent-sign positions blank for non-negative (the conversion picture uses
`-`, which
shows blank for positive and `-` for negative).
## Reference
IBM Enterprise COBOL for z/OS 6.5 Language Reference, SC27-8713-04, **DISPLAY
statement**
(p.340):
> "Internal floating-point numbers are converted to external floating-point
> numbers for
> display such that: A COMP-1 item will display as if it had an external
> floating-point
> PICTURE clause of -.9(8)E-99. A COMP-2 item will display as if it had an
> external
> floating-point PICTURE clause of -.9(17)E-99."
## Impact
DISPLAY output of `COMP-1`/`COMP-2` items does not match IBM Enterprise COBOL,
which
matters for porting/regression against mainframe-produced reference output.
## Note
This may be an intentional "readable" rendering choice in gcobol; this report
documents
the divergence from the IBM Enterprise COBOL LR for projects targeting that
behavior.