2 ///////////////////////////////////////////////////////////////////////////////
3 // Copyright 2013 Nikhar Agrawal
4 // Copyright 2013 Christopher Kormanyos
5 // Copyright 2013 John Maddock
6 // Copyright 2013 Paul Bristow
7 // Distributed under the Boost
8 // Software License, Version 1.0. (See accompanying file
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef _BOOST_BERNOULLI_B2N_2013_05_30_HPP_
12 #define _BOOST_BERNOULLI_B2N_2013_05_30_HPP_
14 #include <boost/math/special_functions/math_fwd.hpp>
15 #include <boost/math/special_functions/detail/unchecked_bernoulli.hpp>
16 #include <boost/math/special_functions/detail/bernoulli_details.hpp>
18 namespace boost { namespace math {
22 template <class T, class OutputIterator, class Policy, int N>
23 OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std::size_t n, const Policy& pol, const mpl::int_<N>& tag)
25 for(std::size_t i = start; (i <= max_bernoulli_b2n<T>::value) && (i < start + n); ++i)
27 *out = unchecked_bernoulli_imp<T>(i, tag);
31 for(std::size_t i = (std::max)(static_cast<std::size_t>(max_bernoulli_b2n<T>::value + 1), start); i < start + n; ++i)
34 *out = (i & 1 ? 1 : -1) * policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(n)", 0, T(i), pol);
40 template <class T, class OutputIterator, class Policy>
41 OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std::size_t n, const Policy& pol, const mpl::int_<0>& tag)
43 for(std::size_t i = start; (i <= max_bernoulli_b2n<T>::value) && (i < start + n); ++i)
45 *out = unchecked_bernoulli_imp<T>(i, tag);
49 // Short circuit return so we don't grab the mutex below unless we have to:
51 if(start + n <= max_bernoulli_b2n<T>::value)
54 return get_bernoulli_numbers_cache<T, Policy>().copy_bernoulli_numbers(out, start, n, pol);
59 template <class T, class Policy>
60 inline T bernoulli_b2n(const int i, const Policy &pol)
62 typedef mpl::int_<detail::bernoulli_imp_variant<T>::value> tag_type;
64 return policies::raise_domain_error<T>("boost::math::bernoulli_b2n<%1%>", "Index should be >= 0 but got %1%", T(i), pol);
66 T result = static_cast<T>(0); // The = 0 is just to silence compiler warnings :-(
67 boost::math::detail::bernoulli_number_imp<T>(&result, static_cast<std::size_t>(i), 1u, pol, tag_type());
72 inline T bernoulli_b2n(const int i)
74 return boost::math::bernoulli_b2n<T>(i, policies::policy<>());
77 template <class T, class OutputIterator, class Policy>
78 inline OutputIterator bernoulli_b2n(const int start_index,
79 const unsigned number_of_bernoullis_b2n,
80 OutputIterator out_it,
83 typedef mpl::int_<detail::bernoulli_imp_variant<T>::value> tag_type;
86 *out_it = policies::raise_domain_error<T>("boost::math::bernoulli_b2n<%1%>", "Index should be >= 0 but got %1%", T(start_index), pol);
90 return boost::math::detail::bernoulli_number_imp<T>(out_it, start_index, number_of_bernoullis_b2n, pol, tag_type());
93 template <class T, class OutputIterator>
94 inline OutputIterator bernoulli_b2n(const int start_index,
95 const unsigned number_of_bernoullis_b2n,
96 OutputIterator out_it)
98 return boost::math::bernoulli_b2n<T, OutputIterator>(start_index, number_of_bernoullis_b2n, out_it, policies::policy<>());
101 template <class T, class Policy>
102 inline T tangent_t2n(const int i, const Policy &pol)
105 return policies::raise_domain_error<T>("boost::math::tangent_t2n<%1%>", "Index should be >= 0 but got %1%", T(i), pol);
108 boost::math::detail::get_bernoulli_numbers_cache<T, Policy>().copy_tangent_numbers(&result, i, 1, pol);
113 inline T tangent_t2n(const int i)
115 return boost::math::tangent_t2n<T>(i, policies::policy<>());
118 template <class T, class OutputIterator, class Policy>
119 inline OutputIterator tangent_t2n(const int start_index,
120 const unsigned number_of_tangent_t2n,
121 OutputIterator out_it,
126 *out_it = policies::raise_domain_error<T>("boost::math::tangent_t2n<%1%>", "Index should be >= 0 but got %1%", T(start_index), pol);
130 return boost::math::detail::get_bernoulli_numbers_cache<T, Policy>().copy_tangent_numbers(out_it, start_index, number_of_tangent_t2n, pol);
133 template <class T, class OutputIterator>
134 inline OutputIterator tangent_t2n(const int start_index,
135 const unsigned number_of_tangent_t2n,
136 OutputIterator out_it)
138 return boost::math::tangent_t2n<T, OutputIterator>(start_index, number_of_tangent_t2n, out_it, policies::policy<>());
141 } } // namespace boost::math
143 #endif // _BOOST_BERNOULLI_B2N_2013_05_30_HPP_