Boost logo

Boost :

Subject: [boost] [multiprecision] Are these types suitable as numeric types for unit tests?
From: Daryle Walker (darylew_at_[hidden])
Date: 2013-06-08 02:57:47


I'm writing new numeric types, and my unit tests use MPL lists of numeric types. I usually use stuff like int, unsigned, and double, but now I'm adding cpp_int and cpp_dec_float_50. Those types were OK when I was just doing type equalities and sizeof checks. Now I'm doing tests that use objects of those types and I'm getting problems.

//====
typedef boost::mpl::list<int, unsigned, cpp_int> test_integer_types;
typedef boost::mpl::list<double, cpp_dec_float_50> test_floating_types;

//...

BOOST_AUTO_TEST_CASE_TEMPLATE( test_complex_component_access1, T,
 test_integer_types )
{
    typedef complex_it<T, 0> real_type;
    typedef complex_it<T, 1> complex_type;

    real_type a;
    real_type const & aa = a;
    complex_type b;
    complex_type const & bb = b;

    a[ 0 ] = 6;
    BOOST_CHECK_EQUAL( a[0], T(6) );
    BOOST_CHECK_EQUAL( T(6), aa[0] );

    b[ 0 ] = 5;
    b[ 1 ] = 7;
    BOOST_CHECK_EQUAL( b[0], T(5) );
    BOOST_CHECK_EQUAL( T(5), bb[0] );
    BOOST_CHECK_EQUAL( b[1], T(7) );
    BOOST_CHECK_EQUAL( T(7), bb[1] );
}
//====

I'm getting warnings about integer overflow. The problem is at Line 59 of boost/test/tools/detail/print_helper.hpp. It sets an output stream's precision based on the digits given by std::numeric_limits.

//====
BOOST_AUTO_TEST_CASE_TEMPLATE( test_complex_component_access2, T,
 test_floating_types )
{
    typedef complex_it<T, 0> real_type;
    typedef complex_it<T, 1> complex_type;

    real_type a;
    real_type const & aa = a;
    complex_type b;
    complex_type const & bb = b;

    a[ 0 ] = 6.0;
    BOOST_CHECK_CLOSE( a[0], T(6.0), 0.1 );
    BOOST_CHECK_CLOSE( T(6.0), aa[0], 0.1 );

    b[ 0 ] = 5.5;
    b[ 1 ] = -7.0;
    BOOST_CHECK_CLOSE( b[0], T(5.5), 0.1 );
    BOOST_CHECK_CLOSE( T(5.5), bb[0], 0.1 );
    BOOST_CHECK_CLOSE( b[1], T(-7.0), 0.1 );
    BOOST_CHECK_CLOSE( T(-7.0), bb[1], 0.1 );
}
//====

This time it's an error, at Line 59 of boost/test/tools/floating_point_comparison.hpp. There no (close enough) matching function for "fpt_abs" from some "boost::multiprecision::detail::expression<..." type. (It was truncated by the display. I don't know how to get a clean print-out of errors from Code::Blocks.) I'm guessing the expression template setup is screwing things up.

Daryle W.


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