Boost logo

Boost :

Subject: Re: [boost] [multiprecision] Are these types suitable as numeric types for unit tests?
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2013-06-08 04:45:24


> -----Original Message-----
> From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Daryle Walker
> Sent: Saturday, June 08, 2013 7:58 AM
> To: Boost Dev-List
> Subject: [boost] [multiprecision] Are these types suitable as numeric types for unit tests?
>
> 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.

I suspect you are right. I hit what looks like similar difficulties and provided an example

https://svn.boost.org/trac/boost/changeset/82914

I added an example

\boost-trunk\libs\math\example\test_cpp_float_close_fraction.cpp

I suggest you use a type like this with expression templates switched off and see if that 'cures'
the problem.

This will at least pinpoint the problem?

Long term it may be possible to change Boost.Test to make this work but our maintainer is rarely
seen in action ;-)

Paul

PS I found I liked NetBeans much more than CodeBlocks. https://netbeans.org/

PPS Note to self - Boost.Math index does not have an entry for expression template switching, making
it difficult to find in the docs.

---
Paul A. Bristow,
Prizet Farmhouse, Kendal LA8 8AB  UK
+44 1539 561830  07714330204
pbristow_at_[hidden]
Added example of switching expression templates off and using Boost.Test BOOST_CHECK_CLOSE_FRACTION
macros.

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