Date: Sun, 25 Aug 2002 06:50:04 -0700 (PDT)
From: Jens Schweikhardt <schweikh@schweikhardt.net>
To: freebsd-bugs@FreeBSD.org
Subject: Re: bin/41823: printf("%+f\n", -0.0) generates +0.000000
Message-ID: <200208251350.g7PDo4W4088825@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/41823; it has been noted by GNATS.
From: Jens Schweikhardt <schweikh@schweikhardt.net>
To: Bruce Evans <bde@zeta.org.au>
Cc: GNATS Bug Followup <bug-followup@FreeBSD.org>
Subject: Re: bin/41823: printf("%+f\n", -0.0) generates +0.000000
Date: Sun, 25 Aug 2002 15:31:21 +0200
On Thu, Aug 22, 2002 at 09:36:30AM +1000, Bruce Evans wrote:
...
# % ===================================================================
# % RCS file: /home/ncvs/src/lib/libc/stdio/vfprintf.c,v
# % retrieving revision 1.43
# % diff -u -r1.43 vfprintf.c
# % --- src/lib/libc/stdio/vfprintf.c 15 Aug 2002 10:28:52 -0000 1.43
# % +++ src/lib/libc/stdio/vfprintf.c 21 Aug 2002 11:17:14 -0000
# % @@ -1409,13 +1409,13 @@
# % ndigits++;
# % mode = 2; /* ndigits significant digits */
# % }
# % - if (value < 0) {
# % + digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve,
# % + dtoaresultp);
# % + if (dsgn) {
# % value = -value;
# % *sign = '-';
# % } else
# % *sign = '\000';
# % - digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve,
# % - dtoaresultp);
# % if ((ch != 'g' && ch != 'G') || flags & ALT) {
# % /* print trailing zeros */
# % bp = digits + ndigits;
# %
#
# Style bugs:
# new:
# negating "value" after using it is bogus. (It is used later, but only
# as a boolean.)
# old:
# don't need to split the __dtoa() line.
# very old (in rev.1.1):
# *sign is a really a boolean, so setting to character values is bogus.
# (It is named *softsign in the only caller and used to set a variable
# named "sign" which really holds a character value there. The caller
# also spells '\0' normally. Actually that '\0' is really a boolean
# too -- it never gets printed for obvious reasons.)
Ok, here's a patch you'll like -- it reduces the lines of code :-)
Index: vfprintf.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/stdio/vfprintf.c,v
retrieving revision 1.43
diff -u -r1.43 vfprintf.c
--- vfprintf.c 15 Aug 2002 10:28:52 -0000 1.43
+++ vfprintf.c 25 Aug 2002 13:26:08 -0000
@@ -1409,13 +1409,8 @@
ndigits++;
mode = 2; /* ndigits significant digits */
}
- if (value < 0) {
- value = -value;
- *sign = '-';
- } else
- *sign = '\000';
- digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve,
- dtoaresultp);
+ digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp);
+ *sign = dsgn != 0;
if ((ch != 'g' && ch != 'G') || flags & ALT) {
/* print trailing zeros */
bp = digits + ndigits;
Regards,
Jens
--
Jens Schweikhardt http://www.schweikhardt.net/
SIGSIG -- signature too long (core dumped)
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208251350.g7PDo4W4088825>
