|
Boost Users : |
From: Laurence Bunnage (Laurence.Bunnage_at_[hidden])
Date: 2007-11-26 06:39:19
I am currently maintaining a project written using Borland C++ Builder
version 6 build 10.166 and boost version 1.32.
I found I had a reoccuring problem in my code whereby the output from
lexical_cast<string>(any_double) was not at the precision I was
expecting. It started off OK, but after a while it changed. I have
tracked it down to some of my code which I simplified to that shown
below.
The first cast, in the try block, works correctly with the output value
d = 5.0 and no assert
The second cast, in the catch statement, returns a value of d =
5.00000013628211 and asserts.
With the assert removed, all subsequent calls to lexical_cast continue
to give similar results.
try
{
double d =
boost::lexical_cast<double>(boost::lexical_cast<std::string>(5.0));
assert(d == 5.0);
throw std::runtime_error("Not enough points in peak");
}
catch (std::exception& e)
{
double d =
boost::lexical_cast<double>(boost::lexical_cast<std::string>(5.0));
assert(d == 5.0);
}
I have searched the boost website for similar problems and have not
found anything (doesn't mean it's not there, just I haven't found it)
Any help, especially a solution or work around would be greatly
appreciated.
NOTE at this time, due to the current state of the project, I would
prefer not to have to upgrade to a newer version of the boost library.
Laurence Bunnage
Software Engineer
e-mail: Laurence.Bunnage_at_[hidden]
<mailto:Laurence.Bunnage_at_[hidden]>
TeraView Limited
Registered in England
Registered Office: Platinum Building, St John's Innovation Park,
Cambridge CB4 0WS
Registered Number: 04126946
VAT Number: 770 8883 84
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