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

Date: Thu, 5 Sep 1996 13:11:29 -0400 (EDT)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
cc: djgpp AT delorie DOT com
Subject: Re: printf format string question
In-Reply-To: <322EC126.41C6@LSTM.Ruhr-UNI-Bochum.De>
Message-ID: <Pine.SOL.3.91.960905130927.1512B-100000@hops.cs.jhu.edu>
MIME-Version: 1.0

Why not simply use sprinf() to print to a string, search for the 'E', and 
use sscanf() on the number that follows in that position, and then 
sprintf() that number back at that position using the "%03d" format 
specifier?  I know, it's a little messy, but valid and portable.

						---Michael Phelps
						   morphine AT cs DOT jhu DOT edu


                               CH3
                               |
                               N
                             / |
                     ______/   |
                    /      \   CH2
             _____/         \__|__      
           //     \\        /  |  \\     
         //        \\______/___CH2 \\  
          \        /       \       /
           \______/         \_____/
          / ------ \       /      \
        OH           \   /         OH
                       O
 
                   Morphine

On Thu, 5 Sep 1996, Thomas Demmer wrote:

> 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