Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:20

0001 
0002 ///////////////////////////////////////////////////////////////////////////////
0003 //  Copyright 2013 Nikhar Agrawal
0004 //  Copyright 2013 Christopher Kormanyos
0005 //  Copyright 2014 John Maddock
0006 //  Copyright 2013 Paul Bristow
0007 //  Distributed under the Boost
0008 //  Software License, Version 1.0. (See accompanying file
0009 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef _BOOST_POLYGAMMA_2013_07_30_HPP_
0012   #define _BOOST_POLYGAMMA_2013_07_30_HPP_
0013 
0014 #include <boost/math/special_functions/factorials.hpp>
0015 #include <boost/math/special_functions/detail/polygamma.hpp>
0016 #include <boost/math/special_functions/trigamma.hpp>
0017 
0018 namespace boost { namespace math {
0019 
0020   
0021   template<class T, class Policy>
0022   inline typename tools::promote_args<T>::type polygamma(const int n, T x, const Policy& pol)
0023   {
0024      //
0025      // Filter off special cases right at the start:
0026      //
0027      if(n == 0)
0028         return boost::math::digamma(x, pol);
0029      if(n == 1)
0030         return boost::math::trigamma(x, pol);
0031      //
0032      // We've found some standard library functions to misbehave if any FPU exception flags
0033      // are set prior to their call, this code will clear those flags, then reset them
0034      // on exit:
0035      //
0036      BOOST_FPU_EXCEPTION_GUARD
0037      //
0038      // The type of the result - the common type of T and U after
0039      // any integer types have been promoted to double:
0040      //
0041      typedef typename tools::promote_args<T>::type result_type;
0042      //
0043      // The type used for the calculation.  This may be a wider type than
0044      // the result in order to ensure full precision:
0045      //
0046      typedef typename policies::evaluation<result_type, Policy>::type value_type;
0047      //
0048      // The type of the policy to forward to the actual implementation.
0049      // We disable promotion of float and double as that's [possibly]
0050      // happened already in the line above.  Also reset to the default
0051      // any policies we don't use (reduces code bloat if we're called
0052      // multiple times with differing policies we don't actually use).
0053      // Also normalise the type, again to reduce code bloat in case we're
0054      // called multiple times with functionally identical policies that happen
0055      // to be different types.
0056      //
0057      typedef typename policies::normalise<
0058         Policy,
0059         policies::promote_float<false>,
0060         policies::promote_double<false>,
0061         policies::discrete_quantile<>,
0062         policies::assert_undefined<> >::type forwarding_policy;
0063      //
0064      // Whew.  Now we can make the actual call to the implementation.
0065      // Arguments are explicitly cast to the evaluation type, and the result
0066      // passed through checked_narrowing_cast which handles things like overflow
0067      // according to the policy passed:
0068      //
0069      return policies::checked_narrowing_cast<result_type, forwarding_policy>(
0070         detail::polygamma_imp(n, static_cast<value_type>(x), forwarding_policy()),
0071         "boost::math::polygamma<%1%>(int, %1%)");
0072   }
0073 
0074   template<class T>
0075   inline typename tools::promote_args<T>::type polygamma(const int n, T x)
0076   {
0077       return boost::math::polygamma(n, x, policies::policy<>());
0078   }
0079 
0080 } } // namespace boost::math
0081 
0082 #endif // _BOOST_BERNOULLI_2013_05_30_HPP_
0083