zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@sunsite.dk>
Subject: Re: LC_NUMERIC=fr_FR and floating point arithmetics
Date: Tue, 11 Mar 2003 11:35:21 +0100	[thread overview]
Message-ID: <16574.1047378921@finches.logica.co.uk> (raw)
In-Reply-To: <20030310192526.GA15858@fysh.org>

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 */


  reply	other threads:[~2003-03-11 10:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-24 17:45 Stephane CHAZELAS
2003-03-10  8:58 ` Oliver Kiddle
2003-03-10 19:25   ` Zefram
2003-03-11 10:35     ` Oliver Kiddle [this message]
2003-03-12  3:32       ` Philippe Troin
2003-03-12  8:30         ` Oliver Kiddle

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=16574.1047378921@finches.logica.co.uk \
    --to=okiddle@yahoo.co.uk \
    --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).