Boost logo

Boost :

From: Johan Råde (rade_at_[hidden])
Date: 2006-07-24 10:49:49


At the suggestion of Robert Ramey's, I have put together facets for
reading and writing non-finite numbers, such as infinity and
not-a-number, to text streams, in a consistent and portable way.

The code, with documentation and tests, is available in the Boost Vault,
serialization/non_finite_num_facets.zip.

If there is enough interest in the code, I will submit it for a
mini-review, in order to have it added to the serialization lib.

---------------------------------------------

What does the code do?

The following test fails on VC++ 7.1:

     stringstream s;
     double x = numeric_limits<double>::infinity();
     double y;
     ss << x;
     ss >> y;
     assert(x == y);

The situation gets even worse when text files are required to
be portable between different platforms.

But the following test succeeds:

     stringstream s;

     locale old_locale;
     locale tmp_locale(old_locale, new extended_num_put<char>);
     locale new_locale(tmp_locale, new extended_num_get<char>);
     s.imbue(new_locale);

     double x = numeric_limits<double>::infinity();
     double y;
     ss << x;
     ss >> y;
     assert(x == y);

For more info, read the documentation.

------------------------------------------------------------

--Johan Råde


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk