From owner-freebsd-bugs Sun Aug 25 6:50:11 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EC6C637B400 for ; Sun, 25 Aug 2002 06:50:04 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 86E9743E84 for ; Sun, 25 Aug 2002 06:50:04 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7PDo4JU088827 for ; Sun, 25 Aug 2002 06:50:04 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7PDo4W4088825; Sun, 25 Aug 2002 06:50:04 -0700 (PDT) Date: Sun, 25 Aug 2002 06:50:04 -0700 (PDT) Message-Id: <200208251350.g7PDo4W4088825@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Jens Schweikhardt Subject: Re: bin/41823: printf("%+f\n", -0.0) generates +0.000000 Reply-To: Jens Schweikhardt Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/41823; it has been noted by GNATS. From: Jens Schweikhardt To: Bruce Evans Cc: GNATS Bug Followup 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