Boost C++ Libraries: Ticket #8272: BOOST_REQUIRE_CLOSE fails to compile with boost::multiprecision::cpp_dec_float_100 https://svn.boost.org/trac10/ticket/8272 <p> Environment: </p> <ul><li>Linux 3.7.9-2-ARCH </li><li>G++ 4.7.2 </li><li>Issue reproduces with Boost SVN trunk </li></ul><p> This code: </p> <pre class="wiki">#define BOOST_TEST_MAIN #include &lt;boost/test/included/unit_test.hpp&gt; #include &lt;boost/test/floating_point_comparison.hpp&gt; #include &lt;boost/multiprecision/cpp_dec_float.hpp&gt; BOOST_AUTO_TEST_CASE(multiprecision_closeness) { using num_t = boost::multiprecision::cpp_dec_float_100; num_t a("1.0000000000000000000000000000001"); num_t b(1); num_t thresh(1e-15); BOOST_REQUIRE_CLOSE(a, b, thresh); } </pre><p> Generates the following compilation error: </p> <pre class="wiki">g++ -std=gnu++11 -g -Iboost-trunk -o prog repro.cpp In file included from boost-trunk/boost/test/tools/old/impl.hpp:21:0, from boost-trunk/boost/test/test_tools.hpp:32, from boost-trunk/boost/test/impl/exception_safety.ipp:35, from boost-trunk/boost/test/included/unit_test.hpp:22, from repro.cpp:2: boost-trunk/boost/test/tools/floating_point_comparison.hpp: In instantiation of ‘FPT boost::math::fpc::fpc_detail::fpt_abs(FPT) [with FPT = boost::multiprecision::detail::expression&lt;boost::multiprecision::detail::subtract_immediates, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, void, void&gt;]’: boost-trunk/boost/test/tools/floating_point_comparison.hpp:207:67: required from ‘bool boost::math::fpc::close_at_tolerance&lt;FPT&gt;::operator()(FPT, FPT) const [with FPT = boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;]’ boost-trunk/boost/test/tools/old/impl.hpp:292:50: required from ‘boost::test_tools::assertion_result boost::test_tools::check_is_close_t::operator()(FPT1, FPT2, ToleranceType) const [with FPT1 = boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;; FPT2 = boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;; ToleranceType = boost::math::fpc::percent_tolerance_t&lt;boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt; &gt;]’ boost-trunk/boost/test/tools/old/impl.hpp:91:1: required from ‘bool boost::test_tools::tt_detail::check_frwd(Pred, const boost::unit_test::lazy_ostream&amp;, boost::unit_test::const_string, std::size_t, boost::test_tools::tt_detail::tool_level, boost::test_tools::tt_detail::check_type, const Arg0&amp;, const char*, const Arg1&amp;, const char*, const Arg2&amp;, const char*) [with Pred = boost::test_tools::check_is_close_t; Arg0 = boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;; Arg1 = boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;; Arg2 = boost::math::fpc::percent_tolerance_t&lt;boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt; &gt;; boost::unit_test::const_string = boost::unit_test::basic_cstring&lt;const char&gt;; std::size_t = long unsigned int]’ repro.cpp:14:1: required from here boost-trunk/boost/test/tools/floating_point_comparison.hpp:59:47: error: no matching function for call to ‘boost::multiprecision::detail::expression&lt;boost::multiprecision::detail::subtract_immediates, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, void, void&gt;::expression(int)’ boost-trunk/boost/test/tools/floating_point_comparison.hpp:59:47: note: candidates are: In file included from boost-trunk/boost/multiprecision/detail/default_ops.hpp:10:0, from boost-trunk/boost/multiprecision/detail/generic_interconvert.hpp:9, from boost-trunk/boost/multiprecision/number.hpp:22, from boost-trunk/boost/multiprecision/cpp_dec_float.hpp:28, from repro.cpp:4: boost-trunk/boost/multiprecision/detail/number_base.hpp:379:4: note: boost::multiprecision::detail::expression&lt;tag, Arg1, Arg2, void, void&gt;::expression(const Arg1&amp;, const Arg2&amp;) [with tag = boost::multiprecision::detail::subtract_immediates; Arg1 = boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;; Arg2 = boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;] boost-trunk/boost/multiprecision/detail/number_base.hpp:379:4: note: candidate expects 2 arguments, 1 provided boost-trunk/boost/multiprecision/detail/number_base.hpp:369:8: note: constexpr boost::multiprecision::detail::expression&lt;boost::multiprecision::detail::subtract_immediates, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, void, void&gt;::expression(const boost::multiprecision::detail::expression&lt;boost::multiprecision::detail::subtract_immediates, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, void, void&gt;&amp;) boost-trunk/boost/multiprecision/detail/number_base.hpp:369:8: note: no known conversion for argument 1 from ‘int’ to ‘const boost::multiprecision::detail::expression&lt;boost::multiprecision::detail::subtract_immediates, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, boost::multiprecision::number&lt;boost::multiprecision::backends::cpp_dec_float&lt;100u&gt; &gt;, void, void&gt;&amp;’ make: *** [prog] Error 1 </pre><p> At line 59 of floating_point_comparison.hpp, FPT appears to be an expression template and doesn't suffer the static cast. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8272 Trac 1.4.3 John Maddock Mon, 11 Mar 2013 13:31:29 GMT owner changed; cc set https://svn.boost.org/trac10/ticket/8272#comment:1 https://svn.boost.org/trac10/ticket/8272#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">pbristow@…</span> added </li> <li><strong>owner</strong> changed from <span class="trac-author">John Maddock</span> to <span class="trac-author">Gennadiy Rozental</span> </li> </ul> <p> Boost.Test knows nothing of expression template types internally and so can't cope with these. The fixes are reasonably easy, but it's up to Boost.Test's maintainer to decide whether to support this use case or not. One fix on your side is to cast arguments to Boost.Test macros to a multiprecision type that has expression template support turned off. </p> <p> Gennadiy, I'm attaching patches and a test case (which IMO belongs in the Boost.Test test suite if you choose to approve the patches), can you take a look? </p> <p> Also adding Paul Bristow in the loop, as I know he hit this one too. </p> Ticket John Maddock Mon, 11 Mar 2013 13:32:54 GMT attachment set https://svn.boost.org/trac10/ticket/8272 https://svn.boost.org/trac10/ticket/8272 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_expression_template_fpt.cpp</span> </li> </ul> <p> Test cases. </p> Ticket John Maddock Thu, 21 Mar 2013 13:36:34 GMT attachment set https://svn.boost.org/trac10/ticket/8272 https://svn.boost.org/trac10/ticket/8272 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_multiprecision.patch</span> </li> </ul> <p> Patches to make Boost.Test work with expression template types. </p> Ticket John Maddock Thu, 21 Mar 2013 13:39:01 GMT component changed https://svn.boost.org/trac10/ticket/8272#comment:2 https://svn.boost.org/trac10/ticket/8272#comment:2 <ul> <li><strong>component</strong> <span class="trac-field-old">multiprecision</span> → <span class="trac-field-new">test</span> </li> </ul> <p> Updated patch (adds missing #include plus test case and Jamfile edits). </p> <p> Tested OK with msvc-9 and 10. GCC-4.7.2, and Intel-13. </p> Ticket Raffi Enficiaud Tue, 07 Jul 2015 08:58:36 GMT status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/8272#comment:3 https://svn.boost.org/trac10/ticket/8272#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.59.0</span> </li> </ul> <p> Duplicates <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/11054" title="#11054: Bugs: Floating-point comparison of multiprecision values fails if expression ... (closed: fixed)">#11054</a> - added the test case <code>fp-multiprecision-comparison</code>: </p> <p> <a class="ext-link" href="https://github.com/boostorg/test/blob/master/test/writing-test-ts/fp-multiprecision-comparison-test.cpp"><span class="icon">​</span>https://github.com/boostorg/test/blob/master/test/writing-test-ts/fp-multiprecision-comparison-test.cpp</a> </p> <p> testing the previous and BOOST_TEST API conformance with multiprecision. </p> Ticket