* Re: Bug#448732: zsh: printf %g -0 outputs 0 instead of -0 [not found] <20071031121911.GA2242@vin.lip.ens-lyon.fr> @ 2007-10-31 16:38 ` Clint Adams 2007-11-06 10:46 ` Peter Stephenson 0 siblings, 1 reply; 4+ messages in thread From: Clint Adams @ 2007-10-31 16:38 UTC (permalink / raw) To: zsh-workers; +Cc: Vincent Lefevre, 448732-forwarded I believe the gist is that since %g calls for a float, -0 should be parsed as negative zero. On Wed, Oct 31, 2007 at 01:19:11PM +0100, Vincent Lefevre wrote: > vin:~> printf "%g %g\n" -0 -0. > 0 -0 > > whereas with the printf from the coreutils on etch: > > courge:~> /usr/bin/printf "%g %g\n" -0 -0. > -0 -0 > > (this will not work on sid due to the bug 448723, but this is a > different bug since the zsh behavior is the same on any OS). > > Discussion: > https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=11150 > https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=11151 > https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=11156 > https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=11159 > https://www.opengroup.org/sophocles/show_mail.tpl?CALLER=show_archive.tpl&source=L&listname=austin-group-l&id=11160 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Bug#448732: zsh: printf %g -0 outputs 0 instead of -0 2007-10-31 16:38 ` Bug#448732: zsh: printf %g -0 outputs 0 instead of -0 Clint Adams @ 2007-11-06 10:46 ` Peter Stephenson 2007-11-12 14:26 ` Vincent Lefevre 0 siblings, 1 reply; 4+ messages in thread From: Peter Stephenson @ 2007-11-06 10:46 UTC (permalink / raw) To: zsh-workers; +Cc: 448732-forwarded 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Bug#448732: zsh: printf %g -0 outputs 0 instead of -0 2007-11-06 10:46 ` Peter Stephenson @ 2007-11-12 14:26 ` Vincent Lefevre 2007-11-12 14:30 ` Peter Stephenson 0 siblings, 1 reply; 4+ messages in thread From: Vincent Lefevre @ 2007-11-12 14:26 UTC (permalink / raw) To: zsh-workers On 2007-11-06 10:46:20 +0000, Peter Stephenson wrote: > 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. The bug in glibc's strtod() was fixed on 2007-08-03: revision 1.25 date: 2007/08/03 16:45:24; author: drepper; state: Exp; lines: +4 -3 (____STRTOF_INTERNAL): Properly handle -0. So, zsh has to fix only its bug. -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon) ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Bug#448732: zsh: printf %g -0 outputs 0 instead of -0 2007-11-12 14:26 ` Vincent Lefevre @ 2007-11-12 14:30 ` Peter Stephenson 0 siblings, 0 replies; 4+ messages in thread From: Peter Stephenson @ 2007-11-12 14:30 UTC (permalink / raw) To: zsh-workers Vincent Lefevre wrote: > On 2007-11-06 10:46:20 +0000, Peter Stephenson wrote: > > 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. > > The bug in glibc's strtod() was fixed on 2007-08-03: > > revision 1.25 > date: 2007/08/03 16:45:24; author: drepper; state: Exp; lines: +4 -3 > (____STRTOF_INTERNAL): Properly handle -0. Thanks, I committed the change in zh so the problem should go away eventually. -- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-11-12 14:31 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <20071031121911.GA2242@vin.lip.ens-lyon.fr> 2007-10-31 16:38 ` Bug#448732: zsh: printf %g -0 outputs 0 instead of -0 Clint Adams 2007-11-06 10:46 ` Peter Stephenson 2007-11-12 14:26 ` Vincent Lefevre 2007-11-12 14:30 ` Peter Stephenson
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).