Boost C++ Libraries: Ticket #12234: boost::multiprecision x64 win32 hard compile errors on windows with mpir https://svn.boost.org/trac10/ticket/12234 <p> I get a hard compile error in trying to get boost multprecision floating point examples working with mpir on windows x64. </p> <p> The crux of the error is that some of the boost code uses functions whose signatures are long* but the code is used with arguments of type mpir_ui* etc.and of course this is a nasty for pointers! </p> <pre class="wiki">1&gt;C:\Program Files\boost\boost_1_61_0\boost/multiprecision/gmp.hpp(982): error C2664: 'double __gmpf_get_d_2exp(mpir_si *,mpf_srcptr)': cannot convert argument 1 from 'long *' to 'mpir_si *' 1&gt; C:\Program Files\boost\boost_1_61_0\boost/multiprecision/gmp.hpp(982): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast </pre><p> One workaround that "works" is to define double <span class="underline">gmpf_get_d_2exp(long * p, mpf_srcptr a) : </span></p> <pre class="wiki">#include "stdafx.h" #include &lt;boost/multiprecision/gmp.hpp&gt; #include &lt;boost/math/special_functions/gamma.hpp&gt; #include "Safeint3.hpp" #include &lt;iostream&gt; namespace boost { namespace multiprecision { template &lt;unsigned Digits10&gt; struct gmp_float; typedef number&lt;gmp_float&lt;50&gt; &gt; mpf_float_50; typedef number&lt;gmp_float&lt;100&gt; &gt; mpf_float_100; typedef number&lt;gmp_float&lt;500&gt; &gt; mpf_float_500; typedef number&lt;gmp_float&lt;1000&gt; &gt; mpf_float_1000; typedef number&lt;gmp_float&lt;0&gt; &gt; mpf_float; } } // namespaces //FIX - define a wrapper double __gmpf_get_d_2exp(long * p, mpf_srcptr a) { mpir_si temp{ *p }; double b = __gmpf_get_d_2exp(&amp;temp, a); *p = SafeInt&lt;long&gt;(temp); return b; } </pre><p> But is this the answer? I find it difficult to get the sense of gmp.hpp well enough to figure out whether or not it knows when it can narrow a variable and when it cannot. </p> <p> Clearly is intended to cope with the 64 32 divide on long; however I am puzzled by code like: </p> <pre class="wiki">inline void eval_convert_to(long* result, const gmp_rational&amp; val) { double r; eval_convert_to(&amp;r, val); *result = static_cast&lt;long&gt;(r); } inline void eval_convert_to(unsigned long* result, const gmp_rational&amp; val) { double r; eval_convert_to(&amp;r, val); *result = static_cast&lt;long&gt;(r); } </pre><p> Which to my amateur eye does not seem to be nice. </p> <p> Suggestions welcome - mpir is the current version and working nicely; boost is 1.61.0 and working nicely. </p> <p> I would really like to get them working together. </p> <p> Environment - VS 2015-2008, Intel 16.0, windows 7. </p> <p> Terry </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12234 Trac 1.4.3 tlyons@… Mon, 30 May 2016 13:31:31 GMT <link>https://svn.boost.org/trac10/ticket/12234#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12234#comment:1</guid> <description> <p> I should have given the code example that triggered the problem. Uncomment the relevant part and it runs successfully: </p> <pre class="wiki">#include "stdafx.h" #include &lt;boost/multiprecision/gmp.hpp&gt; #include &lt;boost/math/special_functions/gamma.hpp&gt; #include "Safeint3.hpp" // for a safe fix: http://safeint.codeplex.com/ #include &lt;iostream&gt; namespace boost { namespace multiprecision { template &lt;unsigned Digits10&gt; struct gmp_float; typedef number&lt;gmp_float&lt;100&gt; &gt; mpf_float_100; } } // namespaces /* // uncomment this block to fix the code double __gmpf_get_d_2exp(long * p, mpf_srcptr a) { mpir_si temp{ *p }; double b = __gmpf_get_d_2exp(&amp;temp, a); *p = SafeInt&lt;long&gt;(temp); return b; } */ using namespace boost::multiprecision; int fourth() { mpf_float_100 b = 2; std::cout &lt;&lt; std::numeric_limits&lt;mpf_float_100&gt;::digits &lt;&lt; std::endl; // We can use any C++ std lib function: std::cout &lt;&lt; log(b) &lt;&lt; std::endl; // print log(2)// ERROR on this line // We can also use any function from Boost.Math: std::cout &lt;&lt; boost::math::tgamma(b) &lt;&lt; std::endl; // These even work when the argument is an expression template: std::cout &lt;&lt; boost::math::tgamma(b * b) &lt;&lt; std::endl; return 0; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 06 Jun 2016 17:56:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12234#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12234#comment:2</guid> <description> <p> I need to check with latest MPIR, but my version has no such type as mpir_si, further the function call that's causing the issue (mpf_get_d_2exp) is documented as: </p> <p> <code> double mpf_get_d_2exp (signed long int *exp, const mpf_t op)</code> </p> <p> In the latest GMP documentation. Is this an incompatibility between GMP and MPIR by any chance? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 07 Jun 2016 18:12:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12234#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12234#comment:3</guid> <description> <p> I believe this to be an MPIR bug: <a class="ext-link" href="https://github.com/wbhart/mpir/commit/fb616eed78d0a32dc9e53b355b0c2d42c1209907#commitcomment-17775327"><span class="icon">​</span>https://github.com/wbhart/mpir/commit/fb616eed78d0a32dc9e53b355b0c2d42c1209907#commitcomment-17775327</a> </p> <p> Will commit a workaround shortly. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 07 Jun 2016 18:15:32 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/12234#comment:4 https://svn.boost.org/trac10/ticket/12234#comment:4 <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.62.0</span> </li> </ul> <p> Workaround/fix in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/0b7591dd3a6425786bfdc58d481de7d796076a7c"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/0b7591dd3a6425786bfdc58d481de7d796076a7c</a> </p> Ticket