Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#6307 closed Bugs (fixed)

problem in bessel_jn

Reported by: phzwart@… Owned by: John Maddock
Milestone: To Be Determined Component: math
Version: Boost Development Trunk Severity: Showstopper
Keywords: Cc:

Description

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;

Change History (2)

comment:1 by John Maddock, 11 years ago

Resolution: fixed
Status: newclosed

(In [76094]) Delete unneeded variable. Fixes #6307.

comment:2 by John Maddock, 11 years ago

(In [76095]) Change overflow tests to not generate an infinity. Fixes #6307.

Note: See TracTickets for help on using tickets.