Ticket #791 (closed defect: wontfix)

Opened 10 years ago

Last modified 9 years ago

Boost serialization of NaN causes failures on retrieval

Reported by: ktl Owned by: ktl
Priority: normal Milestone:
Component: daf_persistence Keywords:
Cc: Blocked By:
Blocking: Project: LSST
Version Number:
How to repeat:
#include "boost/serialization/serialization.hpp"
#include "boost/archive/text_oarchive.hpp"
#include "boost/archive/text_iarchive.hpp"
#include <iostream>
#include <fstream>

struct Foo {
    Foo(void) : _x(0.0), _y(0.0) { };
    void set(void) { _x = 1.0 / 0.0; _x = _x - _x; _y = 3.14159; };
    template <class Archive>
    void serialize(Archive& ar, unsigned int const version) {
        ar & _x; ar & _y;
    };
    friend class boost::serialization::access;
    double _x;
    double _y;
};
int main(void) {
    {
        Foo f;
        std::cerr << "f == " << f._x << "," << f._y << std::endl;
        f.set();
        std::cerr << "f == " << f._x << "," << f._y << std::endl;
        std::ofstream out("/tmp/foo.boost");
        boost::archive::text_oarchive outAr(out);
        outAr & f;
    }
    {
        Foo f;
        std::cerr << "f == " << f._x << "," << f._y << std::endl;
        std::ifstream in("/tmp/foo.boost");
        boost::archive::text_iarchive inAr(in);
        inAr & f;
        std::cerr << "f == " << f._x << "," << f._y << std::endl;
    }
    return 0;
}

Description

Serializing a NaN through boost::serialization to a text archive produces the string "nan" in the output. Attempting to deserialize the resulting file causes a "stream error" at this point.

Possible fixes:

  • Never generate NaNs.
  • Convert all NaNs to something else before serializing them. Messy, because virtually any floating point variable could be a NaN.
  • Fix boost::serialization to round-trip NaNs.

Change History

comment:1 Changed 10 years ago by ktl

  • Status changed from new to deferred

For now, we will try not to generate NaNs.

comment:2 Changed 9 years ago by ktl

  • Status changed from deferred to closed
  • Resolution set to wontfix

Source output has been changed to have a flag indicating whether the associated value is nan. This is a temporary solution until g++ is able to retrieve nans from a stream.

Note: See TracTickets for help on using tickets.