From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16277 invoked from network); 6 Nov 2007 10:50:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 Nov 2007 10:50:51 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 25185 invoked from network); 6 Nov 2007 10:50:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Nov 2007 10:50:45 -0000 Received: (qmail 19660 invoked by alias); 6 Nov 2007 10:50:42 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24068 Received: (qmail 19642 invoked from network); 6 Nov 2007 10:50:41 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 6 Nov 2007 10:50:41 -0000 Received: (qmail 24873 invoked from network); 6 Nov 2007 10:50:41 -0000 Received: from cluster-g.mailcontrol.com (85.115.41.190) by a.mx.sunsite.dk with SMTP; 6 Nov 2007 10:50:35 -0000 Received: from rly12g.srv.mailcontrol.com (localhost.localdomain [127.0.0.1]) by rly12g.srv.mailcontrol.com (MailControl) with ESMTP id lA6Ao5sx027876 for ; Tue, 6 Nov 2007 10:50:11 GMT Received: from submission.mailcontrol.com (submission.mailcontrol.com [86.111.216.190]) by rly12g.srv.mailcontrol.com (MailControl) id lA6An91D025330 for zsh-workers@sunsite.dk; Tue, 6 Nov 2007 10:49:09 GMT Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly12g-eth0.srv.mailcontrol.com (envelope-sender Peter.Stephenson@csr.com) (MIMEDefang) with ESMTP id lA6Aj1dV010600; Tue, 06 Nov 2007 10:49:09 +0000 (GMT) Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Tue, 6 Nov 2007 10:46:21 +0000 Date: Tue, 6 Nov 2007 10:46:20 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk Cc: 448732-forwarded@bugs.debian.org Subject: Re: Bug#448732: zsh: printf %g -0 outputs 0 instead of -0 Message-ID: <20071106104620.17b5760c@news01> In-Reply-To: <20071031163838.GA21586@scowler.net> References: <20071031121911.GA2242@vin.lip.ens-lyon.fr> <20071031163838.GA21586@scowler.net> Organization: CSR X-Mailer: Claws Mail 3.0.2 (GTK+ 2.10.14; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 06 Nov 2007 10:46:21.0050 (UTC) FILETIME=[44A35DA0:01C82062] X-Scanned-By: MailControl A-08-00-00 (www.mailcontrol.com) on 10.71.1.122 On Wed, 31 Oct 2007 12:38:38 -0400 Clint Adams wrote: > I believe the gist is that since %g calls for a float, -0 should be > parsed as negative zero. I tried the following patch, but on my system (Fedora 7 with glibc glibc-2.6-4) strtod() returns the double value 0 (not -0) when parsing the input "-0". I confirmed this with a standalone programme. It seems pointless working around this in the shell. =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.180 diff -u -r1.180 builtin.c --- Src/builtin.c 6 Jul 2007 21:52:39 -0000 1.180 +++ Src/builtin.c 6 Nov 2007 10:39:29 -0000 @@ -4162,9 +4162,25 @@ break; case 2: if (curarg) { - mnumval = matheval(curarg); - doubleval = (mnumval.type & MN_FLOAT) ? - mnumval.u.d : (double)mnumval.u.l; + char *eptr; + /* + * First attempt to parse as a floating + * point constant. If we go through + * a math evaluation, we can lose + * mostly unimportant information + * that people in standards organizations + * worry about. + */ + doubleval = strtod(curarg, &eptr); + /* + * If it didn't parse as a constant, + * parse it as an expression. + */ + if (*eptr != '\0') { + mnumval = matheval(curarg); + doubleval = (mnumval.type & MN_FLOAT) ? + mnumval.u.d : (double)mnumval.u.l; + } } else doubleval = 0; if (errflag) { doubleval = 0; -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070