Skip to content

Commit

Permalink
Skip more than a single leading 0 in exponent display
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeclerck committed Dec 23, 2024
1 parent 5086fdf commit 36b8666
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

2024-12-23 David Declerck <[email protected]>

* termio.c (clean_double): skip more than a single leading
zero in exponent display

2024-12-18 David Declerck <[email protected]>

* string.c: fix a bug where the source of STRING/UNSTRING/INSPECT
Expand Down
10 changes: 8 additions & 2 deletions libcob/termio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
25 changes: 25 additions & 0 deletions tests/testsuite.src/run_misc.at
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 36b8666

Please sign in to comment.