forked from boostorg/conversion
round conversion of floating point types: T -> std::string -> T
[SVN r35595]
This commit is contained in:
@@ -67,6 +67,9 @@ void test_conversion_from_ulong();
|
|||||||
void test_conversion_from_longlong();
|
void test_conversion_from_longlong();
|
||||||
void test_conversion_from_ulonglong();
|
void test_conversion_from_ulonglong();
|
||||||
#endif
|
#endif
|
||||||
|
void test_round_conversion_float();
|
||||||
|
void test_round_conversion_double();
|
||||||
|
void test_round_conversion_long_double();
|
||||||
|
|
||||||
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
unit_test::test_suite *init_unit_test_suite(int, char *[])
|
||||||
{
|
{
|
||||||
@@ -97,6 +100,8 @@ unit_test::test_suite *init_unit_test_suite(int, char *[])
|
|||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_longlong));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_longlong));
|
||||||
suite->add(BOOST_TEST_CASE(&test_conversion_from_ulonglong));
|
suite->add(BOOST_TEST_CASE(&test_conversion_from_ulonglong));
|
||||||
#endif
|
#endif
|
||||||
|
suite->add(BOOST_TEST_CASE(&test_round_conversion_float));
|
||||||
|
suite->add(BOOST_TEST_CASE(&test_round_conversion_double));
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
@@ -606,3 +611,42 @@ void test_conversion_from_ulonglong()
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void test_round_conversion()
|
||||||
|
{
|
||||||
|
T v1 = std::numeric_limits<T>::epsilon();
|
||||||
|
std::string s1 = boost::lexical_cast<std::string>(v1);
|
||||||
|
BOOST_CHECK(v1 == lexical_cast<T>(s1));
|
||||||
|
|
||||||
|
T v2 = (std::numeric_limits<T>::max)();
|
||||||
|
std::string s2 = boost::lexical_cast<std::string>(v2);
|
||||||
|
BOOST_CHECK(v2 == lexical_cast<T>(s2));
|
||||||
|
|
||||||
|
T v3 = (std::numeric_limits<T>::min)();
|
||||||
|
std::string s3 = boost::lexical_cast<std::string>(v3);
|
||||||
|
BOOST_CHECK(v3 == lexical_cast<T>(s3));
|
||||||
|
|
||||||
|
T v4 = v2 / 137;
|
||||||
|
std::string s4 = boost::lexical_cast<std::string>(v4);
|
||||||
|
BOOST_CHECK(v4 == lexical_cast<T>(s4));
|
||||||
|
|
||||||
|
T v5 = v1 * 137;
|
||||||
|
std::string s5 = boost::lexical_cast<std::string>(v5);
|
||||||
|
BOOST_CHECK(v5 == lexical_cast<T>(s5));
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_round_conversion_float()
|
||||||
|
{
|
||||||
|
test_round_conversion<float>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_round_conversion_double()
|
||||||
|
{
|
||||||
|
test_round_conversion<double>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_round_conversion_long_double()
|
||||||
|
{
|
||||||
|
test_round_conversion<long double>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user