Boost logo

Boost :

From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2006-03-15 17:42:38


Paul A Bristow said: (by the date of Wed, 15 Mar 2006 20:15:10 -0000)

>
> std::stringstream stream;
> double num;
> stream << std::setprecision(3 +
> std::numeric_limits<double>::digits * 3030/10000);
> stream << orig_value;
> stream >> num; // <<<<<<<<<< This is where I believe it
> goes wrong, sometimes, by one 1 bit :-((
>
> so orig_value != num.
>

try following modifications in above code. If you still get a mistake by
one bit, then .... well, I'd be very surprised.

#include <boost/lexical_cast.hpp>

        std::stringstream stream;
        double num;
        stream << boost::lexical_cast<std::string>(orig_value);
        std::string tmp;
        stream >> tmp;
        num=boost::lexical_cast<double>(tmp);

-- 
Janek Kozicki                                                         |

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk