Boost logo

Boost Users :

Subject: [Boost-users] Is this a known bug in lexical_cast<double> ?
From: TILLMAN, MICHAEL D9 (michael.d9.tillman_at_[hidden])
Date: 2015-07-13 13:26:09


We're using boost 1.51. Management is reluctant to upgrade because the software is for manned space flight and our current boost version has been stable.

Wanted to see if there was a known bug with boost::lexical_cast<double>. We're seeing failures on what appear to be valid float strings. When we catch the exception, and simply do a second cast on the same string, the cast succeeds. The Code fragment:

  try { dVal = boost::lexical_cast<double>(theValue); }
  catch(boost::bad_lexical_cast &eX)
  {
    ... more code ...
    firstAttemptFailed = true;
  }

  // If the first cast succeeded, don't bother to attempt it again.
  if(firstAttemptFailed == true)
  {
    // Let the API throw the actual exception if the second attempt also fails.
    dVal = boost::lexical_cast<double>(theValue);
  }

The string sequence this fails on is:
...
...
"7104",
"0.416666699999999999983",
"0.22222224",
"4.08233160000000000001",
"1.81436960000000000002",
...
...

It fails on the last string, "1.81.....", in the actual program, but when compiled into a simple test program, it succeeds.

If there is a known bug, we may be able to get a Boost upgrade installed.

Thanks,
Mike



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net