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_caststd::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_caststd::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@teraview.com mailto:Laurence.Bunnage@teraview.com 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
If you want attention, it's always a good idea to put the library name
in the subject line. Cheers,
on Mon Nov 26 2007, "Laurence Bunnage"
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_caststd::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_caststd::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@teraview.com
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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Dave Abrahams Boost Consulting http://www.boost-consulting.com
David Abrahams
If you want attention, it's always a good idea to put the library name in the subject line. Cheers,
I replied to the post using gmane interface but I wasn't subscribed to the list and my reply didn't get through. Laurence, please try boost-trunk first (download instruction can be found at svn.boost.org). If you can't use svn, either download trunk.tar.bz2 by clicking on http://beta.boost.org/development/snapshot.php/trunk or copy boost/detail/lcast_precision.hpp and boost/lexical_cast.hpp to your local copy of boost (don't forget to backup a previous version of lexical_cast.hpp). Precision setting has changed a lot since 1.34. -- Alexander
Hi Alexander
Using the latest version of lexical_cast (and lcast_precision.hpp)
hasn't made any difference. The code still misbehaves.
I have found a culprit, in terms of a function that when removed does
cure the problem. At the top of the main function, before the test
snippet, I had a call to _Control87(MCW_EM,MCW_EM). Moving the code
snippet before this call makes the code work correctly.
Now comes the rub. My software runs on a system which uses the NI-DAQmx
ANSI C Function Library. In their documentation they state that the
_Control87(MCW_EM,MCW_EM) statement is required to stop their libraries
crashing when compiled with Borland C and Delphi. They claim to have
fixed this issue in later versions of their libraries. Unfortunately,
most of our systems in the field are using an earlier version so
upgrading the library and removing the offending statement is not
possible. Brickwall meet head.
Laurence Bunnage
Software Engineer
e-mail: Laurence.Bunnage@teraview.com
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
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Alexander
Nasonov
Sent: 28 November 2007 17:29
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [lexical cast] suspected bug
David Abrahams
If you want attention, it's always a good idea to put the library name in the subject line. Cheers,
I replied to the post using gmane interface but I wasn't subscribed to the list and my reply didn't get through. Laurence, please try boost-trunk first (download instruction can be found at svn.boost.org). If you can't use svn, either download trunk.tar.bz2 by clicking on http://beta.boost.org/development/snapshot.php/trunk or copy boost/detail/lcast_precision.hpp and boost/lexical_cast.hpp to your local copy of boost (don't forget to backup a previous version of lexical_cast.hpp). Precision setting has changed a lot since 1.34. -- Alexander _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Alexander Nasonov
-
David Abrahams
-
Laurence Bunnage