Boost C++ Libraries: Ticket #12191: Unable to produce proper multiprecision output from sph_neumann() function https://svn.boost.org/trac10/ticket/12191 <p> I am trying to use the boost c++ libraries to compute a multiprecision value for the spherical bessel functions and spherical neumann functions. To test the boost package I am using the relationships: </p> <p> pi/6*Spherical_Bessel(0,pi/6) = sin(pi/6) = 0.5 </p> <p> -pi/6*Spherical_Neumann(0,pi/6) = cos(pi/6) = sqrt(3)/2 = 0.866.... My test code is: </p> <blockquote> <p> #include &lt;boost/multiprecision/mpfr.hpp&gt; </p> </blockquote> <blockquote> <p> #include &lt;boost/math/special_functions/bessel.hpp&gt; </p> </blockquote> <blockquote> <p> #include &lt;boost/math/constants/constants.hpp&gt; </p> </blockquote> <blockquote> <p> #include &lt;boost/multiprecision/number.hpp&gt; </p> </blockquote> <blockquote> <p> #define PRECISION 40 <em> Can be set to any number desired. </em></p> </blockquote> <blockquote> <p> using namespace std; using namespace boost::multiprecision; using namespace boost; </p> </blockquote> <blockquote> <p> mpfr_float::default_precision(PRECISION); </p> </blockquote> <blockquote> <p> mpfr_float z, my_pi; </p> </blockquote> <blockquote> <p> my_pi = boost::multiprecision::atan(mpfr_float("1.0"))*mpfr_float("4.0"); <em> Define pi as a multiprecision value to precision = PRECISION. </em></p> </blockquote> <blockquote> <p> z = my_pi/mpfr_float("6.0"); </p> </blockquote> <blockquote> <p> cout &lt;&lt; z*mpfr_float(boost::math::sph_bessel(0,z)) &lt;&lt; endl; </p> </blockquote> <blockquote> <p> cout &lt;&lt; mpfr_float("-1.0")*z*mpfr_float(boost::math::sph_neumann(0,z)) &lt;&lt; endl; </p> </blockquote> <p> ======================================================================== </p> <blockquote> <p> The value of my_pi agrees with the value computed by Wolfram (to at least 100 decimal places). The value of z also agrees with the value from Wolfram. The output for the z*sph_bessel(0,z) function is correct: 0.5000000000.... The output for the -z*sph_neumann(0,z) function is incorrect: 0.86602540378443864<strong>*30</strong>*... instead of 0.86602540378443864<strong>*67</strong>*.... Which looks like the answer is not multiprecision but a float. </p> </blockquote> <p> Can you please help with this bug? Thanks. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12191 Trac 1.4.3 John Maddock Mon, 16 May 2016 17:43:18 GMT component changed; owner set https://svn.boost.org/trac10/ticket/12191#comment:1 https://svn.boost.org/trac10/ticket/12191#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">math</span> </li> </ul> Ticket John Maddock Mon, 16 May 2016 18:49:02 GMT <link>https://svn.boost.org/trac10/ticket/12191#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12191#comment:2</guid> <description> <p> Confirmed - it's an issue with using mpfr_float (a variable precision type and no numeric_limits support) vs a fixed precision type like mpfr_float_50 which does produce the correct result. There's at least one bug somewhere, but I can't find it at present. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 05 Jun 2016 17:35:51 GMT</pubDate> <title>status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/12191#comment:3 https://svn.boost.org/trac10/ticket/12191#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.62.0</span> </li> </ul> <p> This required rather a lot of changes to fix - but is now fixed in develop - you will need both Math and Multiprecision lib develop branches though to see the fix. On the plus side you can now change precision in mid program and have it all still work... something we didn't support before. </p> Ticket