Boost logo

Boost :

From: Johan Råde (rade_at_[hidden])
Date: 2006-07-25 12:54:20


Johan Råde wrote:
> 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
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>

I have uploaded a revised version with a more robust is_nan function.
The code is in the vault: serialization/non_finite_num_facets.zip.

--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