Skip to content

Commit 9f03f29

Browse files
authored
Merge pull request #1261 from boostorg/cleanup_warns
Handle various conversion warnings
2 parents 5130435 + bc0635f commit 9f03f29

File tree

21 files changed

+117
-126
lines changed

21 files changed

+117
-126
lines changed

include/boost/math/constants/info.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include <boost/math/constants/constants.hpp>
1414
#include <iostream>
1515
#include <iomanip>
16+
#ifndef BOOST_MATH_NO_RTTI
1617
#include <typeinfo>
18+
#endif
1719

1820
namespace boost{ namespace math{ namespace constants{
1921

@@ -22,7 +24,11 @@ namespace boost{ namespace math{ namespace constants{
2224
template <class T>
2325
const char* nameof(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T))
2426
{
27+
#ifndef BOOST_MATH_NO_RTTI
2528
return typeid(T).name();
29+
#else
30+
return "unknown";
31+
#endif
2632
}
2733
template <>
2834
const char* nameof<float>(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(float))

include/boost/math/distributions/landau.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3382,7 +3382,7 @@ BOOST_MATH_GPU_ENABLED inline RealType landau_quantile_lower_imp_prec(const Real
33823382

33833383
// Rational Approximation
33843384
// Maximum Relative Error: 5.3064e-35
3385-
//LCOV_EXCL_START
3385+
// LCOV_EXCL_START
33863386
BOOST_MATH_STATIC const RealType P[14] = {
33873387
BOOST_MATH_BIG_CONSTANT(RealType, 113, -5.09971143249822249471944441552701756051e0),
33883388
BOOST_MATH_BIG_CONSTANT(RealType, 113, -3.00154235169065403254826962372636417554e-2),

include/boost/math/policies/error_handling.hpp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,32 @@
88
#ifndef BOOST_MATH_POLICY_ERROR_HANDLING_HPP
99
#define BOOST_MATH_POLICY_ERROR_HANDLING_HPP
1010

11+
#include <boost/math/policies/policy.hpp>
1112
#include <boost/math/tools/config.hpp>
1213
#include <boost/math/tools/numeric_limits.hpp>
13-
#include <boost/math/tools/type_traits.hpp>
14-
#include <boost/math/tools/cstdint.hpp>
15-
#include <boost/math/tools/tuple.hpp>
16-
#include <boost/math/policies/policy.hpp>
1714
#include <boost/math/tools/precision.hpp>
15+
#include <boost/math/tools/tuple.hpp>
16+
#include <boost/math/tools/type_traits.hpp>
1817

1918
#ifndef BOOST_MATH_HAS_NVRTC
2019

21-
#include <iomanip>
22-
#include <string>
23-
#include <cstring>
24-
#ifndef BOOST_MATH_NO_RTTI
25-
#include <typeinfo>
20+
#ifndef BOOST_MATH_NO_EXCEPTIONS
21+
#include <boost/math/tools/throw_exception.hpp>
2622
#endif
23+
2724
#include <cerrno>
28-
#include <complex>
2925
#include <cmath>
26+
#include <complex>
3027
#include <cstdint>
28+
#include <cstring>
29+
#include <iomanip>
30+
#include <sstream>
3131
#ifndef BOOST_MATH_NO_EXCEPTIONS
3232
#include <stdexcept>
33-
#include <boost/math/tools/throw_exception.hpp>
33+
#endif
34+
#include <string>
35+
#ifndef BOOST_MATH_NO_RTTI
36+
#include <typeinfo>
3437
#endif
3538

3639
#ifdef _MSC_VER
@@ -43,7 +46,6 @@
4346
// Note that this only occurs when the compiler can deduce code is unreachable,
4447
// for example when policy macros are used to ignore errors rather than throw.
4548
#endif
46-
#include <sstream>
4749

4850
namespace boost{ namespace math{
4951

@@ -91,15 +93,20 @@ namespace detail
9193
template <class T>
9294
inline std::string prec_format(const T& val)
9395
{
94-
typedef typename boost::math::policies::precision<T, boost::math::policies::policy<> >::type prec_type;
95-
std::stringstream ss;
96+
using prec_type = typename boost::math::policies::precision<T, boost::math::policies::policy<> >::type;
97+
98+
std::stringstream strm { };
99+
96100
if(prec_type::value)
97101
{
98-
int prec = 2 + (prec_type::value * 30103UL) / 100000UL;
99-
ss << std::setprecision(prec);
102+
const std::streamsize prec { static_cast<std::streamsize>(2UL + (prec_type::value * 30103UL) / 100000UL) };
103+
104+
strm << std::setprecision(prec);
100105
}
101-
ss << val;
102-
return ss.str();
106+
107+
strm << val;
108+
109+
return strm.str();
103110
}
104111

105112
#ifdef BOOST_MATH_USE_CHARCONV_FOR_CONVERSION

include/boost/math/policies/policy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ namespace policies{
132132

133133
#define BOOST_MATH_META_INT(Type, name, Default) \
134134
template <Type N = Default> \
135-
class name : public boost::math::integral_constant<int, N>{}; \
135+
class name : public boost::math::integral_constant<Type, N> { }; \
136136
\
137137
namespace detail{ \
138138
template <Type N> \

include/boost/math/special_functions/bessel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ BOOST_MATH_GPU_ENABLED inline T cyl_neumann_zero_imp(T v, int m, const Policy& p
524524

525525
if(number_of_iterations >= policies::get_max_root_iterations<Policy>())
526526
{
527-
return policies::raise_evaluation_error<T>(function, "Unable to locate root in a reasonable time: Current best guess is %1%", yvm, Policy()); //LCOV_EXCL_LINE
527+
return policies::raise_evaluation_error<T>(function, "Unable to locate root in a reasonable time: Current best guess is %1%", yvm, Policy()); // LCOV_EXCL_LINE
528528
}
529529

530530
return yvm;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ inline std::size_t find_bernoulli_overflow_limit(const std::false_type&)
108108
// Set a limit on how large the result can ever be:
109109
static const auto max_result = static_cast<double>((std::numeric_limits<std::size_t>::max)() - 1000u);
110110

111-
unsigned long long t = lltrunc(boost::math::tools::log_max_value<T>());
111+
unsigned long long t = static_cast<unsigned long long>(lltrunc(boost::math::tools::log_max_value<T>()));
112112
max_bernoulli_root_functor fun(t);
113113
boost::math::tools::equal_floor tol;
114114
std::uintmax_t max_iter = boost::math::policies::get_max_root_iterations<Policy>();
@@ -372,7 +372,7 @@ class bernoulli_numbers_cache
372372
{
373373
for(; n; ++start, --n)
374374
{
375-
*out = b2n_asymptotic<T, Policy>(static_cast<typename container_type::size_type>(start * 2U));
375+
*out = b2n_asymptotic<T, Policy>(static_cast<int>(start * 2U));
376376
++out;
377377
}
378378
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ BOOST_MATH_GPU_ENABLED T bessel_jn(int n, T x, const Policy& pol)
7676
{
7777
prev = bessel_j0(x);
7878
current = bessel_j1(x);
79-
policies::check_series_iterations<T>("boost::math::bessel_j_n<%1%>(%1%,%1%)", n, pol);
79+
policies::check_series_iterations<T>("boost::math::bessel_j_n<%1%>(%1%,%1%)", static_cast<unsigned>(n), pol);
8080
for (int k = 1; k < n; k++)
8181
{
8282
value = (2 * k * current / x) - prev;
@@ -96,7 +96,7 @@ BOOST_MATH_GPU_ENABLED T bessel_jn(int n, T x, const Policy& pol)
9696
prev = fn;
9797
current = 1;
9898
// Check recursion won't go on too far:
99-
policies::check_series_iterations<T>("boost::math::bessel_j_n<%1%>(%1%,%1%)", n, pol);
99+
policies::check_series_iterations<T>("boost::math::bessel_j_n<%1%>(%1%,%1%)", static_cast<unsigned>(n), pol);
100100
for (int k = n; k > 0; k--)
101101
{
102102
T fact = 2 * k / x;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ namespace boost { namespace math {
227227
fi = temp * delta_i + fi * delta_r;
228228
for (k = 2; k < policies::get_max_series_iterations<Policy>(); k++)
229229
{
230-
a = k - 0.5f;
230+
a = static_cast<T>(k) - 0.5f;
231231
a *= a;
232232
a -= v2;
233233
bi += 2;
@@ -291,7 +291,7 @@ namespace boost { namespace math {
291291
*J = *Y = policies::raise_evaluation_error<T>(function, "Order of Bessel function is too large to evaluate: got %1%", v, pol);
292292
return 1; // LCOV_EXCL_LINE previous line will throw.
293293
}
294-
n = iround(v, pol);
294+
n = static_cast<unsigned>(iround(v, pol));
295295
u = v - n; // -1/2 <= u < 1/2
296296

297297
if(reflect)
@@ -361,7 +361,8 @@ namespace boost { namespace math {
361361
// Truncated series evaluation for small x and v an integer,
362362
// much quicker in this area than temme_jy below.
363363
// This code is only used in the multiprecision case, otherwise
364-
// we go via bessel_jn. LCOV_EXCL_START
364+
// we go via bessel_jn.
365+
// LCOV_EXCL_START
365366
if(kind&need_j)
366367
Jv = bessel_j_small_z_series(v, x, pol);
367368
else
@@ -370,7 +371,7 @@ namespace boost { namespace math {
370371
|| (org_kind & need_j && (reflect && (sp != 0))))
371372
{
372373
// Only calculate if we need it, and if the reflection formula will actually use it:
373-
Yv = bessel_yn_small_z(n, x, &Yv_scale, pol);
374+
Yv = bessel_yn_small_z(static_cast<int>(n), x, &Yv_scale, pol);
374375
}
375376
else
376377
Yv = boost::math::numeric_limits<T>::quiet_NaN();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ BOOST_MATH_GPU_ENABLED T bessel_yn_small_z(int n, T z, T* scale, const Policy& p
245245
auto p = static_cast<T>(pow(z / 2, n));
246246
#endif
247247

248-
T result = -((boost::math::factorial<T>(n - 1, pol) / constants::pi<T>()));
248+
T result = -((boost::math::factorial<T>(static_cast<unsigned>(n - 1), pol) / constants::pi<T>()));
249249
if(p * tools::max_value<T>() < fabs(result))
250250
{
251251
T div = tools::max_value<T>() / 8;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ BOOST_MATH_GPU_ENABLED T igamma_temme_large(T a, T x, const Policy& pol, const b
273273
BOOST_MATH_BIG_CONSTANT(T, 64, 0.00640336283380806979482),
274274
BOOST_MATH_BIG_CONSTANT(T, 64, -0.00404101610816766177474),
275275
};
276-
// LCOV_EXCL_END
276+
// LCOV_EXCL_STOP
277277

278278
workspace[12] = tools::evaluate_polynomial(C12, z);
279279

@@ -420,7 +420,7 @@ BOOST_MATH_GPU_ENABLED T igamma_temme_large(T a, T x, const Policy& pol, const b
420420
static_cast<T>(0.00083949872067208728L),
421421
static_cast<T>(-0.00043829709854172101L),
422422
};
423-
// LCOV_EXCL_END
423+
// LCOV_EXCL_STOP
424424
workspace[8] = tools::evaluate_polynomial(C8, z);
425425
workspace[9] = static_cast<T>(-0.00059676129019274625L);
426426

@@ -488,7 +488,7 @@ BOOST_MATH_GPU_ENABLED T igamma_temme_large(T a, T x, const Policy& pol, const b
488488
static_cast<T>(0.000771604938L),
489489
};
490490
workspace[2] = tools::evaluate_polynomial(C2, z);
491-
// LCOV_EXCL_END
491+
// LCOV_EXCL_STOP
492492

493493
T result = tools::evaluate_polynomial(workspace, 1/a);
494494
result *= exp(-y) / sqrt(2 * constants::pi<T>() * a);
@@ -810,7 +810,7 @@ BOOST_MATH_GPU_ENABLED T igamma_temme_large(T a, T x, const Policy& pol, const b
810810

811811
return result;
812812
}
813-
// LCOV_EXCL_END
813+
// LCOV_EXCL_STOP
814814

815815
#endif
816816

0 commit comments

Comments
 (0)