From 1f53043596e4f60c302974a83edbe2088fde4470 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 18 May 2005 01:30:55 +0000 Subject: [PATCH] Omit `-' in F format if value rounds to zero. --- src/ChangeLog | 5 +++++ src/data-out.c | 5 +++++ tests/expressions/randist/cauchy.out | 10 +++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index c7c31594..3836660d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Tue May 17 18:29:35 2005 Ben Pfaff + + * data-out.c: (format_and_round) Don't output leading `-' if value + rounds to zero. + Tue May 17 00:06:43 2005 Ben Pfaff Fix PR 11119. diff --git a/src/data-out.c b/src/data-out.c index d21d2902..ae322bce 100644 --- a/src/data-out.c +++ b/src/data-out.c @@ -1116,6 +1116,7 @@ format_and_round (char *dst, double number, const struct fmt_spec *fp, sprintf (buf, "%.*f", decimals, number); + /* Omit integer part if it's 0. */ if (!memcmp (buf, "0.", 2)) memmove (buf, buf + 1, strlen (buf)); else if (!memcmp (buf, "-0.", 3)) @@ -1215,6 +1216,10 @@ format_and_round (char *dst, double number, const struct fmt_spec *fp, } } + /* Omit `-' if value output is zero. */ + if (buf[0] == '-' && buf[strspn (buf, "-.0")] == '\0') + memmove (buf, buf + 1, strlen (buf)); + buf_copy_str_lpad (dst, fp->w, buf); return 1; } diff --git a/tests/expressions/randist/cauchy.out b/tests/expressions/randist/cauchy.out index 0cd1feef..dab2757e 100644 --- a/tests/expressions/randist/cauchy.out +++ b/tests/expressions/randist/cauchy.out @@ -298,11 +298,11 @@ .50 -1.00 1.00 -1.00 .50 .32 .50 -1.00 1.25 -1.00 .50 .25 .50 -1.00 1.50 -1.00 .50 .21 - .50 .00 .50 -.00 .50 .64 - .50 .00 .75 -.00 .50 .42 - .50 .00 1.00 -.00 .50 .32 - .50 .00 1.25 -.00 .50 .25 - .50 .00 1.50 -.00 .50 .21 + .50 .00 .50 .00 .50 .64 + .50 .00 .75 .00 .50 .42 + .50 .00 1.00 .00 .50 .32 + .50 .00 1.25 .00 .50 .25 + .50 .00 1.50 .00 .50 .21 .50 1.00 .50 1.00 .50 .64 .50 1.00 .75 1.00 .50 .42 .50 1.00 1.00 1.00 .50 .32 -- 2.30.2