This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: scanf() (>>) can't read what printf() (zz) produced: NaNs and Inf
- To: Joe Buck <jbuck at Synopsys dot COM>
- Subject: Re: scanf() (>>) can't read what printf() (zz) produced: NaNs and Inf
- From: Joao Cardoso <jcardoso at inescn dot pt>
- Date: Tue, 30 Mar 1999 01:09:36 +0100
- CC: egcs at egcs dot cygnus dot com, mrs at wrs dot com
- Organization: INESC
- References: <199903292052.MAA06164@atrus.synopsys.com>
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