Boost logo

Boost Users :

From: Arnstein Ressem (aressem_at_[hidden])
Date: 2007-08-10 04:55:41


Hi,

I have run into a problem with the boost xml serialization of
overflowing floats. On Linux these are being serialized as 'inf' into
the xml files, but when reading the float back in it results in stream
errors. I have searched the archives to find an answer to this, but
without luck. The small program below has been compiled and run on
32-bit and 64-bit Linux (RedHat Enterprise Linux 4) with boost 1.33.1
and 1.34.1. In every case it results in a stream error and the float can
not be read back in from the xml file.

Does anyone know if this is supposed to work ?

#include <fstream>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>

int main()
{
   const char fname[] = "float.xml";

   float f = 1.0e+20*1.0e+20;

   {
     std::ofstream ofs(fname);
     assert(ofs.good());
     boost::archive::xml_oarchive oa(ofs);
     oa << BOOST_SERIALIZATION_NVP(f);
   }

   {
     std::ifstream ifs(fname);
     assert(ifs.good());
     boost::archive::xml_iarchive ia(ifs);
     ia >> BOOST_SERIALIZATION_NVP(f);
   }

   return 0;
}

Best regards,
Arnstein Ressem


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