Xref: news2.mv.net comp.os.msdos.djgpp:8307 From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: printf format string question Date: Thu, 05 Sep 1996 13:01:42 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 50 Message-ID: <322EC126.41C6@LSTM.Ruhr-UNI-Bochum.De> References: NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Samuel Vincent wrote: > > On Thu, 5 Sep 1996, Eli Zaretskii wrote: > > > On Wed, 4 Sep 1996, x DOT pons AT cc DOT uab DOT es wrote: > > > > > How can specify a width fixed to 3 for the exponent of double variables > > > in printf format strings? That is to say, I want an output like > > > 3.2345E+034 > > > 3.2345E+134 > > > > I don't think this is possible, at least not in ANSI C. The ANSI > > standard says the exponent will always have at least 2 digits, but > > promises nothing else, and no flags are provided to have any control > > whatsoever on the exponent field. > > Oh come now.. it's always possible to do anything.. :) > > Just grab the printf function from the libc source and modify it to your > heart's content. ;) > > -Sam Well, it is possible, but is it sensible? Modifying a libc function in a way that it is no longer ANSI compliant is IMHO not a good solution, as you are loosing compability. A better way is to copy the function and call it SamPrintf (or what ever). Even then you might get into trouble, as you need to modify _doprnt() (The core routine), too. At a first glance I did not see problems with portability, but I may be wrong. On a second glance I found that the representation of NaN relies on IEEE representation of doubles and endianess of the target machine. -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * Voice/Fax Box: +49 2561 91371 2056 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************