>From 0ac8b7e41bc7f7a781f6a44db496c13fd725a3b8 Mon Sep 17 00:00:00 2001
From: Robert Dubner <[email protected]>
Date: Fri, 5 Jun 2026 14:57:27 -0400
Subject: [PATCH] cobol: Properly DISPLAY COMP-1/-2 variables when
"-dialect
ibm" is in effect. [PR125616]
Second try at DISPLAY COMP-1. The generated output now matches the
example giving in the PR.
This also addresses a lang.opt.urls problem.
PR cobol/125616
gcc/cobol/ChangeLog:
* lang.opt.urls: Regenerated.
libgcobol/ChangeLog:
* libgcobol.cc (format_for_display_internal): Format matches the
description in the PR.
---
gcc/cobol/lang.opt.urls | 6 ++++++
libgcobol/libgcobol.cc | 19 +++++++++++++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/gcc/cobol/lang.opt.urls b/gcc/cobol/lang.opt.urls
index 9a9a49e78cb..69493276ac1 100644
--- a/gcc/cobol/lang.opt.urls
+++ b/gcc/cobol/lang.opt.urls
@@ -1,5 +1,8 @@
; Autogenerated by regenerate-opt-urls.py from gcc/cobol/lang.opt and
generated HTML
+B
+UrlSuffix(gcc/Directory-Options.html#index-B)
LangUrlSuffix_D(gdc/Directory-Options.html#index-B)
+
D
UrlSuffix(gcc/Preprocessor-Options.html#index-D-1)
@@ -37,3 +40,6 @@ UrlSuffix(gcc/Directory-Options.html#index-isysroot)
LangUrlSuffix_Fortran(gfort
isystem
UrlSuffix(gcc/Directory-Options.html#index-isystem)
LangUrlSuffix_Fortran(gfortran/Preprocessing-Options.html#index-isystem)
+idirafter
+UrlSuffix(gcc/Directory-Options.html#index-idirafter)
LangUrlSuffix_Fortran(gfortran/Preprocessing-Options.html#index-idirafter)
+
diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc
index dd7ea15dbec..64a61411ecb 100644
--- a/libgcobol/libgcobol.cc
+++ b/libgcobol/libgcobol.cc
@@ -3505,15 +3505,21 @@ format_for_display_internal(char **dest,
// A COMP-1 item will display as if it had an external
// floating-point PICTURE clause of -.9(8)E-99.
// The plus signs are suppressed.
+ floatval *= 10; // Needed because we are going to flip the
+ // // decimal point and first digit.
if( floatval >= 0 )
{
- strfromf32(ach+1, sizeof(ach), "%.8E", floatval);
+ strfromf32(ach+1, sizeof(ach), "%.7E", floatval);
ach[0] = ascii_space;
}
else
{
- strfromf32(ach, sizeof(ach), "%.8E", floatval);
+ strfromf32(ach, sizeof(ach), "%.7E", floatval);
}
+ // Turn 1.23 into .123
+ ach[2] = ach[1];
+ ach[1] = ascii_period;
+
// Turn "E+00" to the IBM "E 00"
p = strchr(ach, ascii_plus);
if(p)
@@ -3570,15 +3576,20 @@ format_for_display_internal(char **dest,
// A COMP-2 item will display as if it had an external
// floating-point PICTURE clause of -.9(17)E-99.
// The plus signs are suppressed.
+ floatval *= 10; // Needed because we are going to flip the
+ // // decimal point and first digit.
if( floatval >= 0 )
{
- strfromf64(ach+1, sizeof(ach), "%.17E", floatval);
+ strfromf64(ach+1, sizeof(ach), "%.16E", floatval);
ach[0] = ascii_space;
}
else
{
- strfromf64(ach, sizeof(ach), "%.17E", floatval);
+ strfromf64(ach, sizeof(ach), "%.16E", floatval);
}
+ // Turn 1.23 into .123
+ ach[2] = ach[1];
+ ach[1] = ascii_period;
// Turn "E+00" to the IBM "E 00"
p = strchr(ach, ascii_plus);
if(p)
--
2.34.1