https://gcc.gnu.org/g:033e0079a4c498c287d610546cf85e83be003e71

commit r17-1380-g033e0079a4c498c287d610546cf85e83be003e71
Author: Robert Dubner <[email protected]>
Date:   Fri Jun 5 14:57:27 2026 -0400

    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.

Diff:
---
 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 9a9a49e78cb2..69493276ac14 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 dd7ea15dbec6..64a61411ecba 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)

Reply via email to