diff --git a/include/boost/math/special_functions/airy.hpp b/include/boost/math/special_functions/airy.hpp index 554fb58d8..450a2d7cd 100644 --- a/include/boost/math/special_functions/airy.hpp +++ b/include/boost/math/special_functions/airy.hpp @@ -154,10 +154,17 @@ T airy_bi_prime_imp(T x, const Policy& pol) } template -T airy_ai_zero_imp(unsigned m, const Policy& pol) +T airy_ai_zero_imp(int m, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names, needed for log, sqrt. + // Handle cases when a negative zero (negative rank) is requested. + if(m < 0) + { + return policies::raise_domain_error("boost::math::airy_ai_zero<%1%>(%1%, int)", + "Requested the %1%'th zero, but the rank must be 1 or more !", m, pol); + } + // Handle case when the zero'th zero is requested. if(m == 0U) { @@ -180,10 +187,10 @@ T airy_ai_zero_imp(unsigned m, const Policy& pol) // Use a dynamic tolerance because the roots get closer the higher m gets. T tolerance; - if (m <= 10U) { tolerance = T(0.3F); } - else if(m <= 100U) { tolerance = T(0.1F); } - else if(m <= 1000U) { tolerance = T(0.05F); } - else { tolerance = T(1) / sqrt(T(m)); } + if (m <= 10) { tolerance = T(0.3F); } + else if(m <= 100) { tolerance = T(0.1F); } + else if(m <= 1000) { tolerance = T(0.05F); } + else { tolerance = T(1) / sqrt(T(m)); } // Perform the root-finding using Newton-Raphson iteration from Boost.Math. const T am = @@ -201,10 +208,17 @@ T airy_ai_zero_imp(unsigned m, const Policy& pol) } template -T airy_bi_zero_imp(unsigned m, const Policy& pol) +T airy_bi_zero_imp(int m, const Policy& pol) { BOOST_MATH_STD_USING // ADL of std names, needed for log, sqrt. + // Handle cases when a negative zero (negative rank) is requested. + if(m < 0) + { + return policies::raise_domain_error("boost::math::airy_bi_zero<%1%>(%1%, int)", + "Requested the %1%'th zero, but the rank must 1 or more !", m, pol); + } + // Handle case when the zero'th zero is requested. if(m == 0U) { @@ -226,10 +240,10 @@ T airy_bi_zero_imp(unsigned m, const Policy& pol) // Use a dynamic tolerance because the roots get closer the higher m gets. T tolerance; - if (m <= 10U) { tolerance = T(0.3F); } - else if(m <= 100U) { tolerance = T(0.1F); } - else if(m <= 1000U) { tolerance = T(0.05F); } - else { tolerance = T(1) / sqrt(T(m)); } + if (m <= 10) { tolerance = T(0.3F); } + else if(m <= 100) { tolerance = T(0.1F); } + else if(m <= 1000) { tolerance = T(0.05F); } + else { tolerance = T(1) / sqrt(T(m)); } // Perform the root-finding using Newton-Raphson iteration from Boost.Math. const T bm = @@ -337,7 +351,7 @@ inline typename tools::promote_args::type airy_bi_prime(T x) } template -inline T airy_ai_zero(unsigned m, const Policy& /*pol*/) +inline T airy_ai_zero(int m, const Policy& /*pol*/) { BOOST_FPU_EXCEPTION_GUARD typedef typename policies::evaluation::type value_type; @@ -352,14 +366,14 @@ inline T airy_ai_zero(unsigned m, const Policy& /*pol*/) } template -inline T airy_ai_zero(unsigned m) +inline T airy_ai_zero(int m) { return airy_ai_zero(m, policies::policy<>()); } template inline OutputIterator airy_ai_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it, const Policy& pol) @@ -367,7 +381,7 @@ inline OutputIterator airy_ai_zero( typedef T result_type; BOOST_STATIC_ASSERT_MSG(false == std::numeric_limits::is_integer, "Airy return type must be a floating-point type."); - for(unsigned i = 0; i < number_of_zeros; ++i) + for(unsigned i = 0; i < static_cast(number_of_zeros); ++i) { *out_it = boost::math::airy_ai_zero(start_index + i, pol); ++out_it; @@ -377,7 +391,7 @@ inline OutputIterator airy_ai_zero( template inline OutputIterator airy_ai_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it) { @@ -385,7 +399,7 @@ inline OutputIterator airy_ai_zero( } template -inline T airy_bi_zero(unsigned m, const Policy& /*pol*/) +inline T airy_bi_zero(int m, const Policy& /*pol*/) { BOOST_FPU_EXCEPTION_GUARD typedef typename policies::evaluation::type value_type; @@ -407,7 +421,7 @@ inline T airy_bi_zero(unsigned m) template inline OutputIterator airy_bi_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it, const Policy& pol) @@ -415,7 +429,7 @@ inline OutputIterator airy_bi_zero( typedef T result_type; BOOST_STATIC_ASSERT_MSG(false == std::numeric_limits::is_integer, "Airy return type must be a floating-point type."); - for(unsigned i = 0; i < number_of_zeros; ++i) + for(int i = 0; i < static_cast(number_of_zeros); ++i) { *out_it = boost::math::airy_bi_zero(start_index + i, pol); ++out_it; @@ -425,7 +439,7 @@ inline OutputIterator airy_bi_zero( template inline OutputIterator airy_bi_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it) { diff --git a/include/boost/math/special_functions/bessel.hpp b/include/boost/math/special_functions/bessel.hpp index ceca30916..60fb1062b 100644 --- a/include/boost/math/special_functions/bessel.hpp +++ b/include/boost/math/special_functions/bessel.hpp @@ -693,7 +693,7 @@ inline OutputIterator cyl_bessel_j_zero(T v, const Policy& pol) { BOOST_STATIC_ASSERT_MSG(false == std::numeric_limits::is_integer, "Order must be a floating-point type."); - for(unsigned i = 0; i < number_of_zeros; ++i) + for(int i = 0; i < static_cast(number_of_zeros); ++i) { *out_it = boost::math::cyl_bessel_j_zero(v, start_index + i, pol); ++out_it; @@ -741,7 +741,7 @@ inline OutputIterator cyl_neumann_zero(T v, const Policy& pol) { BOOST_STATIC_ASSERT_MSG(false == std::numeric_limits::is_integer, "Order must be a floating-point type."); - for(unsigned i = 0; i < number_of_zeros; ++i) + for(int i = 0; i < static_cast(number_of_zeros); ++i) { *out_it = boost::math::cyl_neumann_zero(v, start_index + i, pol); ++out_it; diff --git a/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp b/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp index d502f83dd..dbb7388dd 100644 --- a/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp +++ b/include/boost/math/special_functions/detail/airy_ai_bi_zero.hpp @@ -54,26 +54,26 @@ namespace airy_ai_zero_detail { template - T initial_guess(const unsigned m) + T initial_guess(const int m) { T guess; switch(m) { - case 0U: { guess = T(0); break; } - case 1U: { guess = T(-2.33810741045976703849); break; } - case 2U: { guess = T(-4.08794944413097061664); break; } - case 3U: { guess = T(-5.52055982809555105913); break; } - case 4U: { guess = T(-6.78670809007175899878); break; } - case 5U: { guess = T(-7.94413358712085312314); break; } - case 6U: { guess = T(-9.02265085334098038016); break; } - case 7U: { guess = T(-10.0401743415580859306); break; } - case 8U: { guess = T(-11.0085243037332628932); break; } - case 9U: { guess = T(-11.9360155632362625170); break; } - case 10U:{ guess = T(-12.8287767528657572004); break; } + case 0: { guess = T(0); break; } + case 1: { guess = T(-2.33810741045976703849); break; } + case 2: { guess = T(-4.08794944413097061664); break; } + case 3: { guess = T(-5.52055982809555105913); break; } + case 4: { guess = T(-6.78670809007175899878); break; } + case 5: { guess = T(-7.94413358712085312314); break; } + case 6: { guess = T(-9.02265085334098038016); break; } + case 7: { guess = T(-10.0401743415580859306); break; } + case 8: { guess = T(-11.0085243037332628932); break; } + case 9: { guess = T(-11.9360155632362625170); break; } + case 10:{ guess = T(-12.8287767528657572004); break; } default: { - const T t(((boost::math::constants::pi() * 3U) * ((T(m) * 4U) - 1)) / 8U); + const T t(((boost::math::constants::pi() * 3) * ((T(m) * 4) - 1)) / 8); guess = -boost::math::detail::airy_zero::equation_as_10_4_105(t); break; } @@ -105,26 +105,26 @@ namespace airy_bi_zero_detail { template - T initial_guess(const unsigned m) + T initial_guess(const int m) { T guess; switch(m) { - case 0U: { guess = T(0); break; } - case 1U: { guess = T(-1.17371322270912792492); break; } - case 2U: { guess = T(-3.27109330283635271568); break; } - case 3U: { guess = T(-4.83073784166201593267); break; } - case 4U: { guess = T(-6.16985212831025125983); break; } - case 5U: { guess = T(-7.37676207936776371360); break; } - case 6U: { guess = T(-8.49194884650938801345); break; } - case 7U: { guess = T(-9.53819437934623888663); break; } - case 8U: { guess = T(-10.5299135067053579244); break; } - case 9U: { guess = T(-11.4769535512787794379); break; } - case 10U:{ guess = T(-12.3864171385827387456); break; } + case 0: { guess = T(0); break; } + case 1: { guess = T(-1.17371322270912792492); break; } + case 2: { guess = T(-3.27109330283635271568); break; } + case 3: { guess = T(-4.83073784166201593267); break; } + case 4: { guess = T(-6.16985212831025125983); break; } + case 5: { guess = T(-7.37676207936776371360); break; } + case 6: { guess = T(-8.49194884650938801345); break; } + case 7: { guess = T(-9.53819437934623888663); break; } + case 8: { guess = T(-10.5299135067053579244); break; } + case 9: { guess = T(-11.4769535512787794379); break; } + case 10: { guess = T(-12.3864171385827387456); break; } default: { - const T t(((boost::math::constants::pi() * 3U) * ((T(m) * 4U) - 3)) / 8U); + const T t(((boost::math::constants::pi() * 3) * ((T(m) * 4) - 3)) / 8); guess = -boost::math::detail::airy_zero::equation_as_10_4_105(t); break; } diff --git a/include/boost/math/special_functions/math_fwd.hpp b/include/boost/math/special_functions/math_fwd.hpp index 44f3aa5e3..4fc29019a 100644 --- a/include/boost/math/special_functions/math_fwd.hpp +++ b/include/boost/math/special_functions/math_fwd.hpp @@ -701,35 +701,35 @@ namespace boost typename tools::promote_args::type airy_bi_prime(T x); template - T airy_ai_zero(unsigned m); + T airy_ai_zero(int m); template - T airy_ai_zero(unsigned m, const Policy&); + T airy_ai_zero(int m, const Policy&); template OutputIterator airy_ai_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it); template OutputIterator airy_ai_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it, const Policy&); template - T airy_bi_zero(unsigned m); + T airy_bi_zero(int m); template - T airy_bi_zero(unsigned m, const Policy&); + T airy_bi_zero(int m, const Policy&); template OutputIterator airy_bi_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it); template OutputIterator airy_bi_zero( - unsigned start_index, + int start_index, unsigned number_of_zeros, OutputIterator out_it, const Policy&);