Boost logo

Boost Users :

From: Johan Råde (rade_at_[hidden])
Date: 2006-07-04 09:31:26


I just replaced the binary archives by text archives in an app,
to make sure that the archives will be portable between 32 and 64 bit
platforms.
But when I use text archives, the app crashes.
The problem is:

Text archives do not handle infinite values of type float and double.

--- Example ----------------------------------------------------------

#include <iostream>
#include <limits>
#include <sstream>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/format.hpp>

int main()
{
     std::stringstream ss;

     {
         boost::archive::text_oarchive oa(ss);
         double inf1 = std::numeric_limits<double>::infinity();
         std::cout << boost::format("Save: %1%\n") % inf1;
         oa << inf1;
     }

     {
         boost::archive::text_iarchive ia(ss);
         double inf2;
         ia >> inf2;
         std::cout << boost::format("Load: %1%\n") % inf2;
     }
}

--- Output ----------------------------------------------------------

Save: 1.#INF
Load: 1

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

There are two infinite values of type double,
     std::numeric_limits<double>::infinity()
and
     -std::numeric_limits<double>::infinity().
These could be represented as "inf" and "-inf" in the archive.

I would be very useful for me if this functionality
were added to the serialization library.
(Otherwise I will have to do a lot of code rewriting,
or stick binary archives.)

One could also consider handling nan (not a number),
but that is maybe a lower priority.

--Johan Råde

rade_at_[hidden]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net