diff --git a/doc/constants/constants.qbk b/doc/constants/constants.qbk index 4424ac104..d095860df 100644 --- a/doc/constants/constants.qbk +++ b/doc/constants/constants.qbk @@ -70,7 +70,7 @@ You can see the full list of available constants at [link math_toolkit.constants Some examples of using constants are at [@../../example/constants_eg1.cpp constants_eg1]. -[endsect] +[endsect] [/section:non_templ Use in non-template code] [section:templ Use in template code] @@ -379,10 +379,12 @@ This section lists the mathematical constants, their use(s) (and sometimes ratio ] [/table] -[note Integer values are *not included* in this list of math constants, however interesting, +[note Integer values are [*not included] in this list of math constants, however interesting, because they can be so easily and exactly constructed, even for UDT, for example: `static_cast(42)`.] [tip If you know the approximate value of the constant, you can search for the value to find Boost.Math chosen name in this table.] +[tip Bernoulli numbers are available at __bernoulli_numbers.] +[tip Factorials are available at __factorial.] [endsect] [/section:constants The constants] diff --git a/doc/equations/bernoulli_numbers.mml b/doc/equations/bernoulli_numbers.mml new file mode 100644 index 000000000..e250e076f --- /dev/null +++ b/doc/equations/bernoulli_numbers.mml @@ -0,0 +1,52 @@ + + + + + B + j + + = + + + + + 1 + + + + + j + 2 + + + 1 + + + + + j + + T + + j + / + 2 + + + + + + + 4 + j + + + + 2 + j + + + + + + \ No newline at end of file diff --git a/doc/equations/bernoulli_numbers.png b/doc/equations/bernoulli_numbers.png new file mode 100644 index 000000000..bb4353612 Binary files /dev/null and b/doc/equations/bernoulli_numbers.png differ diff --git a/doc/equations/bernoulli_numbers.svg b/doc/equations/bernoulli_numbers.svg new file mode 100644 index 000000000..e1963536f --- /dev/null +++ b/doc/equations/bernoulli_numbers.svg @@ -0,0 +1,341 @@ + + + + + + + + + image/svg+xml + + + + + B + + j + + + = + + + + ( + + + + + + + 1 + + + + ) + + + + + j + + + 2 + + + + + + + + 1 + + + + + + j + + T + + j + + / + + + 2 + + + + + + + ( + + + 4 + + j + + + + + + 2 + + j + + + + + ) + + + + + diff --git a/doc/equations/tangent_numbers.mml b/doc/equations/tangent_numbers.mml new file mode 100644 index 000000000..5d5d8e244 --- /dev/null +++ b/doc/equations/tangent_numbers.mml @@ -0,0 +1,57 @@ + + + + + + T + j + + = + + + + + 1 + + + + j + + 1 + + + + 2 + + 2 + j + + + + + + 2 + + 2 + n + + + + 1 + + + + + B + + 2 + n + + + + 2 + n + + + + \ No newline at end of file diff --git a/doc/equations/tangent_numbers.png b/doc/equations/tangent_numbers.png new file mode 100644 index 000000000..c82fb438e Binary files /dev/null and b/doc/equations/tangent_numbers.png differ diff --git a/doc/equations/tangent_numbers.svg b/doc/equations/tangent_numbers.svg new file mode 100644 index 000000000..455838832 --- /dev/null +++ b/doc/equations/tangent_numbers.svg @@ -0,0 +1,2 @@ + +Tj=(1)j122j(22n1)B2n2n \ No newline at end of file diff --git a/doc/internals/roots.qbk b/doc/internals/roots.qbk index 662092519..36a6faf5e 100644 --- a/doc/internals/roots.qbk +++ b/doc/internals/roots.qbk @@ -1,4 +1,4 @@ - [section:roots Root Finding With Derivatives: Newton-Raphson, Halley & Schroeder] +[section:roots Root Finding With Derivatives: Newton-Raphson, Halley & Schroeder] [h4 Synopsis] diff --git a/doc/math.qbk b/doc/math.qbk index 7356fb92b..eb233b79b 100644 --- a/doc/math.qbk +++ b/doc/math.qbk @@ -1,13 +1,13 @@ [book Math Toolkit [quickbook 1.6] - [copyright 2006, 2007, 2008, 2009, 2010, 2012, 2013 Paul A. Bristow, Christopher Kormanyos, Hubert Holin, Bruno Lalande, John Maddock, Johan Råde, Gautam Sewani, Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang] + [copyright 2006, 2007, 2008, 2009, 2010, 2012, 2013 Paul A. Bristow, Christopher Kormanyos, Hubert Holin, Bruno Lalande, John Maddock, Johan Råde, Gautam Sewani, Benjamin Sobotta, Thijs van den Berg, Daryle Walker, Xiaogang Zhang and Nikhar Agrawal] [/purpose ISBN 0-9504833-2-X 978-0-9504833-2-0, Classification 519.2-dc22] [license Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at [@http://www.boost.org/LICENSE_1_0.txt]) ] - [authors [Bristow, Paul A.], [Holin, Hubert], [Kormanyos, Christopher], [Lalande, Bruno], [Maddock, John], [Råde, Johan], [Sobotta, Benjamin], [Sewani, Gautam], [van den Berg, Thijs], [Walker, Daryle], [Zhang, Xiaogang] ] + [authors [Bristow, Paul A.], [Holin, Hubert], [Kormanyos, Christopher], [Lalande, Bruno], [Maddock, John], [Råde, Johan], [Sobotta, Benjamin], [Sewani, Gautam], [van den Berg, Thijs], [Walker, Daryle], [Zhang, Xiaogang], [Agrawal, Nikhar]] [/last-revision $Date$] [version 1.8.3] ] @@ -149,6 +149,9 @@ and use the function's name as the link text.] [def __ellint_2 [link math_toolkit.ellint.ellint_2 ellint_2]] [def __ellint_3 [link math_toolkit.ellint.ellint_3 ellint_3]] +[/ Bernoulli functions and numbers] +[def __bernoulli_numbers [link math_toolkit.bernoulli.bernoulli_numbers bernoulli_numbers]] + [/Bessel functions] [def __cyl_bessel_j [link math_toolkit.bessel.bessel_first cyl_bessel_j]] [def __cyl_neumann [link math_toolkit.bessel.bessel_first cyl_neumann]] @@ -385,6 +388,7 @@ using the quantile function on the [NAME] distribution. The describe how to change the rounding policy for these distributions. ] [/ caution] + ] [/ template discrete_quantile_warning] [block '''''' @@ -444,6 +448,8 @@ and as a CD ISBN 0-9504833-2-X 978-0-9504833-2-0, Classification 519.2-dc22. [include sf/factorials.qbk] +[include sf/bernoulli_numbers.qbk] + [section:sf_beta Beta Functions] [include sf/beta.qbk] [include sf/ibeta.qbk] @@ -583,7 +589,7 @@ and as a CD ISBN 0-9504833-2-X 978-0-9504833-2-0, Classification 519.2-dc22. [endmathpart] [/ math.qbk - Copyright 2008, 2010, 2012, 2013 John Maddock and Paul A. Bristow. + Copyright 2008, 2010, 2012, 2013, 2014 John Maddock and Paul A. Bristow. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). diff --git a/doc/overview/common_overviews.qbk b/doc/overview/common_overviews.qbk index b1e1253cf..bf10defd3 100644 --- a/doc/overview/common_overviews.qbk +++ b/doc/overview/common_overviews.qbk @@ -205,7 +205,8 @@ regression tests: cd into boost-root/libs/math/test and do a: bjam mytoolset where "mytoolset" is the name of the -[@../../../../tools/build/index.html Boost.Build] toolset used for your +[@http://www.boost.org/doc/html/bbv2.html Boost.Build] +toolset used for your compiler. The chances are that [*many of the accuracy tests will fail at this stage] - don't panic - the default acceptable error tolerances are quite tight, especially for long double types with an extended @@ -216,8 +217,8 @@ the failing tests and make a judgement as to whether the error rates are acceptable or not. ] -[/ math.qbk - Copyright 2007, 2012 John Maddock and Paul A. Bristow. +[/ common_overviews.qbk + Copyright 2007, 2012, 2014 John Maddock and Paul A. Bristow. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). diff --git a/doc/sf/bernoulli_numbers.qbk b/doc/sf/bernoulli_numbers.qbk new file mode 100644 index 000000000..6ef84ae5f --- /dev/null +++ b/doc/sf/bernoulli_numbers.qbk @@ -0,0 +1,207 @@ +[section:bernoulli_numbers Bernoulli Numbers] + +[@https://en.wikipedia.org/wiki/Bernoulli_number Bernoulli numbers] +are a sequence of rational numbers useful for the Taylor series expansion, +Euler-Maclaurin formula, and the Riemann zeta function. + +Bernoulli numbers are used in evaluation of some Boost.Math functions, +including the __tgamma, __lgamma and polygamma functions. + +[h4 Single Bernoulli number] + +[h4 Synopsis] + +`` +#include +`` + + namespace boost { namespace math { + + template + T bernoulli_b2n(const int i); // Single Bernoulli number (default policy). + + template + T bernoulli_b2n(const int i, const Policy &pol); // User policy for errors etc. + + }} // namespaces + +[h4 Description] + +Both return the (2 * i)[super th] Bernoulli number. + +The final __Policy argument is optional and can be used to control the behaviour of the function: +how it handles errors, what level of precision to use, etc. + +Refer to __policy_section for more details. + +[h4 Examples] + +[import ../../example/bernoulli_example.cpp] +[bernoulli_example_1] + +[bernoulli_output_1] + +[h4 Single (unchecked) Bernoulli number] + +[h4 Synopsis] +`` +#include + +`` + + template + inline T unchecked_bernoulli_b2n(unsigned n); + +`unchecked_bernoulli_b2n` provides access to Bernoulli numbers [*without any checks for overflow or invalid parameters]. +(Not recommended for normal use, but bypassing overflow checks is quicker.) + + template <> + struct max_bernoulli_index::value + +The largest value you can (without overflow) pass to `unchecked_bernoulli_b2n<>` +is `max_bernoulli_b2n<>::value`. + +For example, `boost::math::max_bernoulli_b2n::value` is 129. + +[h4 Multiple Bernoulli Numbers] + +[h4 Synopsis] + +`` +#include +`` + + namespace boost { namespace math { + + // Multiple Bernoulli numbers (default policy). + template + OutputIterator bernoulli_b2n( + int start_index, + unsigned number_of_bernoullis_b2n, + OutputIterator out_it); + + // Multiple Bernoulli numbers (user policy). + template + OutputIterator bernoulli_b2n( + int start_index, + unsigned number_of_bernoullis_b2n, + OutputIterator out_it, + const Policy& pol); + }} // namespaces + +[h4 Description] + +Two versions of the Bernoulli number function are provided to compute multiple Bernoulli numbers +with one call (one with default policy and the other allowing a user-defined policy). + +These return a series of Bernoulli numbers: + + Bernoulli(2*start_index), + Bernoulli(2*(start_index+1)) + ... + Bernoulli(2*(number_of_bernoullis_b2n-1)) + +[h4 Examples] +[bernoulli_example_2] +[bernoulli_output_2] +[bernoulli_example_3] +[bernoulli_output_3] +[bernoulli_example_4] +[bernoulli_output_4] + +The source of this example is at [../../example/bernoulli_example.cpp bernoulli_example.cpp] + +[h4 Accuracy] + +All the functions usually return values within one ULP (unit in the last place) for the floating-point type. + +[h4 Implementation] + +The implementation details are in [@../../include/boost/math/special_functions/detail/bernoulli_details.hpp bernoulli_details.hpp]. + +For `i <= max_bernoulli_index::value` this is implemented by table lookup; +for larger values of `i`, this is implemented by the Tangent Numbers algorithm as described in the paper: +Fast Computation of Bernoulli, Tangent and Secant Numbers, Richard P. Brent and David Harvey, +[@http://arxiv.org/pdf/1108.0286v3.pdf] (2011). + +[@http://mathworld.wolfram.com/TangentNumber.html Tangent (or Zag) numbers] +(an even alternating permutation number) are defined +and their generating function is also given therein. + + [/@http://mathworld.wolfram.com/images/equations/TangentNumber/Inline15.gif] + +The relation of Tangent numbers with Bernoulli numbers ['B[sub i]] +is given by Brent and Harvey's equation 14: + +__spaces[equation tangent_numbers] + +Their relation with Bernoulli numbers ['B[sub i]] are defined by + +if i > 0 and i is even then +__spaces[equation bernoulli_numbers] [br] +elseif i == 0 then ['B[sub i]] = 1 [br] +elseif i == 1 then ['B[sub i]] = -1/2 [br] +elseif i < 0 or i is odd then ['B[sub i]] = 0 + +[/@http://s7.postimg.org/mygi2kror/bernoulli_1.png] + +[endsect] [/section:bernoulli_numbers Bernoulli Numbers] + + +[section:tangent_numbers Tangent Numbers] + +[@http://en.wikipedia.org/wiki/Tangent_numbers Tangent numbers], +also called a zag function. See also +[@http://mathworld.wolfram.com/TangentNumber.html Tangent number]. + +From the number, An, of alternating permutations of the set {1, ..., n}, +the numbers A2n+1 with odd indices are called tangent numbers or zag numbers. +The first few values are 1, 2, 16, 272, 7936, 353792, 22368256, 1903757312 ... +(sequence [@http://oeis.org/A000182 A000182 in OEIS]). +They are called tangent numbers because they appear as +numerators in the Maclaurin series of tan x. + +Tangent numbers are used in the computation of Bernoulli numbers, +but are also made available here. + +[h4 Synopsis] +`` +#include +`` + + template + T tangent_t2n(const int i); // Single tangent number (default policy). + + template + T tangent_t2n(const int i, const Policy &pol); // Single tangent number (user policy). + + // Multiple tangent numbers (default policy). + template + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_tangent_t2n, + OutputIterator out_it); + + // Multiple tangent numbers (user policy). + template + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_tangent_t2n, + OutputIterator out_it, + const Policy& pol); + +[h4 Examples] + +[tangent_example_1] + +The output is: +[tangent_output_1] + +The source of this example is at [../../example/bernoulli_example.cpp bernoulli_example.cpp] + +[endsect] [/section:tangent_numbers Tangent Numbers] + +[/ + Copyright 2013, 2014 Nikhar Agrawal, Christopher Kormanyos, John Maddock, Paul A. Bristow. + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +] diff --git a/example/bernoulli_example.cpp b/example/bernoulli_example.cpp new file mode 100644 index 000000000..ed373c6fe --- /dev/null +++ b/example/bernoulli_example.cpp @@ -0,0 +1,210 @@ +// Copyright Paul A. Bristow 2013. +// Copyright Nakhar Agrawal 2013. +// Copyright John Maddock 2013. +// Copyright Christopher Kormanyos 2013. + +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#pragma warning (disable : 4100) // unreferenced formal parameter. +#pragma warning (disable : 4127) // conditional expression is constant. + +//#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error + +#include +#include + +#include + +/* First 50 from 2 to 100 inclusive: */ +/* TABLE[N[BernoulliB[n], 200], {n,2,100,2}] */ + +//SC_(0.1666666666666666666666666666666666666666), +//SC_(-0.0333333333333333333333333333333333333333), +//SC_(0.0238095238095238095238095238095238095238), +//SC_(-0.0333333333333333333333333333333333333333), +//SC_(0.0757575757575757575757575757575757575757), +//SC_(-0.2531135531135531135531135531135531135531), +//SC_(1.1666666666666666666666666666666666666666), +//SC_(-7.0921568627450980392156862745098039215686), +//SC_(54.9711779448621553884711779448621553884711), + +int main() +{ + //[bernoulli_example_1 + +/*`A simple example computes the value of `Bernoulli(2)` where the return type is `double`. + + +*/ + try + { // It is always wise to use try'n'catch blocks around Boost.Math functions + // so that any informative error messages can be displayed in the catch block. + std::cout + << std::setprecision(std::numeric_limits::digits10) + << boost::math::bernoulli_b2n(2) << std::endl; + +/*`So B[sub 4] == -1/30 == -0.0333333333333333 + +If we use Boost.Multiprecision and its 50 decimal digit floating-point type `cpp_dec_float_50`, +we can calculate the value of much larger numbers like `Bernoulli(100)` +and also obtain much higher precision. +*/ + + std::cout + << std::setprecision(std::numeric_limits::digits10) + << boost::math::bernoulli_b2n(100) << std::endl; + +//] //[/bernoulli_example_1] + +//[bernoulli_example_2 +/*`We can compute and save all the float-precision Bernoulli numbers from one call. +*/ + std::vector bn; // Space for 32-bit `float` precision Bernoulli numbers. + + // Start with Bernoulli number 0. + boost::math::bernoulli_b2n(0, 32, std::back_inserter(bn)); // Fill vector with even Bernoulli numbers. + + for(size_t i = 0; i < bn.size(); i++) + { // Show vector of even Bernoulli numbers, showing all significant decimal digits. + std::cout << std::setprecision(std::numeric_limits::digits10) + << i*2 << ' ' + << bn[i] + << std::endl; + } +//] //[/bernoulli_example_2] + + } + catch(const std::exception& ex) + { + std::cout << "Thrown Exception caught: " << ex.what() << std::endl; + } + + +//[bernoulli_example_3 +/*`Of course, for any floating-point type, there is a maximum Bernoulli number that can be computed + before it overflows the exponent. + By default policy, if we try to compute too high a Bernoulli number, an exception will be thrown. +*/ + try + { + std::cout + << std::setprecision(std::numeric_limits::digits10) + << "Bernoulli number " << 33 * 2 <(33) << std::endl; + } + catch (std::exception ex) + { + std::cout << "Thrown Exception caught: " << ex.what() << std::endl; + } + +/*` +and we will get a helpful error message (provided try'n'catch blocks are used). +*/ + +//] //[/bernoulli_example_3] + +//[bernoulli_example_4 +/*`Users can determine from `max_bernoulli_b2n<>::value` +the largest Bernoulli number you can evaluate for any type +(or safely pass to `unchecked_bernoulli_b2n<>`). + +For example: +*/ + std::cout << "boost::math::max_bernoulli_b2n::value = " << boost::math::max_bernoulli_b2n::value << std::endl; + std::cout << "Maximum Bernoulli number using float is " << boost::math::bernoulli_b2n( boost::math::max_bernoulli_b2n::value) << std::endl; + std::cout << "boost::math::max_bernoulli_b2n::value = " << boost::math::max_bernoulli_b2n::value << std::endl; + std::cout << "Maximum Bernoulli number using double is " << boost::math::bernoulli_b2n( boost::math::max_bernoulli_b2n::value) << std::endl; + //] //[/bernoulli_example_4] + +//[tangent_example_1 + +/*`We can compute and save a few Tangent numbers. +*/ + std::vector tn; // Space for some `float` precision Tangent numbers. + + // Start with Bernoulli number 0. + boost::math::tangent_t2n(1, 6, std::back_inserter(tn)); // Fill vector with even Tangent numbers. + + for(size_t i = 0; i < tn.size(); i++) + { // Show vector of even Tangent numbers, showing all significant decimal digits. + std::cout << std::setprecision(std::numeric_limits::digits10) + << " " + << tn[i]; + } + std::cout << std::endl; + +//] [/tangent_example_1] + +// 1, 2, 16, 272, 7936, 353792, 22368256, 1903757312 + + + +} // int main() + +/* + +//[bernoulli_output_1 + -3.6470772645191354362138308865549944904868234686191e+215 +//] //[/bernoulli_output_1] + +//[bernoulli_output_2 + + 0 1 + 2 0.166667 + 4 -0.0333333 + 6 0.0238095 + 8 -0.0333333 + 10 0.0757576 + 12 -0.253114 + 14 1.16667 + 16 -7.09216 + 18 54.9712 + 20 -529.124 + 22 6192.12 + 24 -86580.3 + 26 1.42552e+006 + 28 -2.72982e+007 + 30 6.01581e+008 + 32 -1.51163e+010 + 34 4.29615e+011 + 36 -1.37117e+013 + 38 4.88332e+014 + 40 -1.92966e+016 + 42 8.41693e+017 + 44 -4.03381e+019 + 46 2.11507e+021 + 48 -1.20866e+023 + 50 7.50087e+024 + 52 -5.03878e+026 + 54 3.65288e+028 + 56 -2.84988e+030 + 58 2.38654e+032 + 60 -2.14e+034 + 62 2.0501e+036 +//] //[/bernoulli_output_2] + +//[bernoulli_output_3 + Bernoulli number 66 + Thrown Exception caught: Error in function boost::math::bernoulli_b2n(n): + Overflow evaluating function at 33 +//] //[/bernoulli_output_3] +//[bernoulli_output_4 + boost::math::max_bernoulli_b2n::value = 32 + Maximum Bernoulli number using float is -2.0938e+038 + boost::math::max_bernoulli_b2n::value = 129 + Maximum Bernoulli number using double is 1.33528e+306 +//] //[/bernoulli_output_4] + + +//[tangent_output_1 + 1 2 16 272 7936 353792 +//] [/tangent_output_1] + + + +*/ + + diff --git a/include/boost/math/policies/error_handling.hpp b/include/boost/math/policies/error_handling.hpp index e7dbb4020..3e8efb982 100644 --- a/include/boost/math/policies/error_handling.hpp +++ b/include/boost/math/policies/error_handling.hpp @@ -249,6 +249,31 @@ template inline T raise_overflow_error( const char* , const char* , + const T&, + const ::boost::math::policies::overflow_error< ::boost::math::policies::ignore_error>&) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + return std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : boost::math::tools::max_value(); +} + +template +inline T raise_overflow_error( + const char* , + const char* , + const ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>&) +{ + errno = ERANGE; + // This may or may not do the right thing, but the user asked for the error + // to be silent so here we go anyway: + return std::numeric_limits::has_infinity ? std::numeric_limits::infinity() : boost::math::tools::max_value(); +} + +template +inline T raise_overflow_error( + const char* , + const char* , + const T&, const ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>&) { errno = ERANGE; @@ -266,6 +291,23 @@ inline T raise_overflow_error( return user_overflow_error(function, message, std::numeric_limits::infinity()); } +template +inline T raise_overflow_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::overflow_error< ::boost::math::policies::user_error>&) +{ + std::string fmsg("Error in function "); +#ifndef BOOST_NO_RTTI + fmsg += (boost::format(function) % typeid(T).name()).str(); +#else + fmsg += function; +#endif + int prec = 2 + (boost::math::policies::digits >() * 30103UL) / 100000UL; + std::string msg = do_format(boost::format(message), boost::io::group(std::setprecision(prec), val)); + return user_overflow_error(fmsg.c_str(), msg.c_str(), std::numeric_limits::infinity()); +} template inline T raise_underflow_error( diff --git a/include/boost/math/special_functions/bernoulli.hpp b/include/boost/math/special_functions/bernoulli.hpp index b283ff938..b2feae3a0 100644 --- a/include/boost/math/special_functions/bernoulli.hpp +++ b/include/boost/math/special_functions/bernoulli.hpp @@ -30,7 +30,7 @@ OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std:: for(std::size_t i = (std::max)(static_cast(max_bernoulli_b2n::value + 1), start); i < start + n; ++i) { // We must overflow: - *out = (i & 1 ? 1 : -1) * policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(n)", 0, pol); + *out = (i & 1 ? 1 : -1) * policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(n)", 0, T(i), pol); ++out; } return out; diff --git a/include/boost/math/special_functions/detail/bernoulli_details.hpp b/include/boost/math/special_functions/detail/bernoulli_details.hpp index d57043697..e3a69d27d 100644 --- a/include/boost/math/special_functions/detail/bernoulli_details.hpp +++ b/include/boost/math/special_functions/detail/bernoulli_details.hpp @@ -86,7 +86,7 @@ T b2n_asymptotic(int n) + (((T(3) / 2) - nx) * boost::math::constants::ln_two()) + ((nx * (T(2) - (nx2 * 7) * (1 + ((nx2 * 30) * ((nx2 * 12) - 1))))) / (((nx2 * nx2) * nx2) * 2520)); return ((n / 2) & 1 ? 1 : -1) * (approximate_log_of_bernoulli_bn > tools::log_max_value() - ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, Policy()) + ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, nx, Policy()) : exp(approximate_log_of_bernoulli_bn)); } @@ -98,7 +98,7 @@ T t2n_asymptotic(int n) T t2n = fabs(b2n_asymptotic(2 * n)) / (2 * n); T p2 = ldexp(T(1), n); if(tools::max_value() / p2 < t2n) - return policies::raise_overflow_error("boost::math::tangent_t2n<%1%>(std::size_t)", 0, Policy()); + return policies::raise_overflow_error("boost::math::tangent_t2n<%1%>(std::size_t)", 0, T(n), Policy()); t2n *= p2; p2 -= 1; if(tools::max_value() / p2 < t2n) @@ -420,7 +420,7 @@ public: } for(; n; ++start, --n) { - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(start), pol); ++out; } return out; @@ -437,7 +437,7 @@ public: for(std::size_t i = (std::max)(max_bernoulli_b2n::value + 1, start); i < start + n; ++i) { - *out = (i >= m_overflow_limit) ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol) : bn[i]; + *out = (i >= m_overflow_limit) ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol) : bn[i]; ++out; } #elif defined(BOOST_MATH_NO_ATOMIC_INT) @@ -453,7 +453,7 @@ public: for(std::size_t i = (std::max)(max_bernoulli_b2n::value + 1, start); i < start + n; ++i) { - *out = (i >= m_overflow_limit) ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol) : bn[i]; + *out = (i >= m_overflow_limit) ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol) : bn[i]; ++out; } @@ -481,7 +481,7 @@ public: for(std::size_t i = (std::max)(static_cast(max_bernoulli_b2n::value + 1), start); i < start + n; ++i) { - *out = (i >= m_overflow_limit) ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol) : bn[static_cast(i)]; + *out = (i >= m_overflow_limit) ? policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol) : bn[static_cast(i)]; ++out; } @@ -523,7 +523,7 @@ public: } for(; n; ++start, --n) { - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(start), pol); ++out; } return out; @@ -541,11 +541,11 @@ public: for(std::size_t i = start; i < start + n; ++i) { if(i >= m_overflow_limit) - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol); else { if(tools::max_value() * tangent_scale_factor() < tn[static_cast(i)]) - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol); else *out = tn[static_cast(i)] / tangent_scale_factor(); } @@ -565,11 +565,11 @@ public: for(std::size_t i = start; i < start + n; ++i) { if(i >= m_overflow_limit) - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol); else { if(tools::max_value() * tangent_scale_factor() < tn[static_cast(i)]) - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol); else *out = tn[static_cast(i)] / tangent_scale_factor(); } @@ -601,11 +601,11 @@ public: for(std::size_t i = start; i < start + n; ++i) { if(i >= m_overflow_limit) - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol); else { if(tools::max_value() * tangent_scale_factor() < tn[static_cast(i)]) - *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, pol); + *out = policies::raise_overflow_error("boost::math::bernoulli_b2n<%1%>(std::size_t)", 0, T(i), pol); else *out = tn[static_cast(i)] / tangent_scale_factor(); }