I have no problem converting “normal” double values, but I can’t convert numeric_limits<double>::max() or DBL_MAX string representations?
std::string max = "1.79769313486232e+308";
std::istringstream stream(max);
double value;
// enters here, failbit is set
if (!(stream >> value))
Could it be something like the actual value of
DBL_MAXisn’t exactly representable in exponential notation with 16 decimal places (say the decimal value is very slightly larger than the two based represenation) but initializing adoublewith theDBL_MAXwill nevertheless set the correct value (due to rounding).std::istringstreammay be a little bit more pickish.EDIT: Actually I found that the value of
DBL_MAXin my compiler is 1.7976931348623158e+308 which works fine for me to stream. Your number is rounded and slightly larger, hence the failure.EDIT2: The exact value of
DBL_MAXin decimal form is given by(2 ^ (1023 - 52)) * (2 ^ 53 - 1)which isn’t representable with 16 decimal places.