Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/math/special_functions/detail/bessel_jn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ BOOST_MATH_GPU_ENABLED T bessel_jn(int n, T x, const Policy& pol)
current = value;
}
}
else if((x < 1) || (n > x * x / 4) || (x < 5))
else if((x < 5) || (n > x * x / 4))
{
return factor * bessel_j_small_z_series(T(n), x, pol);
}
Expand Down
5 changes: 4 additions & 1 deletion include/boost/math/special_functions/detail/bessel_jy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ namespace boost { namespace math {
// x is positive until reflection
W = T(2) / (x * pi<T>()); // Wronskian
T Yv_scale = 1;
if(((kind & need_y) == 0) && ((x < 1) || (v > x * x / 4) || (x < 5)))

const bool kind_does_not_need_y { ((kind & need_y) == 0) };

if(kind_does_not_need_y && ((x < 5) || (v > x * x / 4)))
{
//
// This series will actually converge rapidly for all small
Expand Down
4 changes: 0 additions & 4 deletions test/test_bessel_j.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,3 @@ BOOST_AUTO_TEST_CASE( test_main )
"to pass.</note>" << std::endl;
#endif
}




80 changes: 80 additions & 0 deletions test/test_bessel_j.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,82 @@ void do_test_sph_bessel_j(const T& data, const char* type_name, const char* test
#endif
}

template<class T>
auto test_issue1292_n() -> void
{
using local_ctrl_array_type = std::array<T, std::size_t { UINT8_C(43) }>;

// Table[N[BesselJ[3, n/10], 40], {n, 9, 51, 1}]
const local_ctrl_array_type ctrl_data =
{{
SC_(0.01443402847586617545767791623904539755731), SC_(0.01956335398266840591890532162175150825451), SC_(0.02569452861246328174726417617756888741432), SC_(0.03287433692499494270867882730165246683837),
SC_(0.04113582571991693187673486447516908751463), SC_(0.05049771328895129623567992727476043273558), SC_(0.06096395114113963064394955997646387979571), SC_(0.07252344333261900300034928368068248675877),
SC_(0.08514992694801526415321095754253909148633), SC_(0.09880201565861918291536618746528733463749), SC_(0.1134234066389601112649841240858617923591), SC_(0.1289432494744020510987933329692398352700),
SC_(0.1452766740542063665759023355570418120750), SC_(0.1623254728332874543121706910035271736854), SC_(0.1799789312775334540800304157279732327839), SC_(0.1981147987975668248498434552081155790183),
SC_(0.2166003910391135247666890035159637217168), SC_(0.2352938130489638091015220916013129483423), SC_(0.2540452915872273499615464996563039918262), SC_(0.2726986037216204380267188592437356599939),
SC_(0.2910925878291867784836313080855848616815), SC_(0.3090627222552516436182601949468331494291), SC_(0.3264427561473409695937042738575781129080), SC_(0.3430663764006682009386373318558777864023),
SC_(0.3587688942275418259451574456258027163924), SC_(0.3733889346000900583527754127339797472980), SC_(0.3867701117168813668578718121131100327218), SC_(0.3987626737105880326848194417650226836608),
SC_(0.4092251000454309977422936498249743734653), SC_(0.4180256354477855744864458808409348352597), SC_(0.4250437447674560017637404058105525727991), SC_(0.4301714738756219403581834788533355563393),
SC_(0.4333147025616927046073022200802734463060), SC_(0.4343942763872007823091130214493427347554), SC_(0.4333470055809823422144251313032973397899), SC_(0.4301265203055088083605755042771532591535),
SC_(0.4247039729774556002468140098011553543390), SC_(0.4170685797734672711167804755454067582755), SC_(0.4072279949807128989552790124633945783765), SC_(0.3952085134465309348696666123753181072022),
SC_(0.3810550980268886849843356923521907577982), SC_(0.3648312306136669944635769493587219791343), SC_(0.3466185870197064968846647990300282094299)
}};

const T tolerance { 128 * std::numeric_limits<T>::epsilon() };

int n_val { 9 };

for(const T& ctrl: ctrl_data)
{
const T x_val { static_cast<T>(static_cast<T>(n_val) / 10) };

const T jn_val { boost::math::cyl_bessel_j(3, x_val) };

++n_val;

BOOST_CHECK_CLOSE_FRACTION(jn_val, ctrl, tolerance);
}
}

template<class T>
auto test_issue1292_vu() -> void
{
using local_ctrl_array_type = std::array<T, std::size_t { UINT8_C(43) }>;

// Table[N[BesselJ[31 / 10, n/10], 40], {n, 9, 51, 1}]
const local_ctrl_array_type ctrl_data =
{{
SC_(0.01175139795214295170487105485346781171863), SC_(0.01610092560641321584451701371378836908343), SC_(0.02135659148701787280713314897691402425560), SC_(0.02757316602094671775387912184375438913864),
SC_(0.03479372470942323424236519547108889796879), SC_(0.04304884612770317349181083608393216357649), SC_(0.05235595486839477302545989170267853515412), SC_(0.06271881444009116864560457340917173135492),
SC_(0.07412717428914531462554459978389560408816), SC_(0.08655657401374878955779092959288219537482), SC_(0.09996830657138141192006478769855556316995), SC_(0.1143095409011066041623799431143340837007),
SC_(0.1295136029333754366226206053365805922136), SC_(0.1455004124749064242445094865982308151833), SC_(0.1621770719619318324763655518038365467780), SC_(0.1794386015949089605595848208470049166853),
SC_(0.1971688139222575484595939469080319406355), SC_(0.2152413195483352761119610246805962611319), SC_(0.2335206543185642795903443565627832597552), SC_(0.2518635170977563283446184976264924077045),
SC_(0.2701201061202457234361463802484836927464), SC_(0.2881355408650536940851830262098172944660), SC_(0.3057513555072237123913927136839853900197), SC_(0.3228070492275195774383850177821175151772),
SC_(0.3391416780352496831991017115498371039332), SC_(0.3545954722799571667706920253581728149226), SC_(0.3690114637024459111815176585531943143085), SC_(0.3822371057078773326211699424651752096338),
SC_(0.3941258705356621024731438508712990073773), SC_(0.4045388071531719615179931506197074798366), SC_(0.4133460440118967760814988295083688541739), SC_(0.4204282212729730452147271372029342292548),
SC_(0.4256778377298582292448895379334671298297), SC_(0.4290004984236535775073755577697874033289), SC_(0.4303160498540635572666996674883665298558), SC_(0.4295595907277138677145484170304736319185),
SC_(0.4266823473457215250850626209433240464185), SC_(0.4216524040030023831246842156638018726147), SC_(0.4144552801406973126588418824207056743782), SC_(0.4050943474472003316564108983454900189419),
SC_(0.3935910816286283019261303507307813773886), SC_(0.3799851451515116989978414766085547417497), SC_(0.3643342988837623802358278078893847672838)
}};

const T tolerance { 128 * std::numeric_limits<T>::epsilon() };

const T vu_val { static_cast<T>(static_cast<T>(31) / 10) };

int n_val { 9 };

for(const T& ctrl : ctrl_data)
{
const T x_val { static_cast<T>(static_cast<T>(n_val) / 10) };

const T jn_val { boost::math::cyl_bessel_j(vu_val, x_val) };

++n_val;

BOOST_CHECK_CLOSE_FRACTION(jn_val, ctrl, tolerance);
}
}

template <class T>
void test_bessel(T, const char* name)
{
Expand Down Expand Up @@ -261,6 +337,10 @@ void test_bessel(T, const char* name)
//
// Some special cases:
//

test_issue1292_n<double>();
test_issue1292_vu<double>();

BOOST_CHECK_EQUAL(boost::math::sph_bessel(0, T(0)), T(1));
BOOST_CHECK_EQUAL(boost::math::sph_bessel(1, T(0)), T(0));
BOOST_CHECK_EQUAL(boost::math::sph_bessel(100000, T(0)), T(0));
Expand Down
Loading