The following assertion fails in RAD Studio 2010 (and incidentally would succeed in Visual Studio 2010):
double d1 = 0.0104;
double d2 = 0.0;
std::istringstream ss("0.0104");
ss >> d2;
assert(d1 == d2);
This surprised me a little. I traced down into the extraction operator to see what was happening, got as far as dinkumware/xlocnum, and couldn’t trace any further.
Can anyone tell me why __Stodx(... "0.0104") returns a value that’s marginally different from a double initialized to 0.0104?
(I know that certain values can’t be represented exactly in binary. What I want to know is why the resultant doubles contain different values so that I can understand it.)
Thanks!
Dear Me: The compiler and library use different methods to convert strings to doubles, and without access to the compiler source, nobody is going to be able to tell you how those methods differ.
Sorry,
Me