|
Boost : |
From: Paul Giaccone (paulg_at_[hidden])
Date: 2006-03-15 06:06:05
Paul A Bristow wrote:
>If you want to test round-tripping on your platform and std lib without
>actually using serialization,
>
>may I suggest a loop including something like:
>
> double a = some start value;
> double aa; // to hold the read back.
>
> std::stringstream s;
> s.precision(2+std::numeric_limits<double>::digits * 3010/10000);
> // cout << "output " << a;
> s << a; // output to string s
> //cout << ", s.str() is " << s.str();
> s >> aa; // read back in.
> //cout << ", read back " << aa << endl;
> if (a != aa)
> {
> cout << "error " << a << tab << aa << endl;
> }
> a = nextafter(a, std::numeric_limits<double>::max()); // Make one
>bit bigger?
>
>
>
[...]
>This should give you a feel for the risk of failure.
>
>Paul
>
>
Funnily enough, I've just written a program to test the value I
originally posted about (below, followed by its output):
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <limits>
int main(void)
{
const double orig_value = 0.0019075645054089487;
std::stringstream stream;
double num;
stream << std::setprecision(2 + std::numeric_limits<double>::digits
* 3030/10000);
stream << orig_value;
stream >> num;
if (num == orig_value)
{
std::cout << "Match" << std::endl;
}
else
{
std::cout << "Deserialisation error" << std::endl;
std::cout << std::setprecision(2 +
std::numeric_limits<double>::digits * 3030/10000);
std::cout << "Original numerical value: " << orig_value <<
std::endl;
std::cout << "Contents of stream: " << stream.str() << std::endl;
std::cout << "Deserialised value: " << num << std::endl;
}
return 0;
}
Output:
Deserialisation error
Original numerical value: 0.0019075645054089487
Contents of stream: 0.0019075645054089487
Deserialised value: 0.0019075645054089489
This is the same result as in my original thread, so it does indeed look
like a Microsoft issue with redirection (>>), not with serialisation itself.
Paul
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk