From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11939 invoked from network); 11 Mar 2003 10:39:56 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 11 Mar 2003 10:39:56 -0000 Received: (qmail 23759 invoked by alias); 11 Mar 2003 10:39:43 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 18337 Received: (qmail 23746 invoked from network); 11 Mar 2003 10:39:43 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 11 Mar 2003 10:39:43 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [212.125.75.4] by sunsite.dk (MessageWall 1.0.8) with SMTP; 11 Mar 2003 10:39:43 -0000 Received: (qmail 13462 invoked from network); 11 Mar 2003 10:31:27 -0000 Received: from iris.logica.co.uk (158.234.9.163) by server-9.tower-1.messagelabs.com with SMTP; 11 Mar 2003 10:31:27 -0000 Received: from finches.logica.co.uk ([158.234.142.11]) by iris.logica.co.uk (8.9.3/8.9.3/Debian 8.9.3-21) with ESMTP id KAA18104 for ; Tue, 11 Mar 2003 10:31:26 GMT X-Authentication-Warning: iris.logica.co.uk: Host [158.234.142.11] claimed to be finches.logica.co.uk Received: from finches.logica.co.uk (localhost [127.0.0.1]) by finches.logica.co.uk (8.11.6/8.11.6/SuSE Linux 0.5) with ESMTP id h2BAZL816576 for ; Tue, 11 Mar 2003 11:35:22 +0100 X-VirusChecked: Checked In-reply-to: <20030310192526.GA15858@fysh.org> From: Oliver Kiddle References: <20030224184502.A9922@pcchazelas.free.fr> <1556.1047286700@finches.logica.co.uk> <20030310192526.GA15858@fysh.org> To: Zsh workers Subject: Re: LC_NUMERIC=fr_FR and floating point arithmetics Date: Tue, 11 Mar 2003 11:35:21 +0100 Message-ID: <16574.1047378921@finches.logica.co.uk> Zefram wrote: > > Numeric output should by default be in the input format (C locale) > so that it can be reused in the expected manner. Okay, this patch makes it do that. > If printf is not > sufficient for rendering numbers in human format, we could add an > output-using-locale flag to the output format specification syntax of > $(()) -- there's already syntax to select the radix to use on output. It would possibly be more useful for $a than $(()) because that is where all the typeset -F/-E stuff applies. I'll wait and see if there is demand and if so, a parameter expansion flag could also be added (L and l are gone along with most of the rest of the alphabet so we'd need to think of a suitable free letter). If ksh keeps it's current behaviour, a KSH_something option could perhaps be used. I consider this patch a bug fix which would imply that I should apply it to 4.0 but 4.0 doesn't have printf and hence has no way to output floats in the current locale. I could backport printf, leave the patch out of 4.0 or do something else. Any thoughts? Note also, that there is no way to input numbers with locale conventions. If there is demand for a way to do this, we could perhaps add an option to read so that typeset -F num; read num would do this but lose math evaluation. Or perhaps add the facility somewhere else. Oliver Index: Src/params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/params.c,v retrieving revision 1.69 diff -u -r1.69 params.c --- Src/params.c 31 Oct 2002 18:32:40 -0000 1.69 +++ Src/params.c 11 Mar 2003 10:00:10 -0000 @@ -3417,6 +3417,7 @@ convfloat(double dval, int digits, int flags, FILE *fout) { char fmt[] = "%.*e"; + char *prev_locale, *ret; /* * The difficulty with the buffer size is that a %f conversion @@ -3451,16 +3452,24 @@ digits--; } } +#ifdef USE_LOCALE + prev_locale = dupstring(setlocale(LC_NUMERIC, NULL)); + setlocale(LC_NUMERIC, "POSIX"); +#endif if (fout) { fprintf(fout, fmt, digits, dval); - return NULL; + ret = NULL; } else { VARARR(char, buf, 512 + digits); sprintf(buf, fmt, digits, dval); if (!strchr(buf, 'e') && !strchr(buf, '.')) strcat(buf, "."); - return dupstring(buf); + ret = dupstring(buf); } +#ifdef USE_LOCALE + if (prev_locale) setlocale(LC_NUMERIC, prev_locale); +#endif + return ret; } /* Start a parameter scope */