Boost logo

Boost Users :

From: Peter Sliepenbeek (peter_sliepenbeek_at_[hidden])
Date: 2007-10-05 08:35:00


Hi all,

The test below fails:

#include <iostream>

#include <boost/lexical_cast.hpp>

int main(int argc, char* argv[])
{
    std::string s;

    try
    {
        double d = std::numeric_limits <double> ::max();
        s = boost::lexical_cast <std::string> (d);
    }

    catch (const boost::bad_lexical_cast&)
    {
        std::cout << "double to std::string fails" << std::endl;
    }

    try
    {
        double dd = boost::lexical_cast <double> (s);
    }

    catch (const boost::bad_lexical_cast&)
    {
        std::cout << "std::string to double fails" << std::endl;
    }

    return 0;
}

To solve this issue I propose to alter the line "stream.precision(std::numeric_limits<Target>::digits10 + 1" in the constructor for lexical_stream into "stream.precision(std::numeric_limits<Target>::digits10 - 1".

Regards,

P. Sliepenbeek

       
---------------------------------
Be a better Heartthrob. Get better relationship answers from someone who knows.
Yahoo! Answers - Check it out.



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