Subject: [Boost-bugs] [Boost C++ Libraries] #6307: problem in bessel_jn
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-12-20 19:39:56
#6307: problem in bessel_jn
-------------------------------------+--------------------------------------
Reporter: phzwart@⦠| Owner: johnmaddock
Type: Bugs | Status: new
Milestone: To Be Determined | Component: math
Version: Boost Development Trunk | Severity: Showstopper
Keywords: |
-------------------------------------+--------------------------------------
In bessel_jn (math/special_functions/detail) line 75 reads:
if((tools::max_value<T>() - fabs(prev)) / fabs(fact) < fabs(current))
fact is defined in line 74:
T fact = 2 * k / x;
when k is 1 and x > 2 , fact < 1 resulting in
((tools::max_value<T>() - fabs(prev)) / fabs(fact)
to be bigger then tools::max_value<T>(), resulkting in an error.
I have change line 75 into
if((tools::max_value<T>() - fabs(prev)) < fabs(fact) * fabs(current))
and made the same change for line 100.
With this fix, the code runs and produces (in my limited testing) the same
numbers as octave does. I am not sure if it is a general fix though.
The problem occurred on this architecture:
Linux syrah.als.lbl.gov 2.6.35.14-97.fc14.x86_64 #1 SMP Sat Sep 17
00:15:37 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
svn diff gives this:
===================================================================
--- bessel_jn.hpp (revision 76082)
+++ bessel_jn.hpp (working copy)
@@ -72,7 +72,7 @@
for (int k = 1; k < n; k++)
{
T fact = 2 * k / x;
- if((tools::max_value<T>() - fabs(prev)) / fabs(fact) <
fabs(current))
+ if((tools::max_value<T>() - fabs(prev)) < fabs(fact) *
fabs(current))
{
scale /= current;
prev /= current;
@@ -97,7 +97,7 @@
for (int k = n; k > 0; k--)
{
T fact = 2 * k / x;
- if((tools::max_value<T>() - fabs(prev)) / fact <
fabs(current))
+ if((tools::max_value<T>() - fabs(prev)) < fabs(fact) *
fabs(current))
{
prev /= current;
scale /= current;
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6307> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:08 UTC