Modify

Ticket #6307 (closed Bugs: fixed)

Opened 2 years ago

Last modified 2 years ago

problem in bessel_jn

Reported by: phzwart@… Owned by: johnmaddock
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;

Attachments

Change History

comment:1 Changed 2 years ago by johnmaddock

  • Status changed from new to closed
  • Resolution set to fixed

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

comment:2 Changed 2 years ago by johnmaddock

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.