M
Mr Fish
Is it possible for me to record floats in a std::stringstream with
100% accuracy? If so how?
Here's a little prog that demonstrates how the default ss loses
accuracy
//-----------------------------------------------------------------------------
#include <sstream>
#include <iostream>
using namespace std;
int main()
{
stringstream ss;
float fOriginal = 0.00000011920928955078125f;
ss << fOriginal;
float fRestored;
ss >> fRestored;
cout << endl << fOriginal;
cout << endl << fRestored;
cout << endl << endl << (fOriginal == fRestored); //should be
equal but are not
cout << endl << fOriginal - fRestored; //there's a diff!
return 0;
}
//-----------------------------------------------------------------------------
100% accuracy? If so how?
Here's a little prog that demonstrates how the default ss loses
accuracy
//-----------------------------------------------------------------------------
#include <sstream>
#include <iostream>
using namespace std;
int main()
{
stringstream ss;
float fOriginal = 0.00000011920928955078125f;
ss << fOriginal;
float fRestored;
ss >> fRestored;
cout << endl << fOriginal;
cout << endl << fRestored;
cout << endl << endl << (fOriginal == fRestored); //should be
equal but are not
cout << endl << fOriginal - fRestored; //there's a diff!
return 0;
}
//-----------------------------------------------------------------------------