This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: scanf() (>>) can't read what printf() (zz) produced: NaNs and Inf


Joe Buck wrote:
> 
> > printf() generate special tokens when outputing float/doubles that are
> > not numbers (NaN) or are infinity (Inf).
> > However, scanf() can't read those tokens. Is this deliberate?
> 
> You sent this to the egcs list, but egcs does not provide printf and
> scanf.  You'll need to talk to whoever provides your C library (if you run
> Linux and it is GNU libc, they have their own bug list
> (bug-glibc@gnu.org).

Perhaps you are right, but in libio/floatconv.c of the egcs distribution
are provisions for dealing with NaN and Inf, perhaps because of '<<' and
'>>' when applied to float/doubles.

Perhaps I should send the query to the libstdc++ maintainers?

Thanks,
Joao

#include <strstream.h>

main(){
        double f=1./0., g=0./0., h, l;
        char buf[100];

        ostrstream os(buf,100);
        istrstream is(buf,100);

        cout << f << " " << g << '\n';
        os << f << g << '\0';
        
        is >> h >> l;;
        cout << h << " " << l << '\n';
}

./po
Infinity -NaN
8.59409e-313 -1.01297e-309

-- 
Joao Cardoso, INESC  |  e-mail: jcardoso@inescn.pt
R. Jose Falcao 110   |  tel:    + 351 2 2094345
4050 Porto, Portugal |  fax:    + 351 2 2008487


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]