From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27522 invoked from network); 1 Nov 2001 18:24:39 -0000 Received: from ns2.primenet.com.au (HELO primenet.com.au) (?pEoPp1HX24+pRUNS5R3nDRVBiDqsDOdI?@203.24.36.3) by ns1.primenet.com.au with SMTP; 1 Nov 2001 18:24:39 -0000 Received: (qmail 11432 invoked from network); 1 Nov 2001 18:24:38 -0000 Received: from sunsite.dk (130.225.247.90) by proxy.melb.primenet.com.au with SMTP; 1 Nov 2001 18:24:38 -0000 Received: (qmail 7473 invoked by alias); 1 Nov 2001 18:24:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16203 Received: (qmail 7461 invoked from network); 1 Nov 2001 18:24:30 -0000 X-VirusChecked: Checked Sender: kiddleo@cav.logica.co.uk Message-ID: <3BE191B5.B4FDC8E8@yahoo.co.uk> Date: Thu, 01 Nov 2001 18:17:25 +0000 From: Oliver Kiddle X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.15 i686) X-Accept-Language: en MIME-Version: 1.0 To: Zsh hackers list Subject: Re: printf References: <13357.1004634977@csr.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Peter Stephenson wrote: > > Oliver Kiddle wrote: > > I'd like to be able to support the ' (thousand grouping) > > The more I think about this, the more it seems to me that using quotes is > simply going to cause grief (unless I've misunderstood). Is there any > reason for this rather than the perl version, `_', which isn't going to > conflict with anything? Ksh and many newer printf(3)s use the single quote but I agree with you that it is a bad choice. Is this `_' a new perl feature: perl -e 'printf "%_g\n",132643.45' does not work with 5.0005_03 or am I putting the underscore in the wrong place. We can always offer a choice of flag character here. Going back to my questions earlier this week, fcvt() etc are a bad idea. They don't exist everywhere, on some (BSD) systems, they are in compat libraries and sprintf is seemingly just as good but more available. My idea of writing a function from scratch to format floats was also a bad idea. I've been referred to http://plan9.bell-labs.com/netlib/fp as example source. A brief glance was enough to appreciate that it would be bloat and overkill as well as being not at all easy. This returns me to using sprintf which should be okay. The first issue is dealing with very large precisions specified for floating point variables. To use sprintf, I would potentially have to allocate a stupidly large amount of memory which I'd prefer to avoid. Large widths are not an issue - I'll not use sprintf for the widths but will just call putchar in a loop before or after outputting the formatted argument. They might cause problems with print -s and -z though. I could maybe truncate these to the maximum length a command can be (how do I find that out again?). One solution for dealing with large precisions would be to put a limit on the precision. I can't really see why anyone would want something like '%.10000f' anyway. An easy solution would be to allocate a buffer for sprintf which is based on the maximum length of any argument and at least say 100. You don't get any greater precision than about 60 with doubles anyway. If someone tries '%.101g', they would then get a warning that such precisions are not supported. Or I could just truncate the number returned. Any views on these ideas? To support the ' flag, I'll try a configure test to check for support in printf(3) and otherwise, insert the separators retrospectively. The second issue is working out what is going on with locales. Does basic printf do locales on any platforms? The I flag is glibc 2.2. I'd like to have the I flag in zsh and locales no used without it so that users can rely on the output of printf. Unfortunately, every machine I have access to seems to only have English locale data installed so it is hard to work out what is happening. Oliver _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. For further information visit http://www.messagelabs.com/stats.asp