Operating System - OpenVMS
1827807 Members
2337 Online
109969 Solutions
New Discussion

Re: C++ Standard Library IOStreams floating-point problem

 
Steven Schweda
Honored Contributor

C++ Standard Library IOStreams floating-point problem

A different floating-point thread reminded me
of this C++ problem.

According to the HP C++ User's Guide:

http://h71000.www7.hp.com/commercial/cplus/docs/ugv_stl.html#_sec

7.1.7 IOStreams Expects Default Floating-Point Format

The C++ standard library IOStreams expects floating-point values in the
default floating-point format for each platform: G_FLOAT on Alpha
systems and IEEE on I64 systems. Using standard library IOStreams for
processing floating-point values in a different format (for example, in
a program compiled /FLOAT=IEEE on Alpha or /FLOAT=G_FLOAT on I64) is not
supported. The C++ class library does not have this restriction.

Here, "is not supported" is a gentle euphemism
for "doesn't work". The current SETI@home
client, for example, uses IOStreams, and also
expects IEEE floating-point. The restriction
described above makes this impossible on Alpha.

It would be nice if an IEEE edition of this
library were available on Alpha. Any hope?
4 REPLIES 4
Travis Craig
Frequent Advisor

Re: C++ Standard Library IOStreams floating-point problem

Wow, you're right, Steven. Now I'm wondering how we dodged that bullet with all the code we switched to the standard library a couple of years ago. Nothing I can think off off-hand except luck.

Time to search the source again, I guess. I don't know if it broke anything of ours, but I'd vote for an IEEE version of the library, too.

--Travis Craig
My head is cold.
Steven Schweda
Honored Contributor

Re: C++ Standard Library IOStreams floating-point problem

The secret is to avoid doing the wrong
thing(s). The offending SETI@home code
comprises many statements like:

in >> center;

where "in" is a std::istringstream, and
"center" is a double. The use is like atof()
(or atol[l]() for the integers), apparently,
but so much more cute. They use this stuff
to parse the data in a some ".xml" file(s).
Works fine for integers, too, but the
results are nonsense for floating-point
variables, due to the format difference.

The SETI@home code has hundreds of these,
making manual conversion to harmless, old
code more work than I can justify.
Martin Vorlaender
Honored Contributor

Re: C++ Standard Library IOStreams floating-point problem

Steven,

>>>
in >> center;
...
The SETI@home code has hundreds of these,
making manual conversion to harmless, old
code more work than I can justify.
<<<

Perhaps one could subclass IOStreams, overwriting operator>> to do the Right Thing(TM). That way not the uses of "in" et al. would have to be reworked, but just the declarations.

Just an idea...

cu,
Martin
Steven Schweda
Honored Contributor

Re: C++ Standard Library IOStreams floating-point problem

> Perhaps one could subclass IOStreams [...]

As soon as I learn enough C++ to give this
a try, I may give this a try. (Unless
someone who knows something tells me before
then that it's really hopeless.)