Skip to content

Commit 0703718

Browse files
committed
Handle review comments and add tests
1 parent 018010e commit 0703718

File tree

4 files changed

+174
-19
lines changed

4 files changed

+174
-19
lines changed

include/boost/math/special_functions/detail/bessel_jn.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ BOOST_MATH_GPU_ENABLED T bessel_jn(int n, T x, const Policy& pol)
8484
current = value;
8585
}
8686
}
87-
else if(x < 1)
88-
{
89-
return factor * bessel_j_small_z_series(T(n), x, pol);
90-
}
91-
else if((x < 5) && (n > x * x / 4))
87+
else if((x < 5) || (n > x * x / 4))
9288
{
9389
return factor * bessel_j_small_z_series(T(n), x, pol);
9490
}

include/boost/math/special_functions/detail/bessel_jy.hpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,7 @@ namespace boost { namespace math {
330330

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

333-
const bool x_is_lt_one { (x < 1) };
334-
335-
if(kind_does_not_need_y && x_is_lt_one)
336-
{
337-
//
338-
// This series will actually converge rapidly for all small
339-
// x - say up to x < 20 - but the first few terms are large
340-
// and divergent which leads to large errors :-(
341-
//
342-
Jv = bessel_j_small_z_series(v, x, pol);
343-
Yv = boost::math::numeric_limits<T>::quiet_NaN();
344-
}
345-
else if(kind_does_not_need_y && ((x < 5) && (v > x * x / 4)))
333+
if(kind_does_not_need_y && ((x < 5) || (v > x * x / 4)))
346334
{
347335
//
348336
// This series will actually converge rapidly for all small
@@ -352,7 +340,7 @@ namespace boost { namespace math {
352340
Jv = bessel_j_small_z_series(v, x, pol);
353341
Yv = boost::math::numeric_limits<T>::quiet_NaN();
354342
}
355-
else if(x_is_lt_one && (u != 0) && (log(policies::get_epsilon<T, Policy>() / 2) > v * log((x/2) * (x/2) / v)))
343+
else if((x < 1) && (u != 0) && (log(policies::get_epsilon<T, Policy>() / 2) > v * log((x/2) * (x/2) / v)))
356344
{
357345
// Evaluate using series representations.
358346
// This is particularly important for x << v as in this

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ test-suite special_fun :
201201
[ run git_issue_1249.cpp /boost/test//boost_unit_test_framework : : : [ check-target-builds ../config//is_ci_sanitizer_run "Santizer Build" : : <build>no ] ]
202202
[ run git_issue_1255.cpp ]
203203
[ run git_issue_1247.cpp ]
204+
[ run git_issue_1292.cpp ]
204205
[ run special_functions_test.cpp /boost/test//boost_unit_test_framework ]
205206
[ run test_airy.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]
206207
[ run test_bessel_j.cpp test_instances//test_instances pch_light /boost/test//boost_unit_test_framework ]

test/git_issue_1292.cpp

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#include <boost/math/special_functions/bessel.hpp>
2+
3+
#include <boost/core/lightweight_test.hpp>
4+
5+
#include <array>
6+
#include <cstddef>
7+
#include <cstdint>
8+
9+
template<typename FloatType>
10+
auto test_n() -> void
11+
{
12+
using local_float_type = FloatType;
13+
14+
using local_ctrl_array_type = std::array<local_float_type, std::size_t { UINT8_C(43) }>;
15+
16+
// Table[N[BesselJ[3, n/10], 40], {n, 9, 51, 1}]
17+
const local_ctrl_array_type ctrl_data =
18+
{{
19+
static_cast<local_float_type>(0.01443402847586617545767791623904539755731L),
20+
static_cast<local_float_type>(0.01956335398266840591890532162175150825451L),
21+
static_cast<local_float_type>(0.02569452861246328174726417617756888741432L),
22+
static_cast<local_float_type>(0.03287433692499494270867882730165246683837L),
23+
static_cast<local_float_type>(0.04113582571991693187673486447516908751463L),
24+
static_cast<local_float_type>(0.05049771328895129623567992727476043273558L),
25+
static_cast<local_float_type>(0.06096395114113963064394955997646387979571L),
26+
static_cast<local_float_type>(0.07252344333261900300034928368068248675877L),
27+
static_cast<local_float_type>(0.08514992694801526415321095754253909148633L),
28+
static_cast<local_float_type>(0.09880201565861918291536618746528733463749L),
29+
static_cast<local_float_type>(0.1134234066389601112649841240858617923591L),
30+
static_cast<local_float_type>(0.1289432494744020510987933329692398352700L),
31+
static_cast<local_float_type>(0.1452766740542063665759023355570418120750L),
32+
static_cast<local_float_type>(0.1623254728332874543121706910035271736854L),
33+
static_cast<local_float_type>(0.1799789312775334540800304157279732327839L),
34+
static_cast<local_float_type>(0.1981147987975668248498434552081155790183L),
35+
static_cast<local_float_type>(0.2166003910391135247666890035159637217168L),
36+
static_cast<local_float_type>(0.2352938130489638091015220916013129483423L),
37+
static_cast<local_float_type>(0.2540452915872273499615464996563039918262L),
38+
static_cast<local_float_type>(0.2726986037216204380267188592437356599939L),
39+
static_cast<local_float_type>(0.2910925878291867784836313080855848616815L),
40+
static_cast<local_float_type>(0.3090627222552516436182601949468331494291L),
41+
static_cast<local_float_type>(0.3264427561473409695937042738575781129080L),
42+
static_cast<local_float_type>(0.3430663764006682009386373318558777864023L),
43+
static_cast<local_float_type>(0.3587688942275418259451574456258027163924L),
44+
static_cast<local_float_type>(0.3733889346000900583527754127339797472980L),
45+
static_cast<local_float_type>(0.3867701117168813668578718121131100327218L),
46+
static_cast<local_float_type>(0.3987626737105880326848194417650226836608L),
47+
static_cast<local_float_type>(0.4092251000454309977422936498249743734653L),
48+
static_cast<local_float_type>(0.4180256354477855744864458808409348352597L),
49+
static_cast<local_float_type>(0.4250437447674560017637404058105525727991L),
50+
static_cast<local_float_type>(0.4301714738756219403581834788533355563393L),
51+
static_cast<local_float_type>(0.4333147025616927046073022200802734463060L),
52+
static_cast<local_float_type>(0.4343942763872007823091130214493427347554L),
53+
static_cast<local_float_type>(0.4333470055809823422144251313032973397899L),
54+
static_cast<local_float_type>(0.4301265203055088083605755042771532591535L),
55+
static_cast<local_float_type>(0.4247039729774556002468140098011553543390L),
56+
static_cast<local_float_type>(0.4170685797734672711167804755454067582755L),
57+
static_cast<local_float_type>(0.4072279949807128989552790124633945783765L),
58+
static_cast<local_float_type>(0.3952085134465309348696666123753181072022L),
59+
static_cast<local_float_type>(0.3810550980268886849843356923521907577982L),
60+
static_cast<local_float_type>(0.3648312306136669944635769493587219791343L),
61+
static_cast<local_float_type>(0.3466185870197064968846647990300282094299L)
62+
}};
63+
64+
int n_val { 9 };
65+
66+
for(std::size_t index { UINT8_C(0) }; index < std::tuple_size<local_ctrl_array_type>::value; ++index)
67+
{
68+
const local_float_type x_val { static_cast<local_float_type>(static_cast<local_float_type>(n_val) / 10) };
69+
70+
const local_float_type jn_val { boost::math::cyl_bessel_j(3, x_val) };
71+
72+
++n_val;
73+
74+
using std::fabs;
75+
76+
const local_float_type ratio { jn_val / ctrl_data[index] };
77+
const local_float_type delta { fabs(1 - ratio) };
78+
79+
BOOST_TEST(delta < 128 * std::numeric_limits<local_float_type>::epsilon());
80+
}
81+
}
82+
83+
template<typename FloatType>
84+
auto test_vu() -> void
85+
{
86+
using local_float_type = FloatType;
87+
88+
using local_ctrl_array_type = std::array<local_float_type, std::size_t { UINT8_C(43) }>;
89+
90+
// Table[N[BesselJ[31 / 10, n/10], 40], {n, 9, 51, 1}]
91+
const local_ctrl_array_type ctrl_data =
92+
{{
93+
static_cast<local_float_type>(0.01175139795214295170487105485346781171863L),
94+
static_cast<local_float_type>(0.01610092560641321584451701371378836908343L),
95+
static_cast<local_float_type>(0.02135659148701787280713314897691402425560L),
96+
static_cast<local_float_type>(0.02757316602094671775387912184375438913864L),
97+
static_cast<local_float_type>(0.03479372470942323424236519547108889796879L),
98+
static_cast<local_float_type>(0.04304884612770317349181083608393216357649L),
99+
static_cast<local_float_type>(0.05235595486839477302545989170267853515412L),
100+
static_cast<local_float_type>(0.06271881444009116864560457340917173135492L),
101+
static_cast<local_float_type>(0.07412717428914531462554459978389560408816L),
102+
static_cast<local_float_type>(0.08655657401374878955779092959288219537482L),
103+
static_cast<local_float_type>(0.09996830657138141192006478769855556316995L),
104+
static_cast<local_float_type>(0.1143095409011066041623799431143340837007L),
105+
static_cast<local_float_type>(0.1295136029333754366226206053365805922136L),
106+
static_cast<local_float_type>(0.1455004124749064242445094865982308151833L),
107+
static_cast<local_float_type>(0.1621770719619318324763655518038365467780L),
108+
static_cast<local_float_type>(0.1794386015949089605595848208470049166853L),
109+
static_cast<local_float_type>(0.1971688139222575484595939469080319406355L),
110+
static_cast<local_float_type>(0.2152413195483352761119610246805962611319L),
111+
static_cast<local_float_type>(0.2335206543185642795903443565627832597552L),
112+
static_cast<local_float_type>(0.2518635170977563283446184976264924077045L),
113+
static_cast<local_float_type>(0.2701201061202457234361463802484836927464L),
114+
static_cast<local_float_type>(0.2881355408650536940851830262098172944660L),
115+
static_cast<local_float_type>(0.3057513555072237123913927136839853900197L),
116+
static_cast<local_float_type>(0.3228070492275195774383850177821175151772L),
117+
static_cast<local_float_type>(0.3391416780352496831991017115498371039332L),
118+
static_cast<local_float_type>(0.3545954722799571667706920253581728149226L),
119+
static_cast<local_float_type>(0.3690114637024459111815176585531943143085L),
120+
static_cast<local_float_type>(0.3822371057078773326211699424651752096338L),
121+
static_cast<local_float_type>(0.3941258705356621024731438508712990073773L),
122+
static_cast<local_float_type>(0.4045388071531719615179931506197074798366L),
123+
static_cast<local_float_type>(0.4133460440118967760814988295083688541739L),
124+
static_cast<local_float_type>(0.4204282212729730452147271372029342292548L),
125+
static_cast<local_float_type>(0.4256778377298582292448895379334671298297L),
126+
static_cast<local_float_type>(0.4290004984236535775073755577697874033289L),
127+
static_cast<local_float_type>(0.4303160498540635572666996674883665298558L),
128+
static_cast<local_float_type>(0.4295595907277138677145484170304736319185L),
129+
static_cast<local_float_type>(0.4266823473457215250850626209433240464185L),
130+
static_cast<local_float_type>(0.4216524040030023831246842156638018726147L),
131+
static_cast<local_float_type>(0.4144552801406973126588418824207056743782L),
132+
static_cast<local_float_type>(0.4050943474472003316564108983454900189419L),
133+
static_cast<local_float_type>(0.3935910816286283019261303507307813773886L),
134+
static_cast<local_float_type>(0.3799851451515116989978414766085547417497L),
135+
static_cast<local_float_type>(0.3643342988837623802358278078893847672838L)
136+
}};
137+
138+
int n_val { 9 };
139+
140+
const local_float_type vu_val { static_cast<local_float_type>(static_cast<local_float_type>(31) / 10) };
141+
142+
for(std::size_t index { UINT8_C(0) }; index < std::tuple_size<local_ctrl_array_type>::value; ++index)
143+
{
144+
const local_float_type x_val { static_cast<local_float_type>(static_cast<local_float_type>(n_val) / 10) };
145+
146+
const local_float_type jn_val { boost::math::cyl_bessel_j(vu_val, x_val) };
147+
148+
++n_val;
149+
150+
using std::fabs;
151+
152+
const local_float_type ratio { jn_val / ctrl_data[index] };
153+
const local_float_type delta { fabs(1 - ratio) };
154+
155+
BOOST_TEST(delta < 128 * std::numeric_limits<local_float_type>::epsilon());
156+
}
157+
}
158+
159+
auto main() -> int
160+
{
161+
test_n<float>();
162+
test_n<double>();
163+
test_n<long double>();
164+
165+
test_vu<float>();
166+
test_vu<double>();
167+
test_vu<long double>();
168+
169+
return boost::report_errors();
170+
}

0 commit comments

Comments
 (0)