Boost logo

Boost Users :

From: Rozental, Gennadiy (gennadiy.rozental_at_[hidden])
Date: 2004-05-27 15:19:53


> I was testing out lexical_cast, and I would expect that for
> any value v of type T, it should be true that
>
> v == lexical_cast<T>(lexical_cast<string>(v))
>
> but this does not appear to work for float or double in all
> cases. In particular, the following tests failed:
>
> float value = numeric_values<float>::min();
> BOOST_CHECK_EQUAL(value,
> lexical_cast<float>(lexical_cast<string>(value)));
> value = numeric_values<float>::max();
> BOOST_CHECK_EQUAL(value,
> lexical_cast<float>(lexical_cast<string>(value)));
>
> double dvalue = numeric_values<double>::min();
> BOOST_CHECK_EQUAL(dvalue,
> lexical_cast<double>(lexical_cast<string>(dvalue)));
> dvalue = numeric_values<double>::max();
> BOOST_CHECK_EQUAL(dvalue,
> lexical_cast<double>(lexical_cast<string>(dvalue)));
>
> Should I have expected these tests to pass?
>
> thanks,
>
> --chris

Try to use BOOST_CHECK_CLOSE instead. Don't use BOOST_CHECK_EQUAL to compare
floats.

Gennadiy.


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