Boost logo

Boost :

From: Johan Råde (rade_at_[hidden])
Date: 2006-08-03 04:53:37


I have uploaded a new version to the vault.

This version features:

1. Strict C99 conformance:
        Output is consistent with C99. (In particular, negative NaN is
written as "-nan".
        All representations allowed by C99 are recognized as input.

2. Optional support for negative 0.

3. Clean build with VC++ 7.1 at warning level 4.

4. Improved documentation.

This version is backwards compatible with earlier versions.

The code comes with a test program. I have only run the test program on
VC++ 7.1.
If you run the test program on any other platform, please report the
result to me.
Both good and bad results are of interest.

Many thanks to Paul Bristow, John Maddock and Gennaro Prota for valauble
comments.

--Johan Råde

Johan Råde wrote:
> ----- The Problem -----
>
> The C++98 standard does not specify how non-finite floating point
> numbers,
> such as infinity and not-a-number, should be represented in text streams.
> As a result, different platforms use different representations.
> This can cause undefined behavior when text files and serialization
> archives
> are moved between different platforms.
>
> Some platforms can not even read their own output!
> For instance, the following test fails with VC++ 7.1:
>
> stringstream s;
> double x = numeric_limits<double>::infinity();
> double y;
> ss << x;
> ss >> y;
> assert(x == y);
>
>
> ----- The Solution -----
>
> The facets extended_num_put and extended_num_get
> write and read non-finite floating point numbers
> to text streams in a consistent and portable manner.
>
> The following test succeeds with VC++ 7.1:
>
> 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);
>
>
>


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