Convert from string to double with number greater than std :: numeric_limit <double> :: digits10

std::string str = "12345679012.124678"; double back = boost::lexical_cast<double>( str ); std::string str2 =boost::lexical_cast<std::string>( back ); //here str2 is equal to str 

Is it normal that there are no losses (for example, the final string = orignal string), even if the number of significant digits is greater than std::numeric_limit<double>::digits10 (i.e. 15)?

+4
source share
1 answer

Yes, it is normal.

std::numeric_limit<double>::digits10 refers to the maximum number of digits where casting is guaranteed without loss.

This does not imply loss using wider numbers than the limit, it only means an increasing probability of loss.

0
source

Source: https://habr.com/ru/post/1442770/


All Articles