I think I've found a bug in the boost::lexical_cast<>
library (v1.31.0) on WinXP SP1, MSVC 6.0 (sp5) and
MSVC.NET 2003.
--- Start code snippet ---
#include
Well, this is a long time ago, but I came across this posting when doing a search for lexical_cast related issues. I compiled and ran the code snipped below on Intel C++ 7.1 and STLPort, and it printed "Successfuly", while it fails on MSVC 7.1 and g++ 3.2, so it seems to depend on the platform/library used. If anyone has a patch for it, it would be welcome, but otherwise, this seems to be quite a boundary condition (converting numeric_limit<double>::max() to string and back again), that I'd think it's rarely, if ever, a problem in practice. Regards, Terje
From: "Leon Raj"
To: Cc: "Leon Raj" Sent: Wednesday, July 28, 2004 5:21 AM Subject: [Boost-users] Bug in lexical_cast<> with doubles
I think I've found a bug in the boost::lexical_cast<> library (v1.31.0) on WinXP SP1, MSVC 6.0 (sp5) and MSVC.NET 2003.
--- Start code snippet ---
#include
#include <iostream> int main( int argc, char* argv[] ) { double dMax = = std::numeric_limits< double >::max(); // On a Win32 x86 system, dMax is now 1.7976931348623157e+308
// This is successful and strMax is "1.797693134862316e+308" std::string strMax = boost::lexical_cast< std::string >( dMax );
try { double newDMax = boost::lexical_cast< double >( strMax ); std::cout << "Successfuly" << std::endl; } catch ( boost::bad_lexical_cast& ) { std::cout << "Failed to cast" << std::endl; }
// On a Win32 x86 system, this always fails, // because (I think) strMax overflows a double, // because 1.7976931348623157e+308 is *rounded UP* // to 1.797693134862316e+308, which cannot be // represented by a double }
--- End code snippet ---
participants (2)
-
Leon Raj
-
Terje Slettebø