Opened 10 years ago

Closed 10 years ago

#6953 closed Bugs (invalid)

Cannot serialialize some double values

Reported by: dbaciu@… Owned by: Robert Ramey
Milestone: To Be Determined Component: serialization
Version: Boost 1.43.0 Severity: Problem
Keywords: serialization Cc:

Description

Hi,

The code sample below throws a "stream error" exception at line

ia >> double_back;

My development environment is Visual Studio 10, boost version 1.43. Sorry, I have not tried a newer version of boost.

The binary archive does not seem to handle doubles with lots of decimal places.

#include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp>

void dummy()

{

string filename = "dummy.data";

double someDouble = 0.98123024735605502;

{

std::ofstream ofs; ofs.open(filename.c_str()); boost::archive::binary_oarchive oa(ofs); oa << someDouble;

}

double double_back; {

std::ifstream ifs; ifs.open(filename.c_str()); boost::archive::binary_iarchive ia(ifs); following throws a "stream error" exception ia >> double_back;

}

}

Thanks,

Dragos

Change History (1)

comment:1 by Robert Ramey, 10 years ago

Resolution: invalid
Status: newclosed

I'm gueesing that is not an issue with the serialization library but rather floating point i/o when converting to text. Rework you example to use just standard stream i/o.

your test case .98123024735605502 has 17 significant decimal digits. This is approximatly 58 binary digits. Which shouldn't be a problem on an 80 bit IEEE754 implementation. But it could be a problem with a 64 bit implementation.

Also, some decimal fractional numbers might not be exactly representable in binary. This would lead to a truncation or rounding when he number is converted to binary. This would only be noticable on output.

I'm pretty sure I'm right here so I'm going to close this ticket.

Robert Ramey

Note: See TracTickets for help on using tickets.