|
Boost Users : |
From: Terje Slettebų (tslettebo_at_[hidden])
Date: 2005-01-29 16:50:07
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" <Leon.Raj_at_[hidden]>
>To: <boost-users_at_[hidden]>
>Cc: "Leon Raj" <Leon.Raj_at_[hidden]>
>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 <boost/lexical_cast.hpp>
> #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 ---
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