I have a puzzling error on my hands. I am sure this code worked fine in an earlier version of boost, now (boost 1.72.0) it chucks an exception:
string problemStr = "1.03964e-312";
double problemChild = boost::lexical_cast<double>(problemStr);
Setting a breakpoint in boost's code:
namespace boost
{
template <typename Target, typename Source>
inline Target lexical_cast(const Source &arg)
{
Target result = Target();
if (!boost::conversion::detail::try_lexical_convert(arg, result)) {
boost::conversion::detail::throw_bad_cast<Source, Target>();
}
return result;
}
at the line boost::conversion::detail::throw_bad_cast<Source, Target>();
reveals, that while the value is actually converted to double (result=1.0396399999979624E-312) the test boost::conversion::detail::try_lexical_convert(arg, result)
failed! This then results in the exception:
boost::wrapexcept<boost::bad_lexical_cast>: bad lexical cast: source type value could not be interpreted as target
I'm confused. It seems to do the conversion but still throws the exception? What am I overlooking? Or is this actually a bug?