diff --git a/libcob/ChangeLog b/libcob/ChangeLog index 3f523717..bd4e74e4 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -1,4 +1,9 @@ +2024-12-23 David Declerck + + * termio.c (clean_double): skip more than a single leading + zero in exponent display + 2024-12-18 David Declerck * string.c: fix a bug where the source of STRING/UNSTRING/INSPECT diff --git a/libcob/termio.c b/libcob/termio.c index c44d31ce..83ecba97 100644 --- a/libcob/termio.c +++ b/libcob/termio.c @@ -225,9 +225,15 @@ clean_double (char *wrk) char *pos = strrchr (wrk, 'E'); if (pos) { + char *src; pos += 2; /* skip E+ */ - if (pos[0] == '0') { - memmove (pos, pos + 1, strlen (pos)); + /* Skip leading zeroes */ + /* Note: each COBOL environment has a different output format for floats; + here we only check for internal consistency (support for other + formats might be considered for addition if widely requested) */ + for (src = pos; *src == '0'; ++src); + if (src != pos) { + memmove (pos, src, strlen (src) + 1); } return; } diff --git a/tests/testsuite.src/run_misc.at b/tests/testsuite.src/run_misc.at index 97157f4f..69dfde68 100644 --- a/tests/testsuite.src/run_misc.at +++ b/tests/testsuite.src/run_misc.at @@ -15226,3 +15226,28 @@ AT_CHECK([$COMPILE prog.cob]) AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [], []) AT_CLEANUP + + +AT_SETUP([DISPLAY FLOAT]) +AT_KEYWORDS([FLOAT-SHORT FLOAT-LONG COMP-1 COMP-2]) + +# Note: each COBOL environment has a different output format for floats; +# here we only check for internal consistency (support for other +# formats might be considered for addition if widely requested) + +AT_DATA([prog.cob], [ + IDENTIFICATION DIVISION. + PROGRAM-ID. prog. + DATA DIVISION. + WORKING-STORAGE SECTION. + 01 X FLOAT-SHORT VALUE 0.000012345. + 01 Y FLOAT-LONG VALUE 0.000012345. + PROCEDURE DIVISION. + DISPLAY X SPACE Y WITH NO ADVANCING. + STOP RUN. +]) + +AT_CHECK([$COMPILE prog.cob]) +AT_CHECK([$COBCRUN_DIRECT ./prog], [0], [1.2345E-5 1.2345E-5], []) + +AT_CLEANUP