|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r51059 - in trunk: boost/math/special_functions/detail libs/math/test
From: john_at_[hidden]
Date: 2009-02-06 12:26:31
Author: johnmaddock
Date: 2009-02-06 12:26:30 EST (Fri, 06 Feb 2009)
New Revision: 51059
URL: http://svn.boost.org/trac/boost/changeset/51059
Log:
Fix bug in bessel_jn for n == -1.
Add new test case.
Checked that the other Bessel functions do not have the same issue.
Checked that real-valued -1 argument is fixed OK as well as integer argument.
Fixes #2733.
Text files modified:
trunk/boost/math/special_functions/detail/bessel_jn.hpp | 23 +++++++++++++++--------
trunk/libs/math/test/test_bessel_j.cpp | 4 +++-
2 files changed, 18 insertions(+), 9 deletions(-)
Modified: trunk/boost/math/special_functions/detail/bessel_jn.hpp
==============================================================================
--- trunk/boost/math/special_functions/detail/bessel_jn.hpp (original)
+++ trunk/boost/math/special_functions/detail/bessel_jn.hpp 2009-02-06 12:26:30 EST (Fri, 06 Feb 2009)
@@ -28,14 +28,9 @@
BOOST_MATH_STD_USING
- if (n == 0)
- {
- return bessel_j0(x);
- }
- if (n == 1)
- {
- return bessel_j1(x);
- }
+ //
+ // Reflection has to come first:
+ //
if (n < 0)
{
factor = (n & 0x1) ? -1 : 1; // J_{-n}(z) = (-1)^n J_n(z)
@@ -45,12 +40,24 @@
{
factor = 1;
}
+ //
+ // Special cases:
+ //
+ if (n == 0)
+ {
+ return factor * bessel_j0(x);
+ }
+ if (n == 1)
+ {
+ return factor * bessel_j1(x);
+ }
if (x == 0) // n >= 2
{
return static_cast<T>(0);
}
+ BOOST_ASSERT(n > 1);
if (n < abs(x)) // forward recurrence
{
prev = bessel_j0(x);
Modified: trunk/libs/math/test/test_bessel_j.cpp
==============================================================================
--- trunk/libs/math/test/test_bessel_j.cpp (original)
+++ trunk/libs/math/test/test_bessel_j.cpp 2009-02-06 12:26:30 EST (Fri, 06 Feb 2009)
@@ -450,7 +450,9 @@
SC_(1), SC_(10667654)/(1024*1024), SC_(1.24591331097191900488116495350277530373473085499043086981229e-7),
};
- static const boost::array<boost::array<T, 3>, 14> jn_data = {
+ static const boost::array<boost::array<T, 3>, 15> jn_data = {
+ // This first one is a modified test case from https://svn.boost.org/trac/boost/ticket/2733
+ SC_(-1), SC_(1.25), SC_(-0.510623260319880467069474837274910375352924050139633057168856),
SC_(2), SC_(0), SC_(0),
SC_(2), SC_(1e-02), SC_(1.249989583365885362413250958437642113452e-05),
SC_(5), SC_(10), SC_(-0.2340615281867936404436949416457777864635),
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk