www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/05/13:01:01

Xref: news2.mv.net comp.os.msdos.djgpp:8307
From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
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: <Pine DOT GSO DOT 3 DOT 94 DOT 960905025133 DOT 12616A-100000 AT zippy>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
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                *
*************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019