This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent
- From: "kreckel at ginac dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Jun 2007 14:15:47 -0000
- Subject: [Bug libstdc++/32422] New: Problem reading floats with exponent marker but no exponent
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When reading malformed floats like "3.14e" using operator>>, it appears like
the e character is removed from the input stream but the fact that the stream
state does not signal that something went wrong.
$ cat lcast.cpp
#include <sstream>
#include <iostream>
using namespace std;
int main()
{
stringstream buf;
buf.str("1e");
float r;
buf >> r;
cout << "float==" << r << endl;
cout << "tellg()==" << buf.tellg() << endl;
cout << "fail()==" << buf.fail() << endl;
}
$ g++ lcast.cpp && ./a.out
float==1
tellg()==2
fail()==0
This was noticed in the context of the boost library. There,
boost::lexical_cast<float>("1e") silently return 1.0, which is surprising. E.g.
a compiler would reject float x = 1e saying "exponent has no digits" or
something along these lines.
--
Summary: Problem reading floats with exponent marker but no
exponent
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kreckel at ginac dot de
GCC build triplet: x86_64-suse-linux
GCC host triplet: x86_64-suse-linux
GCC target triplet: x86_64-suse-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32422