brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · 102b493 Raw
150 lines · plain
1 2///////////////////////////////////////////////////////////////////////////////3//  Copyright 2013 Nikhar Agrawal4//  Copyright 2013 Christopher Kormanyos5//  Copyright 2013 John Maddock6//  Copyright 2013 Paul Bristow7//  Distributed under the Boost8//  Software License, Version 1.0. (See accompanying file9//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)10 11#ifndef _BOOST_BERNOULLI_B2N_2013_05_30_HPP_12#define _BOOST_BERNOULLI_B2N_2013_05_30_HPP_13 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>17 18namespace boost { namespace math {19 20namespace detail {21 22template <class T, class OutputIterator, class Policy, int N>23OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std::size_t n, const Policy& pol, const std::integral_constant<int, N>& tag)24{25   for(std::size_t i = start; (i <= max_bernoulli_b2n<T>::value) && (i < start + n); ++i)26   {27      *out = unchecked_bernoulli_imp<T>(i, tag);28      ++out;29   }30 31   for(std::size_t i = (std::max)(static_cast<std::size_t>(max_bernoulli_b2n<T>::value + 1), start); i < start + n; ++i)32   {33      // We must overflow:34      *out = (i & 1 ? 1 : -1) * policies::raise_overflow_error<T>("boost::math::bernoulli_b2n<%1%>(n)", nullptr, T(i), pol);35      ++out;36   }37   return out;38}39 40template <class T, class OutputIterator, class Policy>41OutputIterator bernoulli_number_imp(OutputIterator out, std::size_t start, std::size_t n, const Policy& pol, const std::integral_constant<int, 0>& tag)42{43   for(std::size_t i = start; (i <= max_bernoulli_b2n<T>::value) && (i < start + n); ++i)44   {45      *out = unchecked_bernoulli_imp<T>(i, tag);46      ++out;47   }48   //49   // Short circuit return so we don't grab the mutex below unless we have to:50   //51   if(start + n <= max_bernoulli_b2n<T>::value)52   {53      return out;54   }55 56   return get_bernoulli_numbers_cache<T, Policy>().copy_bernoulli_numbers(out, start, n, pol);57}58 59} // namespace detail60 61template <class T, class Policy>62inline T bernoulli_b2n(const int i, const Policy &pol)63{64   using tag_type = std::integral_constant<int, detail::bernoulli_imp_variant<T>::value>;65   if(i < 0)66   {67      return policies::raise_domain_error<T>("boost::math::bernoulli_b2n<%1%>", "Index should be >= 0 but got %1%", T(i), pol);68   }69 70   T result {};71   boost::math::detail::bernoulli_number_imp<T>(&result, static_cast<std::size_t>(i), 1u, pol, tag_type());72   return result;73}74 75template <class T>76inline T bernoulli_b2n(const int i)77{78   return boost::math::bernoulli_b2n<T>(i, policies::policy<>());79}80 81template <class T, class OutputIterator, class Policy>82inline OutputIterator bernoulli_b2n(const int start_index,83                                    const unsigned number_of_bernoullis_b2n,84                                    OutputIterator out_it,85                                    const Policy& pol)86{87   using tag_type = std::integral_constant<int, detail::bernoulli_imp_variant<T>::value>;88   if(start_index < 0)89   {90      *out_it = policies::raise_domain_error<T>("boost::math::bernoulli_b2n<%1%>", "Index should be >= 0 but got %1%", T(start_index), pol);91      return ++out_it; // LCOV_EXCL_LINE we don't reach here, previous line throws.92   }93 94   return boost::math::detail::bernoulli_number_imp<T>(out_it, start_index, number_of_bernoullis_b2n, pol, tag_type());95}96 97template <class T, class OutputIterator>98inline OutputIterator bernoulli_b2n(const int start_index,99                                    const unsigned number_of_bernoullis_b2n,100                                    OutputIterator out_it)101{102   return boost::math::bernoulli_b2n<T, OutputIterator>(start_index, number_of_bernoullis_b2n, out_it, policies::policy<>());103}104 105template <class T, class Policy>106inline T tangent_t2n(const int i, const Policy &pol)107{108   if(i < 0)109   {110      return policies::raise_domain_error<T>("boost::math::tangent_t2n<%1%>", "Index should be >= 0 but got %1%", T(i), pol);111   }112 113   T result {};114   boost::math::detail::get_bernoulli_numbers_cache<T, Policy>().copy_tangent_numbers(&result, i, 1, pol);115   return result;116}117 118template <class T>119inline T tangent_t2n(const int i)120{121   return boost::math::tangent_t2n<T>(i, policies::policy<>());122}123 124template <class T, class OutputIterator, class Policy>125inline OutputIterator tangent_t2n(const int start_index,126                                    const unsigned number_of_tangent_t2n,127                                    OutputIterator out_it,128                                    const Policy& pol)129{130   if(start_index < 0)131   {132      *out_it = policies::raise_domain_error<T>("boost::math::tangent_t2n<%1%>", "Index should be >= 0 but got %1%", T(start_index), pol);133      return ++out_it; // LCOV_EXCL_LINE we don't reach here, previous line throws.134   }135 136   return boost::math::detail::get_bernoulli_numbers_cache<T, Policy>().copy_tangent_numbers(out_it, start_index, number_of_tangent_t2n, pol);137}138 139template <class T, class OutputIterator>140inline OutputIterator tangent_t2n(const int start_index,141                                    const unsigned number_of_tangent_t2n,142                                    OutputIterator out_it)143{144   return boost::math::tangent_t2n<T, OutputIterator>(start_index, number_of_tangent_t2n, out_it, policies::policy<>());145}146 147} } // namespace boost::math148 149#endif // _BOOST_BERNOULLI_B2N_2013_05_30_HPP_150