From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Cc: 448732-forwarded@bugs.debian.org
Subject: Re: Bug#448732: zsh: printf %g -0 outputs 0 instead of -0
Date: Tue, 6 Nov 2007 10:46:20 +0000 [thread overview]
Message-ID: <20071106104620.17b5760c@news01> (raw)
In-Reply-To: <20071031163838.GA21586@scowler.net>
On Wed, 31 Oct 2007 12:38:38 -0400
Clint Adams <schizo@debian.org> 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 <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
next prev parent reply other threads:[~2007-11-06 10:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071031121911.GA2242@vin.lip.ens-lyon.fr>
2007-10-31 16:38 ` Clint Adams
2007-11-06 10:46 ` Peter Stephenson [this message]
2007-11-12 14:26 ` Vincent Lefevre
2007-11-12 14:30 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071106104620.17b5760c@news01 \
--to=pws@csr.com \
--cc=448732-forwarded@bugs.debian.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).