Boost logo

Boost Users :

Subject: Re: [Boost-users] Is this a known bug in lexical_cast<double> ?
From: Jeff Flinn (jeffrey.flinn_at_[hidden])
Date: 2015-07-15 18:35:39


On 7/13/15 1:26 PM, TILLMAN, MICHAEL D9 wrote:
> 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.

I don't know whether there are known bugs in lexical_cast, but I'd be
more suspicious of theValue's actual value. What is it's type, lifetime,
etc.

Jeff


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