diff options
author | bugaevskiy <bugaevskiy@yandex-team.com> | 2022-08-15 06:14:20 +0300 |
---|---|---|
committer | bugaevskiy <bugaevskiy@yandex-team.com> | 2022-08-15 06:14:20 +0300 |
commit | e21105e206aed9630fd4feaae69ad06622070682 (patch) | |
tree | 76a1dab68ff3720d78c431ac6f5a83a9d2ddfcc5 /contrib/restricted/boost/math | |
parent | d63207b17f00c7b8f8894733d6d0e7e2816849ad (diff) | |
download | ydb-e21105e206aed9630fd4feaae69ad06622070682.tar.gz |
Reimport boost/math as a separate project
Diffstat (limited to 'contrib/restricted/boost/math')
15 files changed, 7247 insertions, 0 deletions
diff --git a/contrib/restricted/boost/math/CMakeLists.txt b/contrib/restricted/boost/math/CMakeLists.txt new file mode 100644 index 0000000000..29a3448392 --- /dev/null +++ b/contrib/restricted/boost/math/CMakeLists.txt @@ -0,0 +1,36 @@ + +# This file was gererated by the build system used internally in the Yandex monorepo. +# Only simple modifications are allowed (adding source-files to targets, adding simple properties +# like target_include_directories). These modifications will be ported to original +# ya.make files by maintainers. Any complex modifications which can't be ported back to the +# original buildsystem will not be accepted. + + + +add_library(restricted-boost-math INTERFACE) +target_include_directories(restricted-boost-math INTERFACE + ${CMAKE_SOURCE_DIR}/contrib/restricted/boost/math/include +) +target_link_libraries(restricted-boost-math INTERFACE + contrib-libs-cxxsupp + yutil + restricted-boost-array + restricted-boost-assert + restricted-boost-atomic + restricted-boost-concept_check + restricted-boost-config + restricted-boost-core + restricted-boost-detail + restricted-boost-fusion + restricted-boost-integer + restricted-boost-lambda + restricted-boost-lexical_cast + restricted-boost-mpl + restricted-boost-predef + restricted-boost-range + restricted-boost-smart_ptr + restricted-boost-static_assert + restricted-boost-throw_exception + restricted-boost-tuple + restricted-boost-type_traits +) diff --git a/contrib/restricted/boost/math/include/boost/math/policies/error_handling.hpp b/contrib/restricted/boost/math/include/boost/math/policies/error_handling.hpp new file mode 100644 index 0000000000..124337ee87 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/policies/error_handling.hpp @@ -0,0 +1,847 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007. + +// 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) + +#ifndef BOOST_MATH_POLICY_ERROR_HANDLING_HPP +#define BOOST_MATH_POLICY_ERROR_HANDLING_HPP + +#include <stdexcept> +#include <iomanip> +#include <string> +#include <cstring> +#include <typeinfo> +#include <cerrno> +#include <boost/config/no_tr1/complex.hpp> +#include <boost/config/no_tr1/cmath.hpp> +#include <stdexcept> +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/policy.hpp> +#include <boost/math/tools/precision.hpp> +#include <boost/throw_exception.hpp> +#include <boost/cstdint.hpp> +#ifdef BOOST_MSVC +# pragma warning(push) // Quiet warnings in boost/format.hpp +# pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE +# pragma warning(disable: 4512) // assignment operator could not be generated. +# pragma warning(disable: 4127) // conditional expression is constant +// And warnings in error handling: +# pragma warning(disable: 4702) // unreachable code. +// Note that this only occurs when the compiler can deduce code is unreachable, +// for example when policy macros are used to ignore errors rather than throw. +#endif +#include <sstream> + +namespace boost{ namespace math{ + +class evaluation_error : public std::runtime_error +{ +public: + evaluation_error(const std::string& s) : std::runtime_error(s){} +}; + +class rounding_error : public std::runtime_error +{ +public: + rounding_error(const std::string& s) : std::runtime_error(s){} +}; + +namespace policies{ +// +// Forward declarations of user error handlers, +// it's up to the user to provide the definition of these: +// +template <class T> +T user_domain_error(const char* function, const char* message, const T& val); +template <class T> +T user_pole_error(const char* function, const char* message, const T& val); +template <class T> +T user_overflow_error(const char* function, const char* message, const T& val); +template <class T> +T user_underflow_error(const char* function, const char* message, const T& val); +template <class T> +T user_denorm_error(const char* function, const char* message, const T& val); +template <class T> +T user_evaluation_error(const char* function, const char* message, const T& val); +template <class T, class TargetType> +T user_rounding_error(const char* function, const char* message, const T& val, const TargetType& t); +template <class T> +T user_indeterminate_result_error(const char* function, const char* message, const T& val); + +namespace detail +{ + +template <class T> +std::string prec_format(const T& val) +{ + typedef typename boost::math::policies::precision<T, boost::math::policies::policy<> >::type prec_type; + std::stringstream ss; + if(prec_type::value) + { + int prec = 2 + (prec_type::value * 30103UL) / 100000UL; + ss << std::setprecision(prec); + } + ss << val; + return ss.str(); +} + +inline void replace_all_in_string(std::string& result, const char* what, const char* with) +{ + std::string::size_type pos = 0; + std::string::size_type slen = std::strlen(what); + std::string::size_type rlen = std::strlen(with); + while((pos = result.find(what, pos)) != std::string::npos) + { + result.replace(pos, slen, with); + pos += rlen; + } +} + +template <class T> +inline const char* name_of() +{ +#ifndef BOOST_NO_RTTI + return typeid(T).name(); +#else + return "unknown"; +#endif +} +template <> inline const char* name_of<float>(){ return "float"; } +template <> inline const char* name_of<double>(){ return "double"; } +template <> inline const char* name_of<long double>(){ return "long double"; } + +#ifdef BOOST_MATH_USE_FLOAT128 +template <> +inline const char* name_of<BOOST_MATH_FLOAT128_TYPE>() +{ + return "__float128"; +} +#endif + +template <class E, class T> +void raise_error(const char* pfunction, const char* message) +{ + if(pfunction == 0) + pfunction = "Unknown function operating on type %1%"; + if(message == 0) + message = "Cause unknown"; + + std::string function(pfunction); + std::string msg("Error in function "); +#ifndef BOOST_NO_RTTI + replace_all_in_string(function, "%1%", boost::math::policies::detail::name_of<T>()); +#else + replace_all_in_string(function, "%1%", "Unknown"); +#endif + msg += function; + msg += ": "; + msg += message; + + E e(msg); + boost::throw_exception(e); +} + +template <class E, class T> +void raise_error(const char* pfunction, const char* pmessage, const T& val) +{ + if(pfunction == 0) + pfunction = "Unknown function operating on type %1%"; + if(pmessage == 0) + pmessage = "Cause unknown: error caused by bad argument with value %1%"; + + std::string function(pfunction); + std::string message(pmessage); + std::string msg("Error in function "); +#ifndef BOOST_NO_RTTI + replace_all_in_string(function, "%1%", boost::math::policies::detail::name_of<T>()); +#else + replace_all_in_string(function, "%1%", "Unknown"); +#endif + msg += function; + msg += ": "; + + std::string sval = prec_format(val); + replace_all_in_string(message, "%1%", sval.c_str()); + msg += message; + + E e(msg); + boost::throw_exception(e); +} + +template <class T> +inline T raise_domain_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::domain_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::domain_error, T>(function, message, val); + // we never get here: + return std::numeric_limits<T>::quiet_NaN(); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_domain_error( + const char* , + const char* , + const T& , + const ::boost::math::policies::domain_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // 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<T>::quiet_NaN(); +} + +template <class T> +inline T raise_domain_error( + const char* , + const char* , + const T& , + const ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + errno = EDOM; + // 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<T>::quiet_NaN(); +} + +template <class T> +inline T raise_domain_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::domain_error< ::boost::math::policies::user_error>&) +{ + return user_domain_error(function, message, val); +} + +template <class T> +inline T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::throw_on_error>&) +{ + return boost::math::policies::detail::raise_domain_error(function, message, val, ::boost::math::policies::domain_error< ::boost::math::policies::throw_on_error>()); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + return ::boost::math::policies::detail::raise_domain_error(function, message, val, ::boost::math::policies::domain_error< ::boost::math::policies::ignore_error>()); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + return ::boost::math::policies::detail::raise_domain_error(function, message, val, ::boost::math::policies::domain_error< ::boost::math::policies::errno_on_error>()); +} + +template <class T> +inline T raise_pole_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::pole_error< ::boost::math::policies::user_error>&) +{ + return user_pole_error(function, message, val); +} + + +template <class T> +inline T raise_overflow_error( + const char* function, + const char* message, + const ::boost::math::policies::overflow_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::overflow_error, T>(function, message ? message : "numeric overflow"); + // We should never get here: + return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline T raise_overflow_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::overflow_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::overflow_error, T>(function, message ? message : "numeric overflow", val); + // We should never get here: + return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_overflow_error( + const char* , + const char* , + const ::boost::math::policies::overflow_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // 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<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_overflow_error( + const char* , + const char* , + const T&, + const ::boost::math::policies::overflow_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // 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<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline T raise_overflow_error( + const char* , + const char* , + const ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + 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<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline T raise_overflow_error( + const char* , + const char* , + const T&, + const ::boost::math::policies::overflow_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + 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<T>::has_infinity ? std::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>(); +} + +template <class T> +inline T raise_overflow_error( + const char* function, + const char* message, + const ::boost::math::policies::overflow_error< ::boost::math::policies::user_error>&) +{ + return user_overflow_error(function, message, std::numeric_limits<T>::infinity()); +} + +template <class T> +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 m(message ? message : ""); + std::string sval = prec_format(val); + replace_all_in_string(m, "%1%", sval.c_str()); + + return user_overflow_error(function, m.c_str(), std::numeric_limits<T>::infinity()); +} + +template <class T> +inline T raise_underflow_error( + const char* function, + const char* message, + const ::boost::math::policies::underflow_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::underflow_error, T>(function, message ? message : "numeric underflow"); + // We should never get here: + return 0; +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_underflow_error( + const char* , + const char* , + const ::boost::math::policies::underflow_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // 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 T(0); +} + +template <class T> +inline T raise_underflow_error( + const char* /* function */, + const char* /* message */, + const ::boost::math::policies::underflow_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + 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 T(0); +} + +template <class T> +inline T raise_underflow_error( + const char* function, + const char* message, + const ::boost::math::policies::underflow_error< ::boost::math::policies::user_error>&) +{ + return user_underflow_error(function, message, T(0)); +} + +template <class T> +inline T raise_denorm_error( + const char* function, + const char* message, + const T& /* val */, + const ::boost::math::policies::denorm_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::underflow_error, T>(function, message ? message : "denormalised result"); + // we never get here: + return T(0); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_denorm_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::denorm_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // 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 val; +} + +template <class T> +inline T raise_denorm_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::denorm_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + 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 val; +} + +template <class T> +inline T raise_denorm_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::denorm_error< ::boost::math::policies::user_error>&) +{ + return user_denorm_error(function, message, val); +} + +template <class T> +inline T raise_evaluation_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<boost::math::evaluation_error, T>(function, message, val); + // we never get here: + return T(0); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T raise_evaluation_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // 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 val; +} + +template <class T> +inline T raise_evaluation_error( + const char* , + const char* , + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + errno = EDOM; + // 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 val; +} + +template <class T> +inline T raise_evaluation_error( + const char* function, + const char* message, + const T& val, + const ::boost::math::policies::evaluation_error< ::boost::math::policies::user_error>&) +{ + return user_evaluation_error(function, message, val); +} + +template <class T, class TargetType> +inline TargetType raise_rounding_error( + const char* function, + const char* message, + const T& val, + const TargetType&, + const ::boost::math::policies::rounding_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<boost::math::rounding_error, T>(function, message, val); + // we never get here: + return TargetType(0); +} + +template <class T, class TargetType> +inline BOOST_MATH_CONSTEXPR TargetType raise_rounding_error( + const char* , + const char* , + const T& val, + const TargetType&, + const ::boost::math::policies::rounding_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // This may or may not do the right thing, but the user asked for the error + // to be ignored so here we go anyway: + BOOST_STATIC_ASSERT(std::numeric_limits<TargetType>::is_specialized); + return val > 0 ? (std::numeric_limits<TargetType>::max)() : (std::numeric_limits<TargetType>::is_integer ? (std::numeric_limits<TargetType>::min)() : -(std::numeric_limits<TargetType>::max)()); +} + +template <class T, class TargetType> +inline TargetType raise_rounding_error( + const char* , + const char* , + const T& val, + const TargetType&, + const ::boost::math::policies::rounding_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + 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: + BOOST_STATIC_ASSERT(std::numeric_limits<TargetType>::is_specialized); + return val > 0 ? (std::numeric_limits<TargetType>::max)() : (std::numeric_limits<TargetType>::is_integer ? (std::numeric_limits<TargetType>::min)() : -(std::numeric_limits<TargetType>::max)()); +} + +template <class T> +inline T raise_rounding_error( + const char* , + const char* , + const T& val, + const T&, + const ::boost::math::policies::rounding_error< ::boost::math::policies::errno_on_error>&) BOOST_MATH_NOEXCEPT(T) +{ + 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 val > 0 ? boost::math::tools::max_value<T>() : -boost::math::tools::max_value<T>(); +} + +template <class T, class TargetType> +inline TargetType raise_rounding_error( + const char* function, + const char* message, + const T& val, + const TargetType& t, + const ::boost::math::policies::rounding_error< ::boost::math::policies::user_error>&) +{ + return user_rounding_error(function, message, val, t); +} + +template <class T, class R> +inline T raise_indeterminate_result_error( + const char* function, + const char* message, + const T& val, + const R& , + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::throw_on_error>&) +{ + raise_error<std::domain_error, T>(function, message, val); + // we never get here: + return std::numeric_limits<T>::quiet_NaN(); +} + +template <class T, class R> +inline BOOST_MATH_CONSTEXPR T raise_indeterminate_result_error( + const char* , + const char* , + const T& , + const R& result, + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(T) +{ + // 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 result; +} + +template <class T, class R> +inline T raise_indeterminate_result_error( + const char* , + const char* , + const T& , + const R& result, + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::errno_on_error>&) +{ + errno = EDOM; + // 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 result; +} + +template <class T, class R> +inline T raise_indeterminate_result_error( + const char* function, + const char* message, + const T& val, + const R& , + const ::boost::math::policies::indeterminate_result_error< ::boost::math::policies::user_error>&) +{ + return user_indeterminate_result_error(function, message, val); +} + +} // namespace detail + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_domain_error(const char* function, const char* message, const T& val, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::domain_error_type policy_type; + return detail::raise_domain_error( + function, message ? message : "Domain Error evaluating function at %1%", + val, policy_type()); +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_pole_error(const char* function, const char* message, const T& val, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::pole_error_type policy_type; + return detail::raise_pole_error( + function, message ? message : "Evaluation of function at pole %1%", + val, policy_type()); +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_overflow_error(const char* function, const char* message, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::overflow_error_type policy_type; + return detail::raise_overflow_error<T>( + function, message ? message : "Overflow Error", + policy_type()); +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_overflow_error(const char* function, const char* message, const T& val, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::overflow_error_type policy_type; + return detail::raise_overflow_error( + function, message ? message : "Overflow evaluating function at %1%", + val, policy_type()); +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_underflow_error(const char* function, const char* message, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::underflow_error_type policy_type; + return detail::raise_underflow_error<T>( + function, message ? message : "Underflow Error", + policy_type()); +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_denorm_error(const char* function, const char* message, const T& val, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::denorm_error_type policy_type; + return detail::raise_denorm_error<T>( + function, message ? message : "Denorm Error", + val, + policy_type()); +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_evaluation_error(const char* function, const char* message, const T& val, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::evaluation_error_type policy_type; + return detail::raise_evaluation_error( + function, message ? message : "Internal Evaluation Error, best value so far was %1%", + val, policy_type()); +} + +template <class T, class TargetType, class Policy> +inline BOOST_MATH_CONSTEXPR TargetType raise_rounding_error(const char* function, const char* message, const T& val, const TargetType& t, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::rounding_error_type policy_type; + return detail::raise_rounding_error( + function, message ? message : "Value %1% can not be represented in the target integer type.", + val, t, policy_type()); +} + +template <class T, class R, class Policy> +inline BOOST_MATH_CONSTEXPR T raise_indeterminate_result_error(const char* function, const char* message, const T& val, const R& result, const Policy&) BOOST_NOEXCEPT_IF(is_noexcept_error_policy<Policy>::value && BOOST_MATH_IS_FLOAT(T)) +{ + typedef typename Policy::indeterminate_result_error_type policy_type; + return detail::raise_indeterminate_result_error( + function, message ? message : "Indeterminate result with value %1%", + val, result, policy_type()); +} + +// +// checked_narrowing_cast: +// +namespace detail +{ + +template <class R, class T, class Policy> +inline bool check_overflow(T val, R* result, const char* function, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T) && (Policy::value != throw_on_error) && (Policy::value != user_error)) +{ + BOOST_MATH_STD_USING + if(fabs(val) > tools::max_value<R>()) + { + boost::math::policies::detail::raise_overflow_error<R>(function, 0, pol); + *result = static_cast<R>(val); + return true; + } + return false; +} +template <class R, class T, class Policy> +inline bool check_overflow(std::complex<T> val, R* result, const char* function, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T) && (Policy::value != throw_on_error) && (Policy::value != user_error)) +{ + typedef typename R::value_type r_type; + r_type re, im; + bool r = check_overflow<r_type>(val.real(), &re, function, pol); + r = check_overflow<r_type>(val.imag(), &im, function, pol) || r; + *result = R(re, im); + return r; +} +template <class R, class T, class Policy> +inline bool check_underflow(T val, R* result, const char* function, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T) && (Policy::value != throw_on_error) && (Policy::value != user_error)) +{ + if((val != 0) && (static_cast<R>(val) == 0)) + { + *result = static_cast<R>(boost::math::policies::detail::raise_underflow_error<R>(function, 0, pol)); + return true; + } + return false; +} +template <class R, class T, class Policy> +inline bool check_underflow(std::complex<T> val, R* result, const char* function, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T) && (Policy::value != throw_on_error) && (Policy::value != user_error)) +{ + typedef typename R::value_type r_type; + r_type re, im; + bool r = check_underflow<r_type>(val.real(), &re, function, pol); + r = check_underflow<r_type>(val.imag(), &im, function, pol) || r; + *result = R(re, im); + return r; +} +template <class R, class T, class Policy> +inline bool check_denorm(T val, R* result, const char* function, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T) && (Policy::value != throw_on_error) && (Policy::value != user_error)) +{ + BOOST_MATH_STD_USING + if((fabs(val) < static_cast<T>(tools::min_value<R>())) && (static_cast<R>(val) != 0)) + { + *result = static_cast<R>(boost::math::policies::detail::raise_denorm_error<R>(function, 0, static_cast<R>(val), pol)); + return true; + } + return false; +} +template <class R, class T, class Policy> +inline bool check_denorm(std::complex<T> val, R* result, const char* function, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T) && (Policy::value != throw_on_error) && (Policy::value != user_error)) +{ + typedef typename R::value_type r_type; + r_type re, im; + bool r = check_denorm<r_type>(val.real(), &re, function, pol); + r = check_denorm<r_type>(val.imag(), &im, function, pol) || r; + *result = R(re, im); + return r; +} + +// Default instantiations with ignore_error policy. +template <class R, class T> +inline BOOST_MATH_CONSTEXPR bool check_overflow(T /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T)) +{ return false; } +template <class R, class T> +inline BOOST_MATH_CONSTEXPR bool check_overflow(std::complex<T> /* val */, R* /* result */, const char* /* function */, const overflow_error<ignore_error>&) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T)) +{ return false; } +template <class R, class T> +inline BOOST_MATH_CONSTEXPR bool check_underflow(T /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T)) +{ return false; } +template <class R, class T> +inline BOOST_MATH_CONSTEXPR bool check_underflow(std::complex<T> /* val */, R* /* result */, const char* /* function */, const underflow_error<ignore_error>&) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T)) +{ return false; } +template <class R, class T> +inline BOOST_MATH_CONSTEXPR bool check_denorm(T /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T)) +{ return false; } +template <class R, class T> +inline BOOST_MATH_CONSTEXPR bool check_denorm(std::complex<T> /* val */, R* /* result*/, const char* /* function */, const denorm_error<ignore_error>&) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T)) +{ return false; } + +} // namespace detail + +template <class R, class Policy, class T> +inline R checked_narrowing_cast(T val, const char* function) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(R) && BOOST_MATH_IS_FLOAT(T) && is_noexcept_error_policy<Policy>::value) +{ + typedef typename Policy::overflow_error_type overflow_type; + typedef typename Policy::underflow_error_type underflow_type; + typedef typename Policy::denorm_error_type denorm_type; + // + // Most of what follows will evaluate to a no-op: + // + R result = 0; + if(detail::check_overflow<R>(val, &result, function, overflow_type())) + return result; + if(detail::check_underflow<R>(val, &result, function, underflow_type())) + return result; + if(detail::check_denorm<R>(val, &result, function, denorm_type())) + return result; + + return static_cast<R>(val); +} + +template <class T, class Policy> +inline void check_series_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && is_noexcept_error_policy<Policy>::value) +{ + if(max_iter >= policies::get_max_series_iterations<Policy>()) + raise_evaluation_error<T>( + function, + "Series evaluation exceeded %1% iterations, giving up now.", static_cast<T>(static_cast<double>(max_iter)), pol); +} + +template <class T, class Policy> +inline void check_root_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && is_noexcept_error_policy<Policy>::value) +{ + if(max_iter >= policies::get_max_root_iterations<Policy>()) + raise_evaluation_error<T>( + function, + "Root finding evaluation exceeded %1% iterations, giving up now.", static_cast<T>(static_cast<double>(max_iter)), pol); +} + +} //namespace policies + +namespace detail{ + +// +// Simple helper function to assist in returning a pair from a single value, +// that value usually comes from one of the error handlers above: +// +template <class T> +std::pair<T, T> pair_from_single(const T& val) BOOST_MATH_NOEXCEPT(T) +{ + return std::make_pair(val, val); +} + +} + +#ifdef BOOST_MSVC +# pragma warning(pop) +#endif + +}} // namespaces boost/math + +#endif // BOOST_MATH_POLICY_ERROR_HANDLING_HPP + diff --git a/contrib/restricted/boost/math/include/boost/math/policies/policy.hpp b/contrib/restricted/boost/math/include/boost/math/policies/policy.hpp new file mode 100644 index 0000000000..c1e1a7be4a --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/policies/policy.hpp @@ -0,0 +1,1040 @@ +// Copyright John Maddock 2007. +// 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) + +#ifndef BOOST_MATH_POLICY_HPP +#define BOOST_MATH_POLICY_HPP + +#include <boost/mpl/list.hpp> +#include <boost/mpl/contains.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/find_if.hpp> +#include <boost/mpl/remove_if.hpp> +#include <boost/mpl/vector.hpp> +#include <boost/mpl/push_back.hpp> +#include <boost/mpl/at.hpp> +#include <boost/mpl/size.hpp> +#include <boost/mpl/comparison.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/static_assert.hpp> +#include <boost/assert.hpp> +#include <boost/math/tools/config.hpp> +#include <limits> +// Sadly we do need the .h versions of these to be sure of getting +// FLT_MANT_DIG etc. +#include <limits.h> +#include <stdlib.h> +#include <stddef.h> +#include <math.h> + +namespace boost{ namespace math{ + +namespace tools{ + +template <class T> +BOOST_MATH_CONSTEXPR int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT; +template <class T> +BOOST_MATH_CONSTEXPR T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T); + +} + +namespace policies{ + +// +// Define macros for our default policies, if they're not defined already: +// +// Special cases for exceptions disabled first: +// +#ifdef BOOST_NO_EXCEPTIONS +# ifndef BOOST_MATH_DOMAIN_ERROR_POLICY +# define BOOST_MATH_DOMAIN_ERROR_POLICY errno_on_error +# endif +# ifndef BOOST_MATH_POLE_ERROR_POLICY +# define BOOST_MATH_POLE_ERROR_POLICY errno_on_error +# endif +# ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY +# define BOOST_MATH_OVERFLOW_ERROR_POLICY errno_on_error +# endif +# ifndef BOOST_MATH_EVALUATION_ERROR_POLICY +# define BOOST_MATH_EVALUATION_ERROR_POLICY errno_on_error +# endif +# ifndef BOOST_MATH_ROUNDING_ERROR_POLICY +# define BOOST_MATH_ROUNDING_ERROR_POLICY errno_on_error +# endif +#endif +// +// Then the regular cases: +// +#ifndef BOOST_MATH_DOMAIN_ERROR_POLICY +#define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_POLE_ERROR_POLICY +#define BOOST_MATH_POLE_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_OVERFLOW_ERROR_POLICY +#define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_EVALUATION_ERROR_POLICY +#define BOOST_MATH_EVALUATION_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_ROUNDING_ERROR_POLICY +#define BOOST_MATH_ROUNDING_ERROR_POLICY throw_on_error +#endif +#ifndef BOOST_MATH_UNDERFLOW_ERROR_POLICY +#define BOOST_MATH_UNDERFLOW_ERROR_POLICY ignore_error +#endif +#ifndef BOOST_MATH_DENORM_ERROR_POLICY +#define BOOST_MATH_DENORM_ERROR_POLICY ignore_error +#endif +#ifndef BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY +#define BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY ignore_error +#endif +#ifndef BOOST_MATH_DIGITS10_POLICY +#define BOOST_MATH_DIGITS10_POLICY 0 +#endif +#ifndef BOOST_MATH_PROMOTE_FLOAT_POLICY +#define BOOST_MATH_PROMOTE_FLOAT_POLICY true +#endif +#ifndef BOOST_MATH_PROMOTE_DOUBLE_POLICY +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#define BOOST_MATH_PROMOTE_DOUBLE_POLICY false +#else +#define BOOST_MATH_PROMOTE_DOUBLE_POLICY true +#endif +#endif +#ifndef BOOST_MATH_DISCRETE_QUANTILE_POLICY +#define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_outwards +#endif +#ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY +#define BOOST_MATH_ASSERT_UNDEFINED_POLICY true +#endif +#ifndef BOOST_MATH_MAX_SERIES_ITERATION_POLICY +#define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000 +#endif +#ifndef BOOST_MATH_MAX_ROOT_ITERATION_POLICY +#define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200 +#endif + +#if !defined(__BORLANDC__) +#define BOOST_MATH_META_INT(type, name, Default)\ + template <type N = Default> struct name : public boost::mpl::int_<N>{};\ + namespace detail{\ + template <type N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_imp\ + {\ + template <type N> static char test(const name<N>*);\ + static double test(...);\ + BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>{}; + +#define BOOST_MATH_META_BOOL(name, Default)\ + template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\ + namespace detail{\ + template <bool N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_imp\ + {\ + template <bool N> static char test(const name<N>*);\ + static double test(...);\ + BOOST_STATIC_CONSTANT(bool, value = sizeof(test(static_cast<T*>(0))) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>{}; +#else +#define BOOST_MATH_META_INT(Type, name, Default)\ + template <Type N = Default> struct name : public boost::mpl::int_<N>{};\ + namespace detail{\ + template <Type N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_tester\ + {\ + template <Type N> static char test(const name<N>&);\ + static double test(...);\ + };\ + template <class T> struct is_##name##_imp\ + {\ + static T inst;\ + BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester<T>::test(inst)) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>\ + {\ + template <class U> struct apply{ typedef is_##name<U> type; };\ + }; + +#define BOOST_MATH_META_BOOL(name, Default)\ + template <bool N = Default> struct name : public boost::mpl::bool_<N>{};\ + namespace detail{\ + template <bool N>\ + char test_is_valid_arg(const name<N>*);\ + char test_is_default_arg(const name<Default>*);\ + template <class T> struct is_##name##_tester\ + {\ + template <bool N> static char test(const name<N>&);\ + static double test(...);\ + };\ + template <class T> struct is_##name##_imp\ + {\ + static T inst;\ + BOOST_STATIC_CONSTANT(bool, value = sizeof( ::boost::math::policies::detail::is_##name##_tester<T>::test(inst)) == 1);\ + };\ + }\ + template <class T> struct is_##name : public boost::mpl::bool_< ::boost::math::policies::detail::is_##name##_imp<T>::value>\ + {\ + template <class U> struct apply{ typedef is_##name<U> type; };\ + }; +#endif +// +// Begin by defining policy types for error handling: +// +enum error_policy_type +{ + throw_on_error = 0, + errno_on_error = 1, + ignore_error = 2, + user_error = 3 +}; + +BOOST_MATH_META_INT(error_policy_type, domain_error, BOOST_MATH_DOMAIN_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, pole_error, BOOST_MATH_POLE_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, overflow_error, BOOST_MATH_OVERFLOW_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, underflow_error, BOOST_MATH_UNDERFLOW_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, denorm_error, BOOST_MATH_DENORM_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, evaluation_error, BOOST_MATH_EVALUATION_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, rounding_error, BOOST_MATH_ROUNDING_ERROR_POLICY) +BOOST_MATH_META_INT(error_policy_type, indeterminate_result_error, BOOST_MATH_INDETERMINATE_RESULT_ERROR_POLICY) + +// +// Policy types for internal promotion: +// +BOOST_MATH_META_BOOL(promote_float, BOOST_MATH_PROMOTE_FLOAT_POLICY) +BOOST_MATH_META_BOOL(promote_double, BOOST_MATH_PROMOTE_DOUBLE_POLICY) +BOOST_MATH_META_BOOL(assert_undefined, BOOST_MATH_ASSERT_UNDEFINED_POLICY) +// +// Policy types for discrete quantiles: +// +enum discrete_quantile_policy_type +{ + real, + integer_round_outwards, + integer_round_inwards, + integer_round_down, + integer_round_up, + integer_round_nearest +}; + +BOOST_MATH_META_INT(discrete_quantile_policy_type, discrete_quantile, BOOST_MATH_DISCRETE_QUANTILE_POLICY) +// +// Precision: +// +BOOST_MATH_META_INT(int, digits10, BOOST_MATH_DIGITS10_POLICY) +BOOST_MATH_META_INT(int, digits2, 0) +// +// Iterations: +// +BOOST_MATH_META_INT(unsigned long, max_series_iterations, BOOST_MATH_MAX_SERIES_ITERATION_POLICY) +BOOST_MATH_META_INT(unsigned long, max_root_iterations, BOOST_MATH_MAX_ROOT_ITERATION_POLICY) +// +// Define the names for each possible policy: +// +#define BOOST_MATH_PARAMETER(name)\ + BOOST_PARAMETER_TEMPLATE_KEYWORD(name##_name)\ + BOOST_PARAMETER_NAME(name##_name) + +struct default_policy{}; + +namespace detail{ +// +// Trait to work out bits precision from digits10 and digits2: +// +template <class Digits10, class Digits2> +struct precision +{ + // + // Now work out the precision: + // + typedef typename mpl::if_c< + (Digits10::value == 0), + digits2<0>, + digits2<((Digits10::value + 1) * 1000L) / 301L> + >::type digits2_type; +public: +#ifdef __BORLANDC__ + typedef typename mpl::if_c< + (Digits2::value > ::boost::math::policies::detail::precision<Digits10,Digits2>::digits2_type::value), + Digits2, digits2_type>::type type; +#else + typedef typename mpl::if_c< + (Digits2::value > digits2_type::value), + Digits2, digits2_type>::type type; +#endif +}; + +template <class A, class B, bool b> +struct select_result +{ + typedef A type; +}; +template <class A, class B> +struct select_result<A, B, false> +{ + typedef typename mpl::deref<B>::type type; +}; + +template <class Seq, class Pred, class DefaultType> +struct find_arg +{ +private: + typedef typename mpl::find_if<Seq, Pred>::type iter; + typedef typename mpl::end<Seq>::type end_type; +public: + typedef typename select_result< + DefaultType, iter, + ::boost::is_same<iter, end_type>::value>::type type; +}; + +double test_is_valid_arg(...); +double test_is_default_arg(...); +char test_is_valid_arg(const default_policy*); +char test_is_default_arg(const default_policy*); + +template <class T> +struct is_valid_policy_imp +{ + BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_valid_arg(static_cast<T*>(0))) == 1); +}; + +template <class T> +struct is_default_policy_imp +{ + BOOST_STATIC_CONSTANT(bool, value = sizeof(::boost::math::policies::detail::test_is_default_arg(static_cast<T*>(0))) == 1); +}; + +template <class T> struct is_valid_policy +: public mpl::bool_< + ::boost::math::policies::detail::is_valid_policy_imp<T>::value> +{}; + +template <class T> struct is_default_policy +: public mpl::bool_< + ::boost::math::policies::detail::is_default_policy_imp<T>::value> +{ + template <class U> + struct apply + { + typedef is_default_policy<U> type; + }; +}; + +template <class Seq, class T, int N> +struct append_N +{ + typedef typename mpl::push_back<Seq, T>::type new_seq; + typedef typename append_N<new_seq, T, N-1>::type type; +}; + +template <class Seq, class T> +struct append_N<Seq, T, 0> +{ + typedef Seq type; +}; + +// +// Traits class to work out what template parameters our default +// policy<> class will have when modified for forwarding: +// +template <bool f, bool d> +struct default_args +{ + typedef promote_float<false> arg1; + typedef promote_double<false> arg2; +}; + +template <> +struct default_args<false, false> +{ + typedef default_policy arg1; + typedef default_policy arg2; +}; + +template <> +struct default_args<true, false> +{ + typedef promote_float<false> arg1; + typedef default_policy arg2; +}; + +template <> +struct default_args<false, true> +{ + typedef promote_double<false> arg1; + typedef default_policy arg2; +}; + +typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg1 forwarding_arg1; +typedef default_args<BOOST_MATH_PROMOTE_FLOAT_POLICY, BOOST_MATH_PROMOTE_DOUBLE_POLICY>::arg2 forwarding_arg2; + +} // detail +// +// Now define the policy type with enough arguments to handle all +// the policies: +// +template <class A1 = default_policy, + class A2 = default_policy, + class A3 = default_policy, + class A4 = default_policy, + class A5 = default_policy, + class A6 = default_policy, + class A7 = default_policy, + class A8 = default_policy, + class A9 = default_policy, + class A10 = default_policy, + class A11 = default_policy, + class A12 = default_policy, + class A13 = default_policy> +struct policy +{ +private: + // + // Validate all our arguments: + // + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A1>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A2>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A3>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A4>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A5>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A6>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A7>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A8>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A9>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A10>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A11>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A12>::value); + BOOST_STATIC_ASSERT(::boost::math::policies::detail::is_valid_policy<A13>::value); + // + // Typelist of the arguments: + // + typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list; + +public: + typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, domain_error<> >::type domain_error_type; + typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, pole_error<> >::type pole_error_type; + typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, overflow_error<> >::type overflow_error_type; + typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, underflow_error<> >::type underflow_error_type; + typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, denorm_error<> >::type denorm_error_type; + typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, evaluation_error<> >::type evaluation_error_type; + typedef typename detail::find_arg<arg_list, is_rounding_error<mpl::_1>, rounding_error<> >::type rounding_error_type; + typedef typename detail::find_arg<arg_list, is_indeterminate_result_error<mpl::_1>, indeterminate_result_error<> >::type indeterminate_result_error_type; +private: + // + // Now work out the precision: + // + typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type; + typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, digits2<> >::type bits_precision_type; +public: + typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type; + // + // Internal promotion: + // + typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, promote_float<> >::type promote_float_type; + typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, promote_double<> >::type promote_double_type; + // + // Discrete quantiles: + // + typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, discrete_quantile<> >::type discrete_quantile_type; + // + // Mathematically undefined properties: + // + typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, assert_undefined<> >::type assert_undefined_type; + // + // Max iterations: + // + typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, max_series_iterations<> >::type max_series_iterations_type; + typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, max_root_iterations<> >::type max_root_iterations_type; +}; +// +// These full specializations are defined to reduce the amount of +// template instantiations that have to take place when using the default +// policies, they have quite a large impact on compile times: +// +template <> +struct policy<default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy> +{ +public: + typedef domain_error<> domain_error_type; + typedef pole_error<> pole_error_type; + typedef overflow_error<> overflow_error_type; + typedef underflow_error<> underflow_error_type; + typedef denorm_error<> denorm_error_type; + typedef evaluation_error<> evaluation_error_type; + typedef rounding_error<> rounding_error_type; + typedef indeterminate_result_error<> indeterminate_result_error_type; +#if BOOST_MATH_DIGITS10_POLICY == 0 + typedef digits2<> precision_type; +#else + typedef detail::precision<digits10<>, digits2<> >::type precision_type; +#endif + typedef promote_float<> promote_float_type; + typedef promote_double<> promote_double_type; + typedef discrete_quantile<> discrete_quantile_type; + typedef assert_undefined<> assert_undefined_type; + typedef max_series_iterations<> max_series_iterations_type; + typedef max_root_iterations<> max_root_iterations_type; +}; + +template <> +struct policy<detail::forwarding_arg1, detail::forwarding_arg2, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy, default_policy> +{ +public: + typedef domain_error<> domain_error_type; + typedef pole_error<> pole_error_type; + typedef overflow_error<> overflow_error_type; + typedef underflow_error<> underflow_error_type; + typedef denorm_error<> denorm_error_type; + typedef evaluation_error<> evaluation_error_type; + typedef rounding_error<> rounding_error_type; + typedef indeterminate_result_error<> indeterminate_result_error_type; +#if BOOST_MATH_DIGITS10_POLICY == 0 + typedef digits2<> precision_type; +#else + typedef detail::precision<digits10<>, digits2<> >::type precision_type; +#endif + typedef promote_float<false> promote_float_type; + typedef promote_double<false> promote_double_type; + typedef discrete_quantile<> discrete_quantile_type; + typedef assert_undefined<> assert_undefined_type; + typedef max_series_iterations<> max_series_iterations_type; + typedef max_root_iterations<> max_root_iterations_type; +}; + +template <class Policy, + class A1 = default_policy, + class A2 = default_policy, + class A3 = default_policy, + class A4 = default_policy, + class A5 = default_policy, + class A6 = default_policy, + class A7 = default_policy, + class A8 = default_policy, + class A9 = default_policy, + class A10 = default_policy, + class A11 = default_policy, + class A12 = default_policy, + class A13 = default_policy> +struct normalise +{ +private: + typedef mpl::list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13> arg_list; + typedef typename detail::find_arg<arg_list, is_domain_error<mpl::_1>, typename Policy::domain_error_type >::type domain_error_type; + typedef typename detail::find_arg<arg_list, is_pole_error<mpl::_1>, typename Policy::pole_error_type >::type pole_error_type; + typedef typename detail::find_arg<arg_list, is_overflow_error<mpl::_1>, typename Policy::overflow_error_type >::type overflow_error_type; + typedef typename detail::find_arg<arg_list, is_underflow_error<mpl::_1>, typename Policy::underflow_error_type >::type underflow_error_type; + typedef typename detail::find_arg<arg_list, is_denorm_error<mpl::_1>, typename Policy::denorm_error_type >::type denorm_error_type; + typedef typename detail::find_arg<arg_list, is_evaluation_error<mpl::_1>, typename Policy::evaluation_error_type >::type evaluation_error_type; + typedef typename detail::find_arg<arg_list, is_rounding_error<mpl::_1>, typename Policy::rounding_error_type >::type rounding_error_type; + typedef typename detail::find_arg<arg_list, is_indeterminate_result_error<mpl::_1>, typename Policy::indeterminate_result_error_type >::type indeterminate_result_error_type; + // + // Now work out the precision: + // + typedef typename detail::find_arg<arg_list, is_digits10<mpl::_1>, digits10<> >::type digits10_type; + typedef typename detail::find_arg<arg_list, is_digits2<mpl::_1>, typename Policy::precision_type >::type bits_precision_type; + typedef typename detail::precision<digits10_type, bits_precision_type>::type precision_type; + // + // Internal promotion: + // + typedef typename detail::find_arg<arg_list, is_promote_float<mpl::_1>, typename Policy::promote_float_type >::type promote_float_type; + typedef typename detail::find_arg<arg_list, is_promote_double<mpl::_1>, typename Policy::promote_double_type >::type promote_double_type; + // + // Discrete quantiles: + // + typedef typename detail::find_arg<arg_list, is_discrete_quantile<mpl::_1>, typename Policy::discrete_quantile_type >::type discrete_quantile_type; + // + // Mathematically undefined properties: + // + typedef typename detail::find_arg<arg_list, is_assert_undefined<mpl::_1>, typename Policy::assert_undefined_type >::type assert_undefined_type; + // + // Max iterations: + // + typedef typename detail::find_arg<arg_list, is_max_series_iterations<mpl::_1>, typename Policy::max_series_iterations_type>::type max_series_iterations_type; + typedef typename detail::find_arg<arg_list, is_max_root_iterations<mpl::_1>, typename Policy::max_root_iterations_type>::type max_root_iterations_type; + // + // Define a typelist of the policies: + // + typedef mpl::vector< + domain_error_type, + pole_error_type, + overflow_error_type, + underflow_error_type, + denorm_error_type, + evaluation_error_type, + rounding_error_type, + indeterminate_result_error_type, + precision_type, + promote_float_type, + promote_double_type, + discrete_quantile_type, + assert_undefined_type, + max_series_iterations_type, + max_root_iterations_type> result_list; + // + // Remove all the policies that are the same as the default: + // + typedef typename mpl::remove_if<result_list, detail::is_default_policy<mpl::_> >::type reduced_list; + // + // Pad out the list with defaults: + // + typedef typename detail::append_N<reduced_list, default_policy, (14 - ::boost::mpl::size<reduced_list>::value)>::type result_type; +public: + typedef policy< + typename mpl::at<result_type, mpl::int_<0> >::type, + typename mpl::at<result_type, mpl::int_<1> >::type, + typename mpl::at<result_type, mpl::int_<2> >::type, + typename mpl::at<result_type, mpl::int_<3> >::type, + typename mpl::at<result_type, mpl::int_<4> >::type, + typename mpl::at<result_type, mpl::int_<5> >::type, + typename mpl::at<result_type, mpl::int_<6> >::type, + typename mpl::at<result_type, mpl::int_<7> >::type, + typename mpl::at<result_type, mpl::int_<8> >::type, + typename mpl::at<result_type, mpl::int_<9> >::type, + typename mpl::at<result_type, mpl::int_<10> >::type, + typename mpl::at<result_type, mpl::int_<11> >::type, + typename mpl::at<result_type, mpl::int_<12> >::type > type; +}; +// +// Full specialisation to speed up compilation of the common case: +// +template <> +struct normalise<policy<>, + promote_float<false>, + promote_double<false>, + discrete_quantile<>, + assert_undefined<>, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy> +{ + typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type; +}; + +template <> +struct normalise<policy<detail::forwarding_arg1, detail::forwarding_arg2>, + promote_float<false>, + promote_double<false>, + discrete_quantile<>, + assert_undefined<>, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy, + default_policy> +{ + typedef policy<detail::forwarding_arg1, detail::forwarding_arg2> type; +}; + +inline BOOST_MATH_CONSTEXPR policy<> make_policy() BOOST_NOEXCEPT +{ return policy<>(); } + +template <class A1> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1>::type make_policy(const A1&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1>::type result_type; + return result_type(); +} + +template <class A1, class A2> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2>::type make_policy(const A1&, const A2&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3>::type make_policy(const A1&, const A2&, const A3&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4>::type make_policy(const A1&, const A2&, const A3&, const A4&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10>::type result_type; + return result_type(); +} + +template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11> +inline BOOST_MATH_CONSTEXPR typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type make_policy(const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&) BOOST_NOEXCEPT +{ + typedef typename normalise<policy<>, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11>::type result_type; + return result_type(); +} + +// +// Traits class to handle internal promotion: +// +template <class Real, class Policy> +struct evaluation +{ + typedef Real type; +}; + +template <class Policy> +struct evaluation<float, Policy> +{ + typedef typename mpl::if_<typename Policy::promote_float_type, double, float>::type type; +}; + +template <class Policy> +struct evaluation<double, Policy> +{ + typedef typename mpl::if_<typename Policy::promote_double_type, long double, double>::type type; +}; + +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + +template <class Real> +struct basic_digits : public mpl::int_<0>{ }; +template <> +struct basic_digits<float> : public mpl::int_<FLT_MANT_DIG>{ }; +template <> +struct basic_digits<double> : public mpl::int_<DBL_MANT_DIG>{ }; +template <> +struct basic_digits<long double> : public mpl::int_<LDBL_MANT_DIG>{ }; + +template <class Real, class Policy> +struct precision +{ + BOOST_STATIC_ASSERT( ::std::numeric_limits<Real>::radix == 2); + typedef typename Policy::precision_type precision_type; + typedef basic_digits<Real> digits_t; + typedef typename mpl::if_< + mpl::equal_to<digits_t, mpl::int_<0> >, + // Possibly unknown precision: + precision_type, + typename mpl::if_< + mpl::or_<mpl::less_equal<digits_t, precision_type>, mpl::less_equal<precision_type, mpl::int_<0> > >, + // Default case, full precision for RealType: + digits2< ::std::numeric_limits<Real>::digits>, + // User customised precision: + precision_type + >::type + >::type type; +}; + +template <class Policy> +struct precision<float, Policy> +{ + typedef digits2<FLT_MANT_DIG> type; +}; +template <class Policy> +struct precision<double, Policy> +{ + typedef digits2<DBL_MANT_DIG> type; +}; +template <class Policy> +struct precision<long double, Policy> +{ + typedef digits2<LDBL_MANT_DIG> type; +}; + +#else + +template <class Real, class Policy> +struct precision +{ + BOOST_STATIC_ASSERT((::std::numeric_limits<Real>::radix == 2) || ((::std::numeric_limits<Real>::is_specialized == 0) || (::std::numeric_limits<Real>::digits == 0))); +#ifndef __BORLANDC__ + typedef typename Policy::precision_type precision_type; + typedef typename mpl::if_c< + ((::std::numeric_limits<Real>::is_specialized == 0) || (::std::numeric_limits<Real>::digits == 0)), + // Possibly unknown precision: + precision_type, + typename mpl::if_c< + ((::std::numeric_limits<Real>::digits <= precision_type::value) + || (Policy::precision_type::value <= 0)), + // Default case, full precision for RealType: + digits2< ::std::numeric_limits<Real>::digits>, + // User customised precision: + precision_type + >::type + >::type type; +#else + typedef typename Policy::precision_type precision_type; + typedef mpl::int_< ::std::numeric_limits<Real>::digits> digits_t; + typedef mpl::bool_< ::std::numeric_limits<Real>::is_specialized> spec_t; + typedef typename mpl::if_< + mpl::or_<mpl::equal_to<spec_t, mpl::false_>, mpl::equal_to<digits_t, mpl::int_<0> > >, + // Possibly unknown precision: + precision_type, + typename mpl::if_< + mpl::or_<mpl::less_equal<digits_t, precision_type>, mpl::less_equal<precision_type, mpl::int_<0> > >, + // Default case, full precision for RealType: + digits2< ::std::numeric_limits<Real>::digits>, + // User customised precision: + precision_type + >::type + >::type type; +#endif +}; + +#endif + +#ifdef BOOST_MATH_USE_FLOAT128 + +template <class Policy> +struct precision<BOOST_MATH_FLOAT128_TYPE, Policy> +{ + typedef mpl::int_<113> type; +}; + +#endif + +namespace detail{ + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR int digits_imp(mpl::true_ const&) BOOST_NOEXCEPT +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + typedef typename boost::math::policies::precision<T, Policy>::type p_t; + return p_t::value; +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR int digits_imp(mpl::false_ const&) BOOST_NOEXCEPT +{ + return tools::digits<T>(); +} + +} // namespace detail + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT +{ + typedef mpl::bool_< std::numeric_limits<T>::is_specialized > tag_type; + return detail::digits_imp<T, Policy>(tag_type()); +} +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR int digits_base10(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT +{ + return boost::math::policies::digits<T, Policy>() * 301 / 1000L; +} + +template <class Policy> +inline BOOST_MATH_CONSTEXPR unsigned long get_max_series_iterations() BOOST_NOEXCEPT +{ + typedef typename Policy::max_series_iterations_type iter_type; + return iter_type::value; +} + +template <class Policy> +inline BOOST_MATH_CONSTEXPR unsigned long get_max_root_iterations() BOOST_NOEXCEPT +{ + typedef typename Policy::max_root_iterations_type iter_type; + return iter_type::value; +} + +namespace detail{ + +template <class T, class Digits, class Small, class Default> +struct series_factor_calc +{ + static T get() BOOST_MATH_NOEXCEPT(T) + { + return ldexp(T(1.0), 1 - Digits::value); + } +}; + +template <class T, class Digits> +struct series_factor_calc<T, Digits, mpl::true_, mpl::true_> +{ + static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T) + { + return boost::math::tools::epsilon<T>(); + } +}; +template <class T, class Digits> +struct series_factor_calc<T, Digits, mpl::true_, mpl::false_> +{ + static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T) + { + return 1 / static_cast<T>(static_cast<boost::uintmax_t>(1u) << (Digits::value - 1)); + } +}; +template <class T, class Digits> +struct series_factor_calc<T, Digits, mpl::false_, mpl::true_> +{ + static BOOST_MATH_CONSTEXPR T get() BOOST_MATH_NOEXCEPT(T) + { + return boost::math::tools::epsilon<T>(); + } +}; + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T get_epsilon_imp(mpl::true_ const&) BOOST_MATH_NOEXCEPT(T) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); + BOOST_ASSERT(::std::numeric_limits<T>::radix == 2); +#endif + typedef typename boost::math::policies::precision<T, Policy>::type p_t; + typedef mpl::bool_<p_t::value <= std::numeric_limits<boost::uintmax_t>::digits> is_small_int; + typedef mpl::bool_<p_t::value >= std::numeric_limits<T>::digits> is_default_value; + return series_factor_calc<T, p_t, is_small_int, is_default_value>::get(); +} + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T get_epsilon_imp(mpl::false_ const&) BOOST_MATH_NOEXCEPT(T) +{ + return tools::epsilon<T>(); +} + +} // namespace detail + +template <class T, class Policy> +inline BOOST_MATH_CONSTEXPR T get_epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + typedef mpl::bool_< (std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::radix == 2)) > tag_type; + return detail::get_epsilon_imp<T, Policy>(tag_type()); +} + +namespace detail{ + +template <class A1, + class A2, + class A3, + class A4, + class A5, + class A6, + class A7, + class A8, + class A9, + class A10, + class A11> +char test_is_policy(const policy<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11>*); +double test_is_policy(...); + +template <class P> +struct is_policy_imp +{ + BOOST_STATIC_CONSTANT(bool, value = (sizeof(::boost::math::policies::detail::test_is_policy(static_cast<P*>(0))) == 1)); +}; + +} + +template <class P> +struct is_policy : public mpl::bool_< ::boost::math::policies::detail::is_policy_imp<P>::value> {}; + +// +// Helper traits class for distribution error handling: +// +template <class Policy> +struct constructor_error_check +{ + typedef typename Policy::domain_error_type domain_error_type; + typedef typename mpl::if_c< + (domain_error_type::value == throw_on_error) || (domain_error_type::value == user_error) || (domain_error_type::value == errno_on_error), + mpl::true_, + mpl::false_>::type type; +}; + +template <class Policy> +struct method_error_check +{ + typedef typename Policy::domain_error_type domain_error_type; + typedef typename mpl::if_c< + (domain_error_type::value == throw_on_error) && (domain_error_type::value != user_error), + mpl::false_, + mpl::true_>::type type; +}; +// +// Does the Policy ever throw on error? +// +template <class Policy> +struct is_noexcept_error_policy +{ + typedef typename Policy::domain_error_type t1; + typedef typename Policy::pole_error_type t2; + typedef typename Policy::overflow_error_type t3; + typedef typename Policy::underflow_error_type t4; + typedef typename Policy::denorm_error_type t5; + typedef typename Policy::evaluation_error_type t6; + typedef typename Policy::rounding_error_type t7; + typedef typename Policy::indeterminate_result_error_type t8; + + BOOST_STATIC_CONSTANT(bool, value = + ((t1::value != throw_on_error) && (t1::value != user_error) + && (t2::value != throw_on_error) && (t2::value != user_error) + && (t3::value != throw_on_error) && (t3::value != user_error) + && (t4::value != throw_on_error) && (t4::value != user_error) + && (t5::value != throw_on_error) && (t5::value != user_error) + && (t6::value != throw_on_error) && (t6::value != user_error) + && (t7::value != throw_on_error) && (t7::value != user_error) + && (t8::value != throw_on_error) && (t8::value != user_error))); +}; + +}}} // namespaces + +#endif // BOOST_MATH_POLICY_HPP + diff --git a/contrib/restricted/boost/math/include/boost/math/special_functions/detail/fp_traits.hpp b/contrib/restricted/boost/math/include/boost/math/special_functions/detail/fp_traits.hpp new file mode 100644 index 0000000000..c957022223 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/special_functions/detail/fp_traits.hpp @@ -0,0 +1,581 @@ +// fp_traits.hpp + +#ifndef BOOST_MATH_FP_TRAITS_HPP +#define BOOST_MATH_FP_TRAITS_HPP + +// Copyright (c) 2006 Johan Rade + +// 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) + +/* +To support old compilers, care has been taken to avoid partial template +specialization and meta function forwarding. +With these techniques, the code could be simplified. +*/ + +#if defined(__vms) && defined(__DECCXX) && !__IEEE_FLOAT +// The VAX floating point formats are used (for float and double) +# define BOOST_FPCLASSIFY_VAX_FORMAT +#endif + +#include <cstring> + +#include <boost/assert.hpp> +#include <boost/cstdint.hpp> +#include <boost/detail/endian.hpp> +#include <boost/static_assert.hpp> +#include <boost/type_traits/is_floating_point.hpp> + +#ifdef BOOST_NO_STDC_NAMESPACE + namespace std{ using ::memcpy; } +#endif + +#ifndef FP_NORMAL + +#define FP_ZERO 0 +#define FP_NORMAL 1 +#define FP_INFINITE 2 +#define FP_NAN 3 +#define FP_SUBNORMAL 4 + +#else + +#define BOOST_HAS_FPCLASSIFY + +#ifndef fpclassify +# if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) \ + && defined(_GLIBCXX_USE_C99_MATH) \ + && !(defined(_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC) \ + && (_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC != 0)) +# ifdef _STLP_VENDOR_CSTD +# if _STLPORT_VERSION >= 0x520 +# define BOOST_FPCLASSIFY_PREFIX ::__std_alias:: +# else +# define BOOST_FPCLASSIFY_PREFIX ::_STLP_VENDOR_CSTD:: +# endif +# else +# define BOOST_FPCLASSIFY_PREFIX ::std:: +# endif +# else +# undef BOOST_HAS_FPCLASSIFY +# define BOOST_FPCLASSIFY_PREFIX +# endif +#elif (defined(__HP_aCC) && !defined(__hppa)) +// aCC 6 appears to do "#define fpclassify fpclassify" which messes us up a bit! +# define BOOST_FPCLASSIFY_PREFIX :: +#else +# define BOOST_FPCLASSIFY_PREFIX +#endif + +#ifdef __MINGW32__ +# undef BOOST_HAS_FPCLASSIFY +#endif + +#endif + + +//------------------------------------------------------------------------------ + +namespace boost { +namespace math { +namespace detail { + +//------------------------------------------------------------------------------ + +/* +The following classes are used to tag the different methods that are used +for floating point classification +*/ + +struct native_tag {}; +template <bool has_limits> +struct generic_tag {}; +struct ieee_tag {}; +struct ieee_copy_all_bits_tag : public ieee_tag {}; +struct ieee_copy_leading_bits_tag : public ieee_tag {}; + +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +// +// These helper functions are used only when numeric_limits<> +// members are not compile time constants: +// +inline bool is_generic_tag_false(const generic_tag<false>*) +{ + return true; +} +inline bool is_generic_tag_false(const void*) +{ + return false; +} +#endif + +//------------------------------------------------------------------------------ + +/* +Most processors support three different floating point precisions: +single precision (32 bits), double precision (64 bits) +and extended double precision (80 - 128 bits, depending on the processor) + +Note that the C++ type long double can be implemented +both as double precision and extended double precision. +*/ + +struct unknown_precision{}; +struct single_precision {}; +struct double_precision {}; +struct extended_double_precision {}; + +// native_tag version -------------------------------------------------------------- + +template<class T> struct fp_traits_native +{ + typedef native_tag method; +}; + +// generic_tag version ------------------------------------------------------------- + +template<class T, class U> struct fp_traits_non_native +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + typedef generic_tag<std::numeric_limits<T>::is_specialized> method; +#else + typedef generic_tag<false> method; +#endif +}; + +// ieee_tag versions --------------------------------------------------------------- + +/* +These specializations of fp_traits_non_native contain information needed +to "parse" the binary representation of a floating point number. + +Typedef members: + + bits -- the target type when copying the leading bytes of a floating + point number. It is a typedef for uint32_t or uint64_t. + + method -- tells us whether all bytes are copied or not. + It is a typedef for ieee_copy_all_bits_tag or ieee_copy_leading_bits_tag. + +Static data members: + + sign, exponent, flag, significand -- bit masks that give the meaning of the + bits in the leading bytes. + +Static function members: + + get_bits(), set_bits() -- provide access to the leading bytes. + +*/ + +// ieee_tag version, float (32 bits) ----------------------------------------------- + +#ifndef BOOST_FPCLASSIFY_VAX_FORMAT + +template<> struct fp_traits_non_native<float, single_precision> +{ + typedef ieee_copy_all_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7f800000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x007fffff); + + typedef uint32_t bits; + static void get_bits(float x, uint32_t& a) { std::memcpy(&a, &x, 4); } + static void set_bits(float& x, uint32_t a) { std::memcpy(&x, &a, 4); } +}; + +// ieee_tag version, double (64 bits) ---------------------------------------------- + +#if defined(BOOST_NO_INT64_T) || defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) \ + || defined(__BORLANDC__) || defined(__CODEGEAR__) + +template<> struct fp_traits_non_native<double, double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + + typedef uint32_t bits; + + static void get_bits(double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 4); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + +//.............................................................................. + +#else + +template<> struct fp_traits_non_native<double, double_precision> +{ + typedef ieee_copy_all_bits_tag method; + + static const uint64_t sign = ((uint64_t)0x80000000u) << 32; + static const uint64_t exponent = ((uint64_t)0x7ff00000) << 32; + static const uint64_t flag = 0; + static const uint64_t significand + = (((uint64_t)0x000fffff) << 32) + ((uint64_t)0xffffffffu); + + typedef uint64_t bits; + static void get_bits(double x, uint64_t& a) { std::memcpy(&a, &x, 8); } + static void set_bits(double& x, uint64_t a) { std::memcpy(&x, &a, 8); } +}; + +#endif + +#endif // #ifndef BOOST_FPCLASSIFY_VAX_FORMAT + +// long double (64 bits) ------------------------------------------------------- + +#if defined(BOOST_NO_INT64_T) || defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)\ + || defined(__BORLANDC__) || defined(__CODEGEAR__) + +template<> struct fp_traits_non_native<long double, double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 4); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + +//.............................................................................. + +#else + +template<> struct fp_traits_non_native<long double, double_precision> +{ + typedef ieee_copy_all_bits_tag method; + + static const uint64_t sign = (uint64_t)0x80000000u << 32; + static const uint64_t exponent = (uint64_t)0x7ff00000 << 32; + static const uint64_t flag = 0; + static const uint64_t significand + = ((uint64_t)0x000fffff << 32) + (uint64_t)0xffffffffu; + + typedef uint64_t bits; + static void get_bits(long double x, uint64_t& a) { std::memcpy(&a, &x, 8); } + static void set_bits(long double& x, uint64_t a) { std::memcpy(&x, &a, 8); } +}; + +#endif + + +// long double (>64 bits), x86 and x64 ----------------------------------------- + +#if defined(__i386) || defined(__i386__) || defined(_M_IX86) \ + || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) \ + || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) + +// Intel extended double precision format (80 bits) + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + 6, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + 6, &a, 4); + } +}; + + +// long double (>64 bits), Itanium --------------------------------------------- + +#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) + +// The floating point format is unknown at compile time +// No template specialization is provided. +// The generic_tag definition is used. + +// The Itanium supports both +// the Intel extended double precision format (80 bits) and +// the IEEE extended double precision format with 15 exponent bits (128 bits). + +#elif defined(__GNUC__) && (LDBL_MANT_DIG == 106) + +// +// Define nothing here and fall though to generic_tag: +// We have GCC's "double double" in effect, and any attempt +// to handle it via bit-fiddling is pretty much doomed to fail... +// + +// long double (>64 bits), PowerPC --------------------------------------------- + +#elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) \ + || defined(__ppc) || defined(__ppc__) || defined(__PPC__) + +// PowerPC extended double precision format (128 bits) + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 12); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + + +// long double (>64 bits), Motorola 68K ---------------------------------------- + +#elif defined(__m68k) || defined(__m68k__) \ + || defined(__mc68000) || defined(__mc68000__) \ + +// Motorola extended double precision format (96 bits) + +// It is the same format as the Intel extended double precision format, +// except that 1) it is big-endian, 2) the 3rd and 4th byte are padding, and +// 3) the flag bit is not set for infinity + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff); + + // copy 1st, 2nd, 5th and 6th byte. 3rd and 4th byte are padding. + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, &x, 2); + std::memcpy(reinterpret_cast<unsigned char*>(&a) + 2, + reinterpret_cast<const unsigned char*>(&x) + 4, 2); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(&x, &a, 2); + std::memcpy(reinterpret_cast<unsigned char*>(&x) + 4, + reinterpret_cast<const unsigned char*>(&a) + 2, 2); + } +}; + + +// long double (>64 bits), All other processors -------------------------------- + +#else + +// IEEE extended double precision format with 15 exponent bits (128 bits) + +template<> +struct fp_traits_non_native<long double, extended_double_precision> +{ + typedef ieee_copy_leading_bits_tag method; + + BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); + BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); + BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); + BOOST_STATIC_CONSTANT(uint32_t, significand = 0x0000ffff); + + typedef uint32_t bits; + + static void get_bits(long double x, uint32_t& a) + { + std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4); + } + + static void set_bits(long double& x, uint32_t a) + { + std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4); + } + +private: + +#if defined(BOOST_BIG_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 0); +#elif defined(BOOST_LITTLE_ENDIAN) + BOOST_STATIC_CONSTANT(int, offset_ = 12); +#else + BOOST_STATIC_ASSERT(false); +#endif +}; + +#endif + +//------------------------------------------------------------------------------ + +// size_to_precision is a type switch for converting a C++ floating point type +// to the corresponding precision type. + +template<int n, bool fp> struct size_to_precision +{ + typedef unknown_precision type; +}; + +template<> struct size_to_precision<4, true> +{ + typedef single_precision type; +}; + +template<> struct size_to_precision<8, true> +{ + typedef double_precision type; +}; + +template<> struct size_to_precision<10, true> +{ + typedef extended_double_precision type; +}; + +template<> struct size_to_precision<12, true> +{ + typedef extended_double_precision type; +}; + +template<> struct size_to_precision<16, true> +{ + typedef extended_double_precision type; +}; + +//------------------------------------------------------------------------------ +// +// Figure out whether to use native classification functions based on +// whether T is a built in floating point type or not: +// +template <class T> +struct select_native +{ + typedef BOOST_DEDUCED_TYPENAME size_to_precision<sizeof(T), ::boost::is_floating_point<T>::value>::type precision; + typedef fp_traits_non_native<T, precision> type; +}; +template<> +struct select_native<float> +{ + typedef fp_traits_native<float> type; +}; +template<> +struct select_native<double> +{ + typedef fp_traits_native<double> type; +}; +template<> +struct select_native<long double> +{ + typedef fp_traits_native<long double> type; +}; + +//------------------------------------------------------------------------------ + +// fp_traits is a type switch that selects the right fp_traits_non_native + +#if (defined(BOOST_MATH_USE_C99) && !(defined(__GNUC__) && (__GNUC__ < 4))) \ + && !defined(__hpux) \ + && !defined(__DECCXX)\ + && !defined(__osf__) \ + && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)\ + && !defined(__FAST_MATH__)\ + && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY)\ + && !defined(BOOST_INTEL)\ + && !defined(sun)\ + && !defined(__VXWORKS__) +# define BOOST_MATH_USE_STD_FPCLASSIFY +#endif + +template<class T> struct fp_traits +{ + typedef BOOST_DEDUCED_TYPENAME size_to_precision<sizeof(T), ::boost::is_floating_point<T>::value>::type precision; +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY) + typedef typename select_native<T>::type type; +#else + typedef fp_traits_non_native<T, precision> type; +#endif + typedef fp_traits_non_native<T, precision> sign_change_type; +}; + +//------------------------------------------------------------------------------ + +} // namespace detail +} // namespace math +} // namespace boost + +#endif diff --git a/contrib/restricted/boost/math/include/boost/math/special_functions/detail/round_fwd.hpp b/contrib/restricted/boost/math/include/boost/math/special_functions/detail/round_fwd.hpp new file mode 100644 index 0000000000..8c45a7d75a --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/special_functions/detail/round_fwd.hpp @@ -0,0 +1,93 @@ +// Copyright John Maddock 2008. + +// 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) + +#ifndef BOOST_MATH_SPECIAL_ROUND_FWD_HPP +#define BOOST_MATH_SPECIAL_ROUND_FWD_HPP + +#include <boost/config.hpp> +#include <boost/math/tools/promotion.hpp> + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost +{ + namespace math + { + + template <class T, class Policy> + typename tools::promote_args<T>::type trunc(const T& v, const Policy& pol); + template <class T> + typename tools::promote_args<T>::type trunc(const T& v); + template <class T, class Policy> + int itrunc(const T& v, const Policy& pol); + template <class T> + int itrunc(const T& v); + template <class T, class Policy> + long ltrunc(const T& v, const Policy& pol); + template <class T> + long ltrunc(const T& v); +#ifdef BOOST_HAS_LONG_LONG + template <class T, class Policy> + boost::long_long_type lltrunc(const T& v, const Policy& pol); + template <class T> + boost::long_long_type lltrunc(const T& v); +#endif + template <class T, class Policy> + typename tools::promote_args<T>::type round(const T& v, const Policy& pol); + template <class T> + typename tools::promote_args<T>::type round(const T& v); + template <class T, class Policy> + int iround(const T& v, const Policy& pol); + template <class T> + int iround(const T& v); + template <class T, class Policy> + long lround(const T& v, const Policy& pol); + template <class T> + long lround(const T& v); +#ifdef BOOST_HAS_LONG_LONG + template <class T, class Policy> + boost::long_long_type llround(const T& v, const Policy& pol); + template <class T> + boost::long_long_type llround(const T& v); +#endif + template <class T, class Policy> + T modf(const T& v, T* ipart, const Policy& pol); + template <class T> + T modf(const T& v, T* ipart); + template <class T, class Policy> + T modf(const T& v, int* ipart, const Policy& pol); + template <class T> + T modf(const T& v, int* ipart); + template <class T, class Policy> + T modf(const T& v, long* ipart, const Policy& pol); + template <class T> + T modf(const T& v, long* ipart); +#ifdef BOOST_HAS_LONG_LONG + template <class T, class Policy> + T modf(const T& v, boost::long_long_type* ipart, const Policy& pol); + template <class T> + T modf(const T& v, boost::long_long_type* ipart); +#endif + + } +} + +#undef BOOST_MATH_STD_USING +#define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE\ + using boost::math::round;\ + using boost::math::iround;\ + using boost::math::lround;\ + using boost::math::trunc;\ + using boost::math::itrunc;\ + using boost::math::ltrunc;\ + using boost::math::modf; + + +#endif // BOOST_MATH_SPECIAL_ROUND_FWD_HPP + diff --git a/contrib/restricted/boost/math/include/boost/math/special_functions/fpclassify.hpp b/contrib/restricted/boost/math/include/boost/math/special_functions/fpclassify.hpp new file mode 100644 index 0000000000..d83e111c48 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/special_functions/fpclassify.hpp @@ -0,0 +1,640 @@ +// Copyright John Maddock 2005-2008. +// Copyright (c) 2006-2008 Johan Rade +// 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) + +#ifndef BOOST_MATH_FPCLASSIFY_HPP +#define BOOST_MATH_FPCLASSIFY_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <math.h> +#include <boost/config/no_tr1/cmath.hpp> +#include <boost/limits.hpp> +#include <boost/math/tools/real_cast.hpp> +#include <boost/type_traits/is_floating_point.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/detail/fp_traits.hpp> +/*! + \file fpclassify.hpp + \brief Classify floating-point value as normal, subnormal, zero, infinite, or NaN. + \version 1.0 + \author John Maddock + */ + +/* + +1. If the platform is C99 compliant, then the native floating point +classification functions are used. However, note that we must only +define the functions which call std::fpclassify etc if that function +really does exist: otherwise a compiler may reject the code even though +the template is never instantiated. + +2. If the platform is not C99 compliant, and the binary format for +a floating point type (float, double or long double) can be determined +at compile time, then the following algorithm is used: + + If all exponent bits, the flag bit (if there is one), + and all significand bits are 0, then the number is zero. + + If all exponent bits and the flag bit (if there is one) are 0, + and at least one significand bit is 1, then the number is subnormal. + + If all exponent bits are 1 and all significand bits are 0, + then the number is infinity. + + If all exponent bits are 1 and at least one significand bit is 1, + then the number is a not-a-number. + + Otherwise the number is normal. + + This algorithm works for the IEEE 754 representation, + and also for several non IEEE 754 formats. + + Most formats have the structure + sign bit + exponent bits + significand bits. + + A few have the structure + sign bit + exponent bits + flag bit + significand bits. + The flag bit is 0 for zero and subnormal numbers, + and 1 for normal numbers and NaN. + It is 0 (Motorola 68K) or 1 (Intel) for infinity. + + To get the bits, the four or eight most significant bytes are copied + into an uint32_t or uint64_t and bit masks are applied. + This covers all the exponent bits and the flag bit (if there is one), + but not always all the significand bits. + Some of the functions below have two implementations, + depending on whether all the significand bits are copied or not. + +3. If the platform is not C99 compliant, and the binary format for +a floating point type (float, double or long double) can not be determined +at compile time, then comparison with std::numeric_limits values +is used. + +*/ + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#include <float.h> +#endif +#ifdef BOOST_MATH_USE_FLOAT128 +#ifdef __has_include +#if __has_include("quadmath.h") +#include "quadmath.h" +#define BOOST_MATH_HAS_QUADMATH_H +#endif +#endif +#endif + +#ifdef BOOST_NO_STDC_NAMESPACE + namespace std{ using ::abs; using ::fabs; } +#endif + +namespace boost{ + +// +// This must not be located in any namespace under boost::math +// otherwise we can get into an infinite loop if isnan is +// a #define for "isnan" ! +// +namespace math_detail{ + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4800) +#endif + +template <class T> +inline bool is_nan_helper(T t, const boost::true_type&) +{ +#ifdef isnan + return isnan(t); +#elif defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY) || !defined(BOOST_HAS_FPCLASSIFY) + (void)t; + return false; +#else // BOOST_HAS_FPCLASSIFY + return (BOOST_FPCLASSIFY_PREFIX fpclassify(t) == (int)FP_NAN); +#endif +} + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +template <class T> +inline bool is_nan_helper(T, const boost::false_type&) +{ + return false; +} +#if defined(BOOST_MATH_USE_FLOAT128) +#if defined(BOOST_MATH_HAS_QUADMATH_H) +inline bool is_nan_helper(__float128 f, const boost::true_type&) { return ::isnanq(f); } +inline bool is_nan_helper(__float128 f, const boost::false_type&) { return ::isnanq(f); } +#elif defined(BOOST_GNU_STDLIB) && BOOST_GNU_STDLIB && \ + _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC +inline bool is_nan_helper(__float128 f, const boost::true_type&) { return std::isnan(static_cast<double>(f)); } +inline bool is_nan_helper(__float128 f, const boost::false_type&) { return std::isnan(static_cast<double>(f)); } +#else +inline bool is_nan_helper(__float128 f, const boost::true_type&) { return ::isnan(static_cast<double>(f)); } +inline bool is_nan_helper(__float128 f, const boost::false_type&) { return ::isnan(static_cast<double>(f)); } +#endif +#endif +} + +namespace math{ + +namespace detail{ + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY +template <class T> +inline int fpclassify_imp BOOST_NO_MACRO_EXPAND(T t, const native_tag&) +{ + return (std::fpclassify)(t); +} +#endif + +template <class T> +inline int fpclassify_imp BOOST_NO_MACRO_EXPAND(T t, const generic_tag<true>&) +{ + BOOST_MATH_INSTRUMENT_VARIABLE(t); + + // whenever possible check for Nan's first: +#if defined(BOOST_HAS_FPCLASSIFY) && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY) + if(::boost::math_detail::is_nan_helper(t, ::boost::is_floating_point<T>())) + return FP_NAN; +#elif defined(isnan) + if(boost::math_detail::is_nan_helper(t, ::boost::is_floating_point<T>())) + return FP_NAN; +#elif defined(_MSC_VER) || defined(__BORLANDC__) + if(::_isnan(boost::math::tools::real_cast<double>(t))) + return FP_NAN; +#endif + // std::fabs broken on a few systems especially for long long!!!! + T at = (t < T(0)) ? -t : t; + + // Use a process of exclusion to figure out + // what kind of type we have, this relies on + // IEEE conforming reals that will treat + // Nan's as unordered. Some compilers + // don't do this once optimisations are + // turned on, hence the check for nan's above. + if(at <= (std::numeric_limits<T>::max)()) + { + if(at >= (std::numeric_limits<T>::min)()) + return FP_NORMAL; + return (at != 0) ? FP_SUBNORMAL : FP_ZERO; + } + else if(at > (std::numeric_limits<T>::max)()) + return FP_INFINITE; + return FP_NAN; +} + +template <class T> +inline int fpclassify_imp BOOST_NO_MACRO_EXPAND(T t, const generic_tag<false>&) +{ +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return fpclassify_imp(t, generic_tag<true>()); +#endif + // + // An unknown type with no numeric_limits support, + // so what are we supposed to do we do here? + // + BOOST_MATH_INSTRUMENT_VARIABLE(t); + + return t == 0 ? FP_ZERO : FP_NORMAL; +} + +template<class T> +int fpclassify_imp BOOST_NO_MACRO_EXPAND(T x, ieee_copy_all_bits_tag) +{ + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_MATH_INSTRUMENT_VARIABLE(x); + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + BOOST_MATH_INSTRUMENT_VARIABLE(a); + a &= traits::exponent | traits::flag | traits::significand; + BOOST_MATH_INSTRUMENT_VARIABLE((traits::exponent | traits::flag | traits::significand)); + BOOST_MATH_INSTRUMENT_VARIABLE(a); + + if(a <= traits::significand) { + if(a == 0) + return FP_ZERO; + else + return FP_SUBNORMAL; + } + + if(a < traits::exponent) return FP_NORMAL; + + a &= traits::significand; + if(a == 0) return FP_INFINITE; + + return FP_NAN; +} + +template<class T> +int fpclassify_imp BOOST_NO_MACRO_EXPAND(T x, ieee_copy_leading_bits_tag) +{ + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_MATH_INSTRUMENT_VARIABLE(x); + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::flag | traits::significand; + + if(a <= traits::significand) { + if(x == 0) + return FP_ZERO; + else + return FP_SUBNORMAL; + } + + if(a < traits::exponent) return FP_NORMAL; + + a &= traits::significand; + traits::set_bits(x,a); + if(x == 0) return FP_INFINITE; + + return FP_NAN; +} + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && (defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)) +inline int fpclassify_imp BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::fpclassify_imp(t, generic_tag<true>()); +} +#endif + +} // namespace detail + +template <class T> +inline int fpclassify BOOST_NO_MACRO_EXPAND(T t) +{ + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + typedef typename tools::promote_args_permissive<T>::type value_type; +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized && detail::is_generic_tag_false(static_cast<method*>(0))) + return detail::fpclassify_imp(static_cast<value_type>(t), detail::generic_tag<true>()); + return detail::fpclassify_imp(static_cast<value_type>(t), method()); +#else + return detail::fpclassify_imp(static_cast<value_type>(t), method()); +#endif +} + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +template <> +inline int fpclassify<long double> BOOST_NO_MACRO_EXPAND(long double t) +{ + typedef detail::fp_traits<long double>::type traits; + typedef traits::method method; + typedef long double value_type; +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<long double>::is_specialized && detail::is_generic_tag_false(static_cast<method*>(0))) + return detail::fpclassify_imp(static_cast<value_type>(t), detail::generic_tag<true>()); + return detail::fpclassify_imp(static_cast<value_type>(t), method()); +#else + return detail::fpclassify_imp(static_cast<value_type>(t), method()); +#endif +} +#endif + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isfinite_impl(T x, native_tag const&) + { + return (std::isfinite)(x); + } +#endif + + template<class T> + inline bool isfinite_impl(T x, generic_tag<true> const&) + { + return x >= -(std::numeric_limits<T>::max)() + && x <= (std::numeric_limits<T>::max)(); + } + + template<class T> + inline bool isfinite_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isfinite_impl(x, generic_tag<true>()); +#endif + (void)x; // warning suppression. + return true; + } + + template<class T> + inline bool isfinite_impl(T x, ieee_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME detail::fp_traits<T>::type traits; + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent; + return a != traits::exponent; + } + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) +inline bool isfinite_impl BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::isfinite_impl(t, generic_tag<true>()); +} +#endif + +} + +template<class T> +inline bool (isfinite)(T x) +{ //!< \brief return true if floating-point type t is finite. + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + // typedef typename boost::is_floating_point<T>::type fp_tag; + typedef typename tools::promote_args_permissive<T>::type value_type; + return detail::isfinite_impl(static_cast<value_type>(x), method()); +} + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +template<> +inline bool (isfinite)(long double x) +{ //!< \brief return true if floating-point type t is finite. + typedef detail::fp_traits<long double>::type traits; + typedef traits::method method; + //typedef boost::is_floating_point<long double>::type fp_tag; + typedef long double value_type; + return detail::isfinite_impl(static_cast<value_type>(x), method()); +} +#endif + +//------------------------------------------------------------------------------ + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isnormal_impl(T x, native_tag const&) + { + return (std::isnormal)(x); + } +#endif + + template<class T> + inline bool isnormal_impl(T x, generic_tag<true> const&) + { + if(x < 0) x = -x; + return x >= (std::numeric_limits<T>::min)() + && x <= (std::numeric_limits<T>::max)(); + } + + template<class T> + inline bool isnormal_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isnormal_impl(x, generic_tag<true>()); +#endif + return !(x == 0); + } + + template<class T> + inline bool isnormal_impl(T x, ieee_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME detail::fp_traits<T>::type traits; + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::flag; + return (a != 0) && (a < traits::exponent); + } + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) +inline bool isnormal_impl BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::isnormal_impl(t, generic_tag<true>()); +} +#endif + +} + +template<class T> +inline bool (isnormal)(T x) +{ + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + //typedef typename boost::is_floating_point<T>::type fp_tag; + typedef typename tools::promote_args_permissive<T>::type value_type; + return detail::isnormal_impl(static_cast<value_type>(x), method()); +} + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +template<> +inline bool (isnormal)(long double x) +{ + typedef detail::fp_traits<long double>::type traits; + typedef traits::method method; + //typedef boost::is_floating_point<long double>::type fp_tag; + typedef long double value_type; + return detail::isnormal_impl(static_cast<value_type>(x), method()); +} +#endif + +//------------------------------------------------------------------------------ + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isinf_impl(T x, native_tag const&) + { + return (std::isinf)(x); + } +#endif + + template<class T> + inline bool isinf_impl(T x, generic_tag<true> const&) + { + (void)x; // in case the compiler thinks that x is unused because std::numeric_limits<T>::has_infinity is false + return std::numeric_limits<T>::has_infinity + && ( x == std::numeric_limits<T>::infinity() + || x == -std::numeric_limits<T>::infinity()); + } + + template<class T> + inline bool isinf_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isinf_impl(x, generic_tag<true>()); +#endif + (void)x; // warning suppression. + return false; + } + + template<class T> + inline bool isinf_impl(T x, ieee_copy_all_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::significand; + return a == traits::exponent; + } + + template<class T> + inline bool isinf_impl(T x, ieee_copy_leading_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::significand; + if(a != traits::exponent) + return false; + + traits::set_bits(x,0); + return x == 0; + } + +#if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && defined(BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) +inline bool isinf_impl BOOST_NO_MACRO_EXPAND(long double t, const native_tag&) +{ + return boost::math::detail::isinf_impl(t, generic_tag<true>()); +} +#endif + +} // namespace detail + +template<class T> +inline bool (isinf)(T x) +{ + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + // typedef typename boost::is_floating_point<T>::type fp_tag; + typedef typename tools::promote_args_permissive<T>::type value_type; + return detail::isinf_impl(static_cast<value_type>(x), method()); +} + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +template<> +inline bool (isinf)(long double x) +{ + typedef detail::fp_traits<long double>::type traits; + typedef traits::method method; + //typedef boost::is_floating_point<long double>::type fp_tag; + typedef long double value_type; + return detail::isinf_impl(static_cast<value_type>(x), method()); +} +#endif +#if defined(BOOST_MATH_USE_FLOAT128) && defined(BOOST_MATH_HAS_QUADMATH_H) +template<> +inline bool (isinf)(__float128 x) +{ + return ::isinfq(x); +} +#endif + +//------------------------------------------------------------------------------ + +namespace detail { + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline bool isnan_impl(T x, native_tag const&) + { + return (std::isnan)(x); + } +#endif + + template<class T> + inline bool isnan_impl(T x, generic_tag<true> const&) + { + return std::numeric_limits<T>::has_infinity + ? !(x <= std::numeric_limits<T>::infinity()) + : x != x; + } + + template<class T> + inline bool isnan_impl(T x, generic_tag<false> const&) + { +#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + if(std::numeric_limits<T>::is_specialized) + return isnan_impl(x, generic_tag<true>()); +#endif + (void)x; // warning suppression + return false; + } + + template<class T> + inline bool isnan_impl(T x, ieee_copy_all_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a &= traits::exponent | traits::significand; + return a > traits::exponent; + } + + template<class T> + inline bool isnan_impl(T x, ieee_copy_leading_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + + a &= traits::exponent | traits::significand; + if(a < traits::exponent) + return false; + + a &= traits::significand; + traits::set_bits(x,a); + return x != 0; + } + +} // namespace detail + +template<class T> +inline bool (isnan)(T x) +{ //!< \brief return true if floating-point type t is NaN (Not A Number). + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + // typedef typename boost::is_floating_point<T>::type fp_tag; + return detail::isnan_impl(x, method()); +} + +#ifdef isnan +template <> inline bool isnan BOOST_NO_MACRO_EXPAND<float>(float t){ return ::boost::math_detail::is_nan_helper(t, boost::true_type()); } +template <> inline bool isnan BOOST_NO_MACRO_EXPAND<double>(double t){ return ::boost::math_detail::is_nan_helper(t, boost::true_type()); } +template <> inline bool isnan BOOST_NO_MACRO_EXPAND<long double>(long double t){ return ::boost::math_detail::is_nan_helper(t, boost::true_type()); } +#elif defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) +template<> +inline bool (isnan)(long double x) +{ //!< \brief return true if floating-point type t is NaN (Not A Number). + typedef detail::fp_traits<long double>::type traits; + typedef traits::method method; + //typedef boost::is_floating_point<long double>::type fp_tag; + return detail::isnan_impl(x, method()); +} +#endif +#if defined(BOOST_MATH_USE_FLOAT128) && defined(BOOST_MATH_HAS_QUADMATH_H) +template<> +inline bool (isnan)(__float128 x) +{ + return ::isnanq(x); +} +#endif + +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_FPCLASSIFY_HPP + diff --git a/contrib/restricted/boost/math/include/boost/math/special_functions/math_fwd.hpp b/contrib/restricted/boost/math/include/boost/math/special_functions/math_fwd.hpp new file mode 100644 index 0000000000..4f44f56113 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/special_functions/math_fwd.hpp @@ -0,0 +1,1651 @@ +// math_fwd.hpp + +// TODO revise completely for new distribution classes. + +// Copyright Paul A. Bristow 2006. +// Copyright John Maddock 2006. + +// 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) + +// Omnibus list of forward declarations of math special functions. + +// IT = Integer type. +// RT = Real type (built-in floating-point types, float, double, long double) & User Defined Types +// AT = Integer or Real type + +#ifndef BOOST_MATH_SPECIAL_MATH_FWD_HPP +#define BOOST_MATH_SPECIAL_MATH_FWD_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <vector> +#include <boost/math/special_functions/detail/round_fwd.hpp> +#include <boost/math/tools/promotion.hpp> // for argument promotion. +#include <boost/math/policies/policy.hpp> +#include <boost/mpl/comparison.hpp> +#include <boost/utility/enable_if.hpp> +#include <boost/config/no_tr1/complex.hpp> + +#define BOOST_NO_MACRO_EXPAND /**/ + +namespace boost +{ + namespace math + { // Math functions (in roughly alphabetic order). + + // Beta functions. + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type + beta(RT1 a, RT2 b); // Beta function (2 arguments). + + template <class RT1, class RT2, class A> + typename tools::promote_args<RT1, RT2, A>::type + beta(RT1 a, RT2 b, A x); // Beta function (3 arguments). + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + beta(RT1 a, RT2 b, RT3 x, const Policy& pol); // Beta function (3 arguments). + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + betac(RT1 a, RT2 b, RT3 x); + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + betac(RT1 a, RT2 b, RT3 x, const Policy& pol); + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta(RT1 a, RT2 b, RT3 x); // Incomplete beta function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta(RT1 a, RT2 b, RT3 x, const Policy& pol); // Incomplete beta function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac(RT1 a, RT2 b, RT3 x); // Incomplete beta complement function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac(RT1 a, RT2 b, RT3 x, const Policy& pol); // Incomplete beta complement function. + + template <class T1, class T2, class T3, class T4> + typename tools::promote_args<T1, T2, T3, T4>::type + ibeta_inv(T1 a, T2 b, T3 p, T4* py); + + template <class T1, class T2, class T3, class T4, class Policy> + typename tools::promote_args<T1, T2, T3, T4>::type + ibeta_inv(T1 a, T2 b, T3 p, T4* py, const Policy& pol); + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inv(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inv(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inva(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_inva(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_invb(RT1 a, RT2 b, RT3 p); // Incomplete beta inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_invb(RT1 a, RT2 b, RT3 p, const Policy&); // Incomplete beta inverse function. + + template <class T1, class T2, class T3, class T4> + typename tools::promote_args<T1, T2, T3, T4>::type + ibetac_inv(T1 a, T2 b, T3 q, T4* py); + + template <class T1, class T2, class T3, class T4, class Policy> + typename tools::promote_args<T1, T2, T3, T4>::type + ibetac_inv(T1 a, T2 b, T3 q, T4* py, const Policy& pol); + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inv(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inv(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inva(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_inva(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_invb(RT1 a, RT2 b, RT3 q); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibetac_invb(RT1 a, RT2 b, RT3 q, const Policy&); // Incomplete beta complement inverse function. + + template <class RT1, class RT2, class RT3> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_derivative(RT1 a, RT2 b, RT3 x); // derivative of incomplete beta + + template <class RT1, class RT2, class RT3, class Policy> + typename tools::promote_args<RT1, RT2, RT3>::type + ibeta_derivative(RT1 a, RT2 b, RT3 x, const Policy& pol); // derivative of incomplete beta + + // Binomial: + template <class T, class Policy> + T binomial_coefficient(unsigned n, unsigned k, const Policy& pol); + template <class T> + T binomial_coefficient(unsigned n, unsigned k); + + // erf & erfc error functions. + template <class RT> // Error function. + typename tools::promote_args<RT>::type erf(RT z); + template <class RT, class Policy> // Error function. + typename tools::promote_args<RT>::type erf(RT z, const Policy&); + + template <class RT>// Error function complement. + typename tools::promote_args<RT>::type erfc(RT z); + template <class RT, class Policy>// Error function complement. + typename tools::promote_args<RT>::type erfc(RT z, const Policy&); + + template <class RT>// Error function inverse. + typename tools::promote_args<RT>::type erf_inv(RT z); + template <class RT, class Policy>// Error function inverse. + typename tools::promote_args<RT>::type erf_inv(RT z, const Policy& pol); + + template <class RT>// Error function complement inverse. + typename tools::promote_args<RT>::type erfc_inv(RT z); + template <class RT, class Policy>// Error function complement inverse. + typename tools::promote_args<RT>::type erfc_inv(RT z, const Policy& pol); + + // Polynomials: + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + legendre_next(unsigned l, T1 x, T2 Pl, T3 Plm1); + + template <class T> + typename tools::promote_args<T>::type + legendre_p(int l, T x); + template <class T> + typename tools::promote_args<T>::type + legendre_p_prime(int l, T x); + + + template <class T, class Policy> + inline std::vector<T> legendre_p_zeros(int l, const Policy& pol); + + template <class T> + inline std::vector<T> legendre_p_zeros(int l); + +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310) + template <class T, class Policy> + typename boost::enable_if_c<policies::is_policy<Policy>::value, typename tools::promote_args<T>::type>::type + legendre_p(int l, T x, const Policy& pol); + template <class T, class Policy> + inline typename boost::enable_if_c<policies::is_policy<Policy>::value, typename tools::promote_args<T>::type>::type + legendre_p_prime(int l, T x, const Policy& pol); +#endif + template <class T> + typename tools::promote_args<T>::type + legendre_q(unsigned l, T x); +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1310) + template <class T, class Policy> + typename boost::enable_if_c<policies::is_policy<Policy>::value, typename tools::promote_args<T>::type>::type + legendre_q(unsigned l, T x, const Policy& pol); +#endif + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + legendre_next(unsigned l, unsigned m, T1 x, T2 Pl, T3 Plm1); + + template <class T> + typename tools::promote_args<T>::type + legendre_p(int l, int m, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + legendre_p(int l, int m, T x, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + laguerre_next(unsigned n, T1 x, T2 Ln, T3 Lnm1); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + laguerre_next(unsigned n, unsigned l, T1 x, T2 Pl, T3 Plm1); + + template <class T> + typename tools::promote_args<T>::type + laguerre(unsigned n, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + laguerre(unsigned n, unsigned m, T x, const Policy& pol); + + template <class T1, class T2> + struct laguerre_result + { + typedef typename mpl::if_< + policies::is_policy<T2>, + typename tools::promote_args<T1>::type, + typename tools::promote_args<T2>::type + >::type type; + }; + + template <class T1, class T2> + typename laguerre_result<T1, T2>::type + laguerre(unsigned n, T1 m, T2 x); + + template <class T> + typename tools::promote_args<T>::type + hermite(unsigned n, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type + hermite(unsigned n, T x, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + hermite_next(unsigned n, T1 x, T2 Hn, T3 Hnm1); + + template<class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type chebyshev_next(T1 const & x, T2 const & Tn, T3 const & Tn_1); + + template <class Real, class Policy> + typename tools::promote_args<Real>::type + chebyshev_t(unsigned n, Real const & x, const Policy&); + template<class Real> + typename tools::promote_args<Real>::type chebyshev_t(unsigned n, Real const & x); + + template <class Real, class Policy> + typename tools::promote_args<Real>::type + chebyshev_u(unsigned n, Real const & x, const Policy&); + template<class Real> + typename tools::promote_args<Real>::type chebyshev_u(unsigned n, Real const & x); + + template <class Real, class Policy> + typename tools::promote_args<Real>::type + chebyshev_t_prime(unsigned n, Real const & x, const Policy&); + template<class Real> + typename tools::promote_args<Real>::type chebyshev_t_prime(unsigned n, Real const & x); + + template<class Real, class T2> + Real chebyshev_clenshaw_recurrence(const Real* const c, size_t length, const T2& x); + + template <class T1, class T2> + std::complex<typename tools::promote_args<T1, T2>::type> + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class Policy> + std::complex<typename tools::promote_args<T1, T2>::type> + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol); + + // Elliptic integrals: + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + ellint_rf(T1 x, T2 y, T3 z); + + template <class T1, class T2, class T3, class Policy> + typename tools::promote_args<T1, T2, T3>::type + ellint_rf(T1 x, T2 y, T3 z, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + ellint_rd(T1 x, T2 y, T3 z); + + template <class T1, class T2, class T3, class Policy> + typename tools::promote_args<T1, T2, T3>::type + ellint_rd(T1 x, T2 y, T3 z, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + ellint_rc(T1 x, T2 y); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + ellint_rc(T1 x, T2 y, const Policy& pol); + + template <class T1, class T2, class T3, class T4> + typename tools::promote_args<T1, T2, T3, T4>::type + ellint_rj(T1 x, T2 y, T3 z, T4 p); + + template <class T1, class T2, class T3, class T4, class Policy> + typename tools::promote_args<T1, T2, T3, T4>::type + ellint_rj(T1 x, T2 y, T3 z, T4 p, const Policy& pol); + + template <class T1, class T2, class T3> + typename tools::promote_args<T1, T2, T3>::type + ellint_rg(T1 x, T2 y, T3 z); + + template <class T1, class T2, class T3, class Policy> + typename tools::promote_args<T1, T2, T3>::type + ellint_rg(T1 x, T2 y, T3 z, const Policy& pol); + + template <typename T> + typename tools::promote_args<T>::type ellint_2(T k); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi, const Policy& pol); + + template <typename T> + typename tools::promote_args<T>::type ellint_1(T k); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi, const Policy& pol); + + template <typename T> + typename tools::promote_args<T>::type ellint_d(T k); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type ellint_d(T1 k, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type ellint_d(T1 k, T2 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi, const Policy& pol); + + namespace detail{ + + template <class T, class U, class V> + struct ellint_3_result + { + typedef typename mpl::if_< + policies::is_policy<V>, + typename tools::promote_args<T, U>::type, + typename tools::promote_args<T, U, V>::type + >::type type; + }; + + } // namespace detail + + + template <class T1, class T2, class T3> + typename detail::ellint_3_result<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi); + + template <class T1, class T2, class T3, class Policy> + typename tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v); + + // Factorial functions. + // Note: not for integral types, at present. + template <class RT> + struct max_factorial; + template <class RT> + RT factorial(unsigned int); + template <class RT, class Policy> + RT factorial(unsigned int, const Policy& pol); + template <class RT> + RT unchecked_factorial(unsigned int BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(RT)); + template <class RT> + RT double_factorial(unsigned i); + template <class RT, class Policy> + RT double_factorial(unsigned i, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type falling_factorial(RT x, unsigned n); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type falling_factorial(RT x, unsigned n, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type rising_factorial(RT x, int n); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type rising_factorial(RT x, int n, const Policy& pol); + + // Gamma functions. + template <class RT> + typename tools::promote_args<RT>::type tgamma(RT z); + + template <class RT> + typename tools::promote_args<RT>::type tgamma1pm1(RT z); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type tgamma1pm1(RT z, const Policy& pol); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type lgamma(RT z, int* sign); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type lgamma(RT z, int* sign, const Policy& pol); + + template <class RT> + typename tools::promote_args<RT>::type lgamma(RT x); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type lgamma(RT x, const Policy& pol); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z, const Policy&); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z, const Policy&); + + template <class RT1, class RT2> + typename tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z); + + template <class RT1, class RT2, class Policy> + typename tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x, const Policy&); + + // gamma inverse. + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q, const Policy&); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q, const Policy&); + + // digamma: + template <class T> + typename tools::promote_args<T>::type digamma(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type digamma(T x, const Policy&); + + // trigamma: + template <class T> + typename tools::promote_args<T>::type trigamma(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type trigamma(T x, const Policy&); + + // polygamma: + template <class T> + typename tools::promote_args<T>::type polygamma(int n, T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type polygamma(int n, T x, const Policy&); + + // Hypotenuse function sqrt(x ^ 2 + y ^ 2). + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + hypot(T1 x, T2 y); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + hypot(T1 x, T2 y, const Policy&); + + // cbrt - cube root. + template <class RT> + typename tools::promote_args<RT>::type cbrt(RT z); + + template <class RT, class Policy> + typename tools::promote_args<RT>::type cbrt(RT z, const Policy&); + + // log1p is log(x + 1) + template <class T> + typename tools::promote_args<T>::type log1p(T); + + template <class T, class Policy> + typename tools::promote_args<T>::type log1p(T, const Policy&); + + // log1pmx is log(x + 1) - x + template <class T> + typename tools::promote_args<T>::type log1pmx(T); + + template <class T, class Policy> + typename tools::promote_args<T>::type log1pmx(T, const Policy&); + + // Exp (x) minus 1 functions. + template <class T> + typename tools::promote_args<T>::type expm1(T); + + template <class T, class Policy> + typename tools::promote_args<T>::type expm1(T, const Policy&); + + // Power - 1 + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type + powm1(const T1 a, const T2 z); + + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type + powm1(const T1 a, const T2 z, const Policy&); + + // sqrt(1+x) - 1 + template <class T> + typename tools::promote_args<T>::type sqrt1pm1(const T& val); + + template <class T, class Policy> + typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy&); + + // sinus cardinals: + template <class T> + typename tools::promote_args<T>::type sinc_pi(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type sinc_pi(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type sinhc_pi(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type sinhc_pi(T x, const Policy&); + + // inverse hyperbolics: + template<typename T> + typename tools::promote_args<T>::type asinh(T x); + + template<typename T, class Policy> + typename tools::promote_args<T>::type asinh(T x, const Policy&); + + template<typename T> + typename tools::promote_args<T>::type acosh(T x); + + template<typename T, class Policy> + typename tools::promote_args<T>::type acosh(T x, const Policy&); + + template<typename T> + typename tools::promote_args<T>::type atanh(T x); + + template<typename T, class Policy> + typename tools::promote_args<T>::type atanh(T x, const Policy&); + + namespace detail{ + + typedef mpl::int_<0> bessel_no_int_tag; // No integer optimisation possible. + typedef mpl::int_<1> bessel_maybe_int_tag; // Maybe integer optimisation. + typedef mpl::int_<2> bessel_int_tag; // Definite integer optimistaion. + + template <class T1, class T2, class Policy> + struct bessel_traits + { + typedef typename mpl::if_< + is_integral<T1>, + typename tools::promote_args<T2>::type, + typename tools::promote_args<T1, T2>::type + >::type result_type; + + typedef typename policies::precision<result_type, Policy>::type precision_type; + + typedef typename mpl::if_< + mpl::or_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::greater<precision_type, mpl::int_<64> > >, + bessel_no_int_tag, + typename mpl::if_< + is_integral<T1>, + bessel_int_tag, + bessel_maybe_int_tag + >::type + >::type optimisation_tag; + typedef typename mpl::if_< + mpl::or_< + mpl::less_equal<precision_type, mpl::int_<0> >, + mpl::greater<precision_type, mpl::int_<113> > >, + bessel_no_int_tag, + typename mpl::if_< + is_integral<T1>, + bessel_int_tag, + bessel_maybe_int_tag + >::type + >::type optimisation_tag128; + }; + } // detail + + // Bessel functions: + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_j(T1 v, T2 x, const Policy& pol); + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_j_prime(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_j(T1 v, T2 x); + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_j_prime(T1 v, T2 x); + + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type sph_bessel(unsigned v, T x, const Policy& pol); + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type sph_bessel_prime(unsigned v, T x, const Policy& pol); + + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_bessel(unsigned v, T x); + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_bessel_prime(unsigned v, T x); + + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_i(T1 v, T2 x, const Policy& pol); + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_i_prime(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_i(T1 v, T2 x); + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_i_prime(T1 v, T2 x); + + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_k(T1 v, T2 x, const Policy& pol); + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_bessel_k_prime(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_k(T1 v, T2 x); + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_bessel_k_prime(T1 v, T2 x); + + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_neumann(T1 v, T2 x, const Policy& pol); + template <class T1, class T2, class Policy> + typename detail::bessel_traits<T1, T2, Policy>::result_type cyl_neumann_prime(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_neumann(T1 v, T2 x); + template <class T1, class T2> + typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type cyl_neumann_prime(T1 v, T2 x); + + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type sph_neumann(unsigned v, T x, const Policy& pol); + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type sph_neumann_prime(unsigned v, T x, const Policy& pol); + + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_neumann(unsigned v, T x); + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type sph_neumann_prime(unsigned v, T x); + + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type cyl_bessel_j_zero(T v, int m, const Policy& pol); + + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type cyl_bessel_j_zero(T v, int m); + + template <class T, class OutputIterator> + OutputIterator cyl_bessel_j_zero(T v, + int start_index, + unsigned number_of_zeros, + OutputIterator out_it); + + template <class T, class OutputIterator, class Policy> + OutputIterator cyl_bessel_j_zero(T v, + int start_index, + unsigned number_of_zeros, + OutputIterator out_it, + const Policy&); + + template <class T, class Policy> + typename detail::bessel_traits<T, T, Policy>::result_type cyl_neumann_zero(T v, int m, const Policy& pol); + + template <class T> + typename detail::bessel_traits<T, T, policies::policy<> >::result_type cyl_neumann_zero(T v, int m); + + template <class T, class OutputIterator> + OutputIterator cyl_neumann_zero(T v, + int start_index, + unsigned number_of_zeros, + OutputIterator out_it); + + template <class T, class OutputIterator, class Policy> + OutputIterator cyl_neumann_zero(T v, + int start_index, + unsigned number_of_zeros, + OutputIterator out_it, + const Policy&); + + template <class T1, class T2> + std::complex<typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type> cyl_hankel_1(T1 v, T2 x); + + template <class T1, class T2, class Policy> + std::complex<typename detail::bessel_traits<T1, T2, Policy>::result_type> cyl_hankel_1(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2, class Policy> + std::complex<typename detail::bessel_traits<T1, T2, Policy>::result_type> cyl_hankel_2(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + std::complex<typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type> cyl_hankel_2(T1 v, T2 x); + + template <class T1, class T2, class Policy> + std::complex<typename detail::bessel_traits<T1, T2, Policy>::result_type> sph_hankel_1(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + std::complex<typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type> sph_hankel_1(T1 v, T2 x); + + template <class T1, class T2, class Policy> + std::complex<typename detail::bessel_traits<T1, T2, Policy>::result_type> sph_hankel_2(T1 v, T2 x, const Policy& pol); + + template <class T1, class T2> + std::complex<typename detail::bessel_traits<T1, T2, policies::policy<> >::result_type> sph_hankel_2(T1 v, T2 x); + + template <class T, class Policy> + typename tools::promote_args<T>::type airy_ai(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type airy_ai(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type airy_bi(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type airy_bi(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type airy_ai_prime(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type airy_ai_prime(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type airy_bi_prime(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type airy_bi_prime(T x); + + template <class T> + T airy_ai_zero(int m); + template <class T, class Policy> + T airy_ai_zero(int m, const Policy&); + + template <class OutputIterator> + OutputIterator airy_ai_zero( + int start_index, + unsigned number_of_zeros, + OutputIterator out_it); + template <class OutputIterator, class Policy> + OutputIterator airy_ai_zero( + int start_index, + unsigned number_of_zeros, + OutputIterator out_it, + const Policy&); + + template <class T> + T airy_bi_zero(int m); + template <class T, class Policy> + T airy_bi_zero(int m, const Policy&); + + template <class OutputIterator> + OutputIterator airy_bi_zero( + int start_index, + unsigned number_of_zeros, + OutputIterator out_it); + template <class OutputIterator, class Policy> + OutputIterator airy_bi_zero( + int start_index, + unsigned number_of_zeros, + OutputIterator out_it, + const Policy&); + + template <class T, class Policy> + typename tools::promote_args<T>::type sin_pi(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type sin_pi(T x); + + template <class T, class Policy> + typename tools::promote_args<T>::type cos_pi(T x, const Policy&); + + template <class T> + typename tools::promote_args<T>::type cos_pi(T x); + + template <class T> + int fpclassify BOOST_NO_MACRO_EXPAND(T t); + + template <class T> + bool isfinite BOOST_NO_MACRO_EXPAND(T z); + + template <class T> + bool isinf BOOST_NO_MACRO_EXPAND(T t); + + template <class T> + bool isnan BOOST_NO_MACRO_EXPAND(T t); + + template <class T> + bool isnormal BOOST_NO_MACRO_EXPAND(T t); + + template<class T> + int signbit BOOST_NO_MACRO_EXPAND(T x); + + template <class T> + int sign BOOST_NO_MACRO_EXPAND(const T& z); + + template <class T, class U> + typename tools::promote_args_permissive<T, U>::type copysign BOOST_NO_MACRO_EXPAND(const T& x, const U& y); + + template <class T> + typename tools::promote_args_permissive<T>::type changesign BOOST_NO_MACRO_EXPAND(const T& z); + + // Exponential integrals: + namespace detail{ + + template <class T, class U> + struct expint_result + { + typedef typename mpl::if_< + policies::is_policy<U>, + typename tools::promote_args<T>::type, + typename tools::promote_args<U>::type + >::type type; + }; + + } // namespace detail + + template <class T, class Policy> + typename tools::promote_args<T>::type expint(unsigned n, T z, const Policy&); + + template <class T, class U> + typename detail::expint_result<T, U>::type expint(T const z, U const u); + + template <class T> + typename tools::promote_args<T>::type expint(T z); + + // Zeta: + template <class T, class Policy> + typename tools::promote_args<T>::type zeta(T s, const Policy&); + + // Owen's T function: + template <class T1, class T2, class Policy> + typename tools::promote_args<T1, T2>::type owens_t(T1 h, T2 a, const Policy& pol); + + template <class T1, class T2> + typename tools::promote_args<T1, T2>::type owens_t(T1 h, T2 a); + + // Jacobi Functions: + template <class T, class U, class V, class Policy> + typename tools::promote_args<T, U, V>::type jacobi_elliptic(T k, U theta, V* pcn, V* pdn, const Policy&); + + template <class T, class U, class V> + typename tools::promote_args<T, U, V>::type jacobi_elliptic(T k, U theta, V* pcn = 0, V* pdn = 0); + + template <class U, class T, class Policy> + typename tools::promote_args<T, U>::type jacobi_sn(U k, T theta, const Policy& pol); + + template <class U, class T> + typename tools::promote_args<T, U>::type jacobi_sn(U k, T theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_cn(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_cn(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_dn(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_dn(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_cd(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_cd(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_dc(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_dc(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_ns(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_ns(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_sd(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_sd(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_ds(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_ds(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_nc(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_nc(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_nd(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_nd(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_sc(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_sc(T k, U theta); + + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type jacobi_cs(T k, U theta, const Policy& pol); + + template <class T, class U> + typename tools::promote_args<T, U>::type jacobi_cs(T k, U theta); + + + template <class T> + typename tools::promote_args<T>::type zeta(T s); + + // pow: + template <int N, typename T, class Policy> + typename tools::promote_args<T>::type pow(T base, const Policy& policy); + + template <int N, typename T> + typename tools::promote_args<T>::type pow(T base); + + // next: + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type nextafter(const T&, const U&, const Policy&); + template <class T, class U> + typename tools::promote_args<T, U>::type nextafter(const T&, const U&); + template <class T, class Policy> + typename tools::promote_args<T>::type float_next(const T&, const Policy&); + template <class T> + typename tools::promote_args<T>::type float_next(const T&); + template <class T, class Policy> + typename tools::promote_args<T>::type float_prior(const T&, const Policy&); + template <class T> + typename tools::promote_args<T>::type float_prior(const T&); + template <class T, class U, class Policy> + typename tools::promote_args<T, U>::type float_distance(const T&, const U&, const Policy&); + template <class T, class U> + typename tools::promote_args<T, U>::type float_distance(const T&, const U&); + template <class T, class Policy> + typename tools::promote_args<T>::type float_advance(T val, int distance, const Policy& pol); + template <class T> + typename tools::promote_args<T>::type float_advance(const T& val, int distance); + + template <class T, class Policy> + typename tools::promote_args<T>::type ulp(const T& val, const Policy& pol); + template <class T> + typename tools::promote_args<T>::type ulp(const T& val); + + template <class T, class U> + typename tools::promote_args<T, U>::type relative_difference(const T&, const U&); + template <class T, class U> + typename tools::promote_args<T, U>::type epsilon_difference(const T&, const U&); + + template<class T> + BOOST_MATH_CONSTEXPR_TABLE_FUNCTION T unchecked_bernoulli_b2n(const std::size_t n); + template <class T, class Policy> + T bernoulli_b2n(const int i, const Policy &pol); + template <class T> + T bernoulli_b2n(const int i); + template <class T, class OutputIterator, class Policy> + OutputIterator bernoulli_b2n(const int start_index, + const unsigned number_of_bernoullis_b2n, + OutputIterator out_it, + const Policy& pol); + template <class T, class OutputIterator> + OutputIterator bernoulli_b2n(const int start_index, + const unsigned number_of_bernoullis_b2n, + OutputIterator out_it); + template <class T, class Policy> + T tangent_t2n(const int i, const Policy &pol); + template <class T> + T tangent_t2n(const int i); + template <class T, class OutputIterator, class Policy> + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_bernoullis_b2n, + OutputIterator out_it, + const Policy& pol); + template <class T, class OutputIterator> + OutputIterator tangent_t2n(const int start_index, + const unsigned number_of_bernoullis_b2n, + OutputIterator out_it); + + } // namespace math +} // namespace boost + +#ifdef BOOST_HAS_LONG_LONG +#define BOOST_MATH_DETAIL_LL_FUNC(Policy)\ + \ + template <class T>\ + inline T modf(const T& v, boost::long_long_type* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <class T>\ + inline boost::long_long_type lltrunc(const T& v){ using boost::math::lltrunc; return lltrunc(v, Policy()); }\ + \ + template <class T>\ + inline boost::long_long_type llround(const T& v){ using boost::math::llround; return llround(v, Policy()); }\ + +#else +#define BOOST_MATH_DETAIL_LL_FUNC(Policy) +#endif + +#define BOOST_MATH_DECLARE_SPECIAL_FUNCTIONS(Policy)\ + \ + BOOST_MATH_DETAIL_LL_FUNC(Policy)\ + \ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type \ + beta(RT1 a, RT2 b) { return ::boost::math::beta(a, b, Policy()); }\ +\ + template <class RT1, class RT2, class A>\ + inline typename boost::math::tools::promote_args<RT1, RT2, A>::type \ + beta(RT1 a, RT2 b, A x){ return ::boost::math::beta(a, b, x, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + betac(RT1 a, RT2 b, RT3 x) { return ::boost::math::betac(a, b, x, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibeta(a, b, x, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibetac(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibetac(a, b, x, Policy()); }\ +\ + template <class T1, class T2, class T3, class T4>\ + inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \ + ibeta_inv(T1 a, T2 b, T3 p, T4* py){ return ::boost::math::ibeta_inv(a, b, p, py, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_inv(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_inv(a, b, p, Policy()); }\ +\ + template <class T1, class T2, class T3, class T4>\ + inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \ + ibetac_inv(T1 a, T2 b, T3 q, T4* py){ return ::boost::math::ibetac_inv(a, b, q, py, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_inva(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_inva(a, b, p, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ibetac_inva(T1 a, T2 b, T3 q){ return ::boost::math::ibetac_inva(a, b, q, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_invb(RT1 a, RT2 b, RT3 p){ return ::boost::math::ibeta_invb(a, b, p, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ibetac_invb(T1 a, T2 b, T3 q){ return ::boost::math::ibetac_invb(a, b, q, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibetac_inv(RT1 a, RT2 b, RT3 q){ return ::boost::math::ibetac_inv(a, b, q, Policy()); }\ +\ + template <class RT1, class RT2, class RT3>\ + inline typename boost::math::tools::promote_args<RT1, RT2, RT3>::type \ + ibeta_derivative(RT1 a, RT2 b, RT3 x){ return ::boost::math::ibeta_derivative(a, b, x, Policy()); }\ +\ + template <class T> T binomial_coefficient(unsigned n, unsigned k){ return ::boost::math::binomial_coefficient<T, Policy>(n, k, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erf(RT z) { return ::boost::math::erf(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erfc(RT z){ return ::boost::math::erfc(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erf_inv(RT z) { return ::boost::math::erf_inv(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type erfc_inv(RT z){ return ::boost::math::erfc_inv(z, Policy()); }\ +\ + using boost::math::legendre_next;\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + legendre_p(int l, T x){ return ::boost::math::legendre_p(l, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + legendre_p_prime(int l, T x){ return ::boost::math::legendre_p(l, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + legendre_q(unsigned l, T x){ return ::boost::math::legendre_q(l, x, Policy()); }\ +\ + using ::boost::math::legendre_next;\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + legendre_p(int l, int m, T x){ return ::boost::math::legendre_p(l, m, x, Policy()); }\ +\ + using ::boost::math::laguerre_next;\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + laguerre(unsigned n, T x){ return ::boost::math::laguerre(n, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::laguerre_result<T1, T2>::type \ + laguerre(unsigned n, T1 m, T2 x) { return ::boost::math::laguerre(n, m, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type \ + hermite(unsigned n, T x){ return ::boost::math::hermite(n, x, Policy()); }\ +\ + using boost::math::hermite_next;\ +\ + using boost::math::chebyshev_next;\ +\ + template<class Real>\ + Real chebyshev_t(unsigned n, Real const & x){ return ::boost::math::chebyshev_t(n, x, Policy()); }\ +\ + template<class Real>\ + Real chebyshev_u(unsigned n, Real const & x){ return ::boost::math::chebyshev_u(n, x, Policy()); }\ +\ + template<class Real>\ + Real chebyshev_t_prime(unsigned n, Real const & x){ return ::boost::math::chebyshev_t_prime(n, x, Policy()); }\ +\ + using ::boost::math::chebyshev_clenshaw_recurrence;\ +\ + template <class T1, class T2>\ + inline std::complex<typename boost::math::tools::promote_args<T1, T2>::type> \ + spherical_harmonic(unsigned n, int m, T1 theta, T2 phi){ return boost::math::spherical_harmonic(n, m, theta, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + spherical_harmonic_r(unsigned n, int m, T1 theta, T2 phi){ return ::boost::math::spherical_harmonic_r(n, m, theta, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi){ return boost::math::spherical_harmonic_i(n, m, theta, phi, Policy()); }\ +\ + template <class T1, class T2, class Policy>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + spherical_harmonic_i(unsigned n, int m, T1 theta, T2 phi, const Policy& pol);\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ellint_rf(T1 x, T2 y, T3 z){ return ::boost::math::ellint_rf(x, y, z, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ellint_rd(T1 x, T2 y, T3 z){ return ::boost::math::ellint_rd(x, y, z, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + ellint_rc(T1 x, T2 y){ return ::boost::math::ellint_rc(x, y, Policy()); }\ +\ + template <class T1, class T2, class T3, class T4>\ + inline typename boost::math::tools::promote_args<T1, T2, T3, T4>::type \ + ellint_rj(T1 x, T2 y, T3 z, T4 p){ return boost::math::ellint_rj(x, y, z, p, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type \ + ellint_rg(T1 x, T2 y, T3 z){ return ::boost::math::ellint_rg(x, y, z, Policy()); }\ + \ + template <typename T>\ + inline typename boost::math::tools::promote_args<T>::type ellint_2(T k){ return boost::math::ellint_2(k, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type ellint_2(T1 k, T2 phi){ return boost::math::ellint_2(k, phi, Policy()); }\ +\ + template <typename T>\ + inline typename boost::math::tools::promote_args<T>::type ellint_d(T k){ return boost::math::ellint_d(k, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type ellint_d(T1 k, T2 phi){ return boost::math::ellint_d(k, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type jacobi_zeta(T1 k, T2 phi){ return boost::math::jacobi_zeta(k, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type heuman_lambda(T1 k, T2 phi){ return boost::math::heuman_lambda(k, phi, Policy()); }\ +\ + template <typename T>\ + inline typename boost::math::tools::promote_args<T>::type ellint_1(T k){ return boost::math::ellint_1(k, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type ellint_1(T1 k, T2 phi){ return boost::math::ellint_1(k, phi, Policy()); }\ +\ + template <class T1, class T2, class T3>\ + inline typename boost::math::tools::promote_args<T1, T2, T3>::type ellint_3(T1 k, T2 v, T3 phi){ return boost::math::ellint_3(k, v, phi, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type ellint_3(T1 k, T2 v){ return boost::math::ellint_3(k, v, Policy()); }\ +\ + using boost::math::max_factorial;\ + template <class RT>\ + inline RT factorial(unsigned int i) { return boost::math::factorial<RT>(i, Policy()); }\ + using boost::math::unchecked_factorial;\ + template <class RT>\ + inline RT double_factorial(unsigned i){ return boost::math::double_factorial<RT>(i, Policy()); }\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type falling_factorial(RT x, unsigned n){ return boost::math::falling_factorial(x, n, Policy()); }\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type rising_factorial(RT x, unsigned n){ return boost::math::rising_factorial(x, n, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type tgamma(RT z){ return boost::math::tgamma(z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type tgamma1pm1(RT z){ return boost::math::tgamma1pm1(z, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type tgamma(RT1 a, RT2 z){ return boost::math::tgamma(a, z, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type lgamma(RT z, int* sign){ return boost::math::lgamma(z, sign, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type lgamma(RT x){ return boost::math::lgamma(x, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type tgamma_lower(RT1 a, RT2 z){ return boost::math::tgamma_lower(a, z, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type gamma_q(RT1 a, RT2 z){ return boost::math::gamma_q(a, z, Policy()); }\ +\ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type gamma_p(RT1 a, RT2 z){ return boost::math::gamma_p(a, z, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type tgamma_delta_ratio(T1 z, T2 delta){ return boost::math::tgamma_delta_ratio(z, delta, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type tgamma_ratio(T1 a, T2 b) { return boost::math::tgamma_ratio(a, b, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_derivative(T1 a, T2 x){ return boost::math::gamma_p_derivative(a, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_inv(T1 a, T2 p){ return boost::math::gamma_p_inv(a, p, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_p_inva(T1 a, T2 p){ return boost::math::gamma_p_inva(a, p, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_q_inv(T1 a, T2 q){ return boost::math::gamma_q_inv(a, q, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type gamma_q_inva(T1 a, T2 q){ return boost::math::gamma_q_inva(a, q, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type digamma(T x){ return boost::math::digamma(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type trigamma(T x){ return boost::math::trigamma(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type polygamma(int n, T x){ return boost::math::polygamma(n, x, Policy()); }\ + \ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + hypot(T1 x, T2 y){ return boost::math::hypot(x, y, Policy()); }\ +\ + template <class RT>\ + inline typename boost::math::tools::promote_args<RT>::type cbrt(RT z){ return boost::math::cbrt(z, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type log1p(T x){ return boost::math::log1p(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type log1pmx(T x){ return boost::math::log1pmx(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type expm1(T x){ return boost::math::expm1(x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::tools::promote_args<T1, T2>::type \ + powm1(const T1 a, const T2 z){ return boost::math::powm1(a, z, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sqrt1pm1(const T& val){ return boost::math::sqrt1pm1(val, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sinc_pi(T x){ return boost::math::sinc_pi(x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sinhc_pi(T x){ return boost::math::sinhc_pi(x, Policy()); }\ +\ + template<typename T>\ + inline typename boost::math::tools::promote_args<T>::type asinh(const T x){ return boost::math::asinh(x, Policy()); }\ +\ + template<typename T>\ + inline typename boost::math::tools::promote_args<T>::type acosh(const T x){ return boost::math::acosh(x, Policy()); }\ +\ + template<typename T>\ + inline typename boost::math::tools::promote_args<T>::type atanh(const T x){ return boost::math::atanh(x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type cyl_bessel_j(T1 v, T2 x)\ + { return boost::math::cyl_bessel_j(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type cyl_bessel_j_prime(T1 v, T2 x)\ + { return boost::math::cyl_bessel_j_prime(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type sph_bessel(unsigned v, T x)\ + { return boost::math::sph_bessel(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type sph_bessel_prime(unsigned v, T x)\ + { return boost::math::sph_bessel_prime(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_bessel_i(T1 v, T2 x) { return boost::math::cyl_bessel_i(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_bessel_i_prime(T1 v, T2 x) { return boost::math::cyl_bessel_i_prime(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_bessel_k(T1 v, T2 x) { return boost::math::cyl_bessel_k(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_bessel_k_prime(T1 v, T2 x) { return boost::math::cyl_bessel_k_prime(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_neumann(T1 v, T2 x){ return boost::math::cyl_neumann(v, x, Policy()); }\ +\ + template <class T1, class T2>\ + inline typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type \ + cyl_neumann_prime(T1 v, T2 x){ return boost::math::cyl_neumann_prime(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type \ + sph_neumann(unsigned v, T x){ return boost::math::sph_neumann(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type \ + sph_neumann_prime(unsigned v, T x){ return boost::math::sph_neumann_prime(v, x, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type cyl_bessel_j_zero(T v, int m)\ + { return boost::math::cyl_bessel_j_zero(v, m, Policy()); }\ +\ +template <class OutputIterator, class T>\ + inline void cyl_bessel_j_zero(T v,\ + int start_index,\ + unsigned number_of_zeros,\ + OutputIterator out_it)\ + { boost::math::cyl_bessel_j_zero(v, start_index, number_of_zeros, out_it, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::detail::bessel_traits<T, T, Policy >::result_type cyl_neumann_zero(T v, int m)\ + { return boost::math::cyl_neumann_zero(v, m, Policy()); }\ +\ +template <class OutputIterator, class T>\ + inline void cyl_neumann_zero(T v,\ + int start_index,\ + unsigned number_of_zeros,\ + OutputIterator out_it)\ + { boost::math::cyl_neumann_zero(v, start_index, number_of_zeros, out_it, Policy()); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type sin_pi(T x){ return boost::math::sin_pi(x); }\ +\ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type cos_pi(T x){ return boost::math::cos_pi(x); }\ +\ + using boost::math::fpclassify;\ + using boost::math::isfinite;\ + using boost::math::isinf;\ + using boost::math::isnan;\ + using boost::math::isnormal;\ + using boost::math::signbit;\ + using boost::math::sign;\ + using boost::math::copysign;\ + using boost::math::changesign;\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T,U>::type expint(T const& z, U const& u)\ + { return boost::math::expint(z, u, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type expint(T z){ return boost::math::expint(z, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type zeta(T s){ return boost::math::zeta(s, Policy()); }\ + \ + template <class T>\ + inline T round(const T& v){ using boost::math::round; return round(v, Policy()); }\ + \ + template <class T>\ + inline int iround(const T& v){ using boost::math::iround; return iround(v, Policy()); }\ + \ + template <class T>\ + inline long lround(const T& v){ using boost::math::lround; return lround(v, Policy()); }\ + \ + template <class T>\ + inline T trunc(const T& v){ using boost::math::trunc; return trunc(v, Policy()); }\ + \ + template <class T>\ + inline int itrunc(const T& v){ using boost::math::itrunc; return itrunc(v, Policy()); }\ + \ + template <class T>\ + inline long ltrunc(const T& v){ using boost::math::ltrunc; return ltrunc(v, Policy()); }\ + \ + template <class T>\ + inline T modf(const T& v, T* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <class T>\ + inline T modf(const T& v, int* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <class T>\ + inline T modf(const T& v, long* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\ + \ + template <int N, class T>\ + inline typename boost::math::tools::promote_args<T>::type pow(T v){ return boost::math::pow<N>(v, Policy()); }\ + \ + template <class T> T nextafter(const T& a, const T& b){ return boost::math::nextafter(a, b, Policy()); }\ + template <class T> T float_next(const T& a){ return boost::math::float_next(a, Policy()); }\ + template <class T> T float_prior(const T& a){ return boost::math::float_prior(a, Policy()); }\ + template <class T> T float_distance(const T& a, const T& b){ return boost::math::float_distance(a, b, Policy()); }\ + template <class T> T ulp(const T& a){ return boost::math::ulp(a, Policy()); }\ + \ + template <class RT1, class RT2>\ + inline typename boost::math::tools::promote_args<RT1, RT2>::type owens_t(RT1 a, RT2 z){ return boost::math::owens_t(a, z, Policy()); }\ + \ + template <class T1, class T2>\ + inline std::complex<typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type> cyl_hankel_1(T1 v, T2 x)\ + { return boost::math::cyl_hankel_1(v, x, Policy()); }\ + \ + template <class T1, class T2>\ + inline std::complex<typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type> cyl_hankel_2(T1 v, T2 x)\ + { return boost::math::cyl_hankel_2(v, x, Policy()); }\ + \ + template <class T1, class T2>\ + inline std::complex<typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type> sph_hankel_1(T1 v, T2 x)\ + { return boost::math::sph_hankel_1(v, x, Policy()); }\ + \ + template <class T1, class T2>\ + inline std::complex<typename boost::math::detail::bessel_traits<T1, T2, Policy >::result_type> sph_hankel_2(T1 v, T2 x)\ + { return boost::math::sph_hankel_2(v, x, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type jacobi_elliptic(T k, T theta, T* pcn, T* pdn)\ + { return boost::math::jacobi_elliptic(k, theta, pcn, pdn, Policy()); }\ + \ + template <class U, class T>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_sn(U k, T theta)\ + { return boost::math::jacobi_sn(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_cn(T k, U theta)\ + { return boost::math::jacobi_cn(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_dn(T k, U theta)\ + { return boost::math::jacobi_dn(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_cd(T k, U theta)\ + { return boost::math::jacobi_cd(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_dc(T k, U theta)\ + { return boost::math::jacobi_dc(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_ns(T k, U theta)\ + { return boost::math::jacobi_ns(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_sd(T k, U theta)\ + { return boost::math::jacobi_sd(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_ds(T k, U theta)\ + { return boost::math::jacobi_ds(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_nc(T k, U theta)\ + { return boost::math::jacobi_nc(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_nd(T k, U theta)\ + { return boost::math::jacobi_nd(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_sc(T k, U theta)\ + { return boost::math::jacobi_sc(k, theta, Policy()); }\ + \ + template <class T, class U>\ + inline typename boost::math::tools::promote_args<T, U>::type jacobi_cs(T k, U theta)\ + { return boost::math::jacobi_cs(k, theta, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type airy_ai(T x)\ + { return boost::math::airy_ai(x, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type airy_bi(T x)\ + { return boost::math::airy_bi(x, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type airy_ai_prime(T x)\ + { return boost::math::airy_ai_prime(x, Policy()); }\ + \ + template <class T>\ + inline typename boost::math::tools::promote_args<T>::type airy_bi_prime(T x)\ + { return boost::math::airy_bi_prime(x, Policy()); }\ + \ + template <class T>\ + inline T airy_ai_zero(int m)\ + { return boost::math::airy_ai_zero<T>(m, Policy()); }\ + template <class T, class OutputIterator>\ + OutputIterator airy_ai_zero(int start_index, unsigned number_of_zeros, OutputIterator out_it)\ + { return boost::math::airy_ai_zero<T>(start_index, number_of_zeros, out_it, Policy()); }\ + \ + template <class T>\ + inline T airy_bi_zero(int m)\ + { return boost::math::airy_bi_zero<T>(m, Policy()); }\ + template <class T, class OutputIterator>\ + OutputIterator airy_bi_zero(int start_index, unsigned number_of_zeros, OutputIterator out_it)\ + { return boost::math::airy_bi_zero<T>(start_index, number_of_zeros, out_it, Policy()); }\ + \ + template <class T>\ + T bernoulli_b2n(const int i)\ + { return boost::math::bernoulli_b2n<T>(i, Policy()); }\ + template <class T, class OutputIterator>\ + OutputIterator bernoulli_b2n(int start_index, unsigned number_of_bernoullis_b2n, OutputIterator out_it)\ + { return boost::math::bernoulli_b2n<T>(start_index, number_of_bernoullis_b2n, out_it, Policy()); }\ + \ + template <class T>\ + T tangent_t2n(const int i)\ + { return boost::math::tangent_t2n<T>(i, Policy()); }\ + template <class T, class OutputIterator>\ + OutputIterator tangent_t2n(int start_index, unsigned number_of_bernoullis_b2n, OutputIterator out_it)\ + { return boost::math::tangent_t2n<T>(start_index, number_of_bernoullis_b2n, out_it, Policy()); }\ + \ + + + + + +#endif // BOOST_MATH_SPECIAL_MATH_FWD_HPP diff --git a/contrib/restricted/boost/math/include/boost/math/special_functions/next.hpp b/contrib/restricted/boost/math/include/boost/math/special_functions/next.hpp new file mode 100644 index 0000000000..a63983e1c3 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/special_functions/next.hpp @@ -0,0 +1,858 @@ +// (C) Copyright John Maddock 2008. +// 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) + +#ifndef BOOST_MATH_SPECIAL_NEXT_HPP +#define BOOST_MATH_SPECIAL_NEXT_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/fpclassify.hpp> +#include <boost/math/special_functions/sign.hpp> +#include <boost/math/special_functions/trunc.hpp> + +#include <float.h> + +#if !defined(_CRAYC) && !defined(__CUDACC__) && (!defined(__GNUC__) || (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ > 3))) +#if (defined(_M_IX86_FP) && (_M_IX86_FP >= 2)) || defined(__SSE2__) +#include "xmmintrin.h" +#define BOOST_MATH_CHECK_SSE2 +#endif +#endif + +namespace boost{ namespace math{ + + namespace concepts { + + class real_concept; + class std_real_concept; + + } + +namespace detail{ + +template <class T> +struct has_hidden_guard_digits; +template <> +struct has_hidden_guard_digits<float> : public mpl::false_ {}; +template <> +struct has_hidden_guard_digits<double> : public mpl::false_ {}; +template <> +struct has_hidden_guard_digits<long double> : public mpl::false_ {}; +#ifdef BOOST_HAS_FLOAT128 +template <> +struct has_hidden_guard_digits<__float128> : public mpl::false_ {}; +#endif +template <> +struct has_hidden_guard_digits<boost::math::concepts::real_concept> : public mpl::false_ {}; +template <> +struct has_hidden_guard_digits<boost::math::concepts::std_real_concept> : public mpl::false_ {}; + +template <class T, bool b> +struct has_hidden_guard_digits_10 : public mpl::false_ {}; +template <class T> +struct has_hidden_guard_digits_10<T, true> : public mpl::bool_<(std::numeric_limits<T>::digits10 != std::numeric_limits<T>::max_digits10)> {}; + +template <class T> +struct has_hidden_guard_digits + : public has_hidden_guard_digits_10<T, + std::numeric_limits<T>::is_specialized + && (std::numeric_limits<T>::radix == 10) > +{}; + +template <class T> +inline const T& normalize_value(const T& val, const mpl::false_&) { return val; } +template <class T> +inline T normalize_value(const T& val, const mpl::true_&) +{ + BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); + + boost::intmax_t shift = std::numeric_limits<T>::digits - ilogb(val) - 1; + T result = scalbn(val, shift); + result = round(result); + return scalbn(result, -shift); +} + +template <class T> +inline T get_smallest_value(mpl::true_ const&) +{ + // + // numeric_limits lies about denorms being present - particularly + // when this can be turned on or off at runtime, as is the case + // when using the SSE2 registers in DAZ or FTZ mode. + // + static const T m = std::numeric_limits<T>::denorm_min(); +#ifdef BOOST_MATH_CHECK_SSE2 + return (_mm_getcsr() & (_MM_FLUSH_ZERO_ON | 0x40)) ? tools::min_value<T>() : m;; +#else + return ((tools::min_value<T>() / 2) == 0) ? tools::min_value<T>() : m; +#endif +} + +template <class T> +inline T get_smallest_value(mpl::false_ const&) +{ + return tools::min_value<T>(); +} + +template <class T> +inline T get_smallest_value() +{ +#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1310) + return get_smallest_value<T>(mpl::bool_<std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::has_denorm == 1)>()); +#else + return get_smallest_value<T>(mpl::bool_<std::numeric_limits<T>::is_specialized && (std::numeric_limits<T>::has_denorm == std::denorm_present)>()); +#endif +} + +// +// Returns the smallest value that won't generate denorms when +// we calculate the value of the least-significant-bit: +// +template <class T> +T get_min_shift_value(); + +template <class T> +struct min_shift_initializer +{ + struct init + { + init() + { + do_init(); + } + static void do_init() + { + get_min_shift_value<T>(); + } + void force_instantiate()const{} + }; + static const init initializer; + static void force_instantiate() + { + initializer.force_instantiate(); + } +}; + +template <class T> +const typename min_shift_initializer<T>::init min_shift_initializer<T>::initializer; + +template <class T> +inline T calc_min_shifted(const mpl::true_&) +{ + BOOST_MATH_STD_USING + return ldexp(tools::min_value<T>(), tools::digits<T>() + 1); +} +template <class T> +inline T calc_min_shifted(const mpl::false_&) +{ + BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); + + return scalbn(tools::min_value<T>(), std::numeric_limits<T>::digits + 1); +} + + +template <class T> +inline T get_min_shift_value() +{ + static const T val = calc_min_shifted<T>(mpl::bool_<!std::numeric_limits<T>::is_specialized || std::numeric_limits<T>::radix == 2>()); + min_shift_initializer<T>::force_instantiate(); + + return val; +} + +template <class T, class Policy> +T float_next_imp(const T& val, const mpl::true_&, const Policy& pol) +{ + BOOST_MATH_STD_USING + int expon; + static const char* function = "float_next<%1%>(%1%)"; + + int fpclass = (boost::math::fpclassify)(val); + + if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE)) + { + if(val < 0) + return -tools::max_value<T>(); + return policies::raise_domain_error<T>( + function, + "Argument must be finite, but got %1%", val, pol); + } + + if(val >= tools::max_value<T>()) + return policies::raise_overflow_error<T>(function, 0, pol); + + if(val == 0) + return detail::get_smallest_value<T>(); + + if((fpclass != (int)FP_SUBNORMAL) && (fpclass != (int)FP_ZERO) && (fabs(val) < detail::get_min_shift_value<T>()) && (val != -tools::min_value<T>())) + { + // + // Special case: if the value of the least significant bit is a denorm, and the result + // would not be a denorm, then shift the input, increment, and shift back. + // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set. + // + return ldexp(float_next(T(ldexp(val, 2 * tools::digits<T>())), pol), -2 * tools::digits<T>()); + } + + if(-0.5f == frexp(val, &expon)) + --expon; // reduce exponent when val is a power of two, and negative. + T diff = ldexp(T(1), expon - tools::digits<T>()); + if(diff == 0) + diff = detail::get_smallest_value<T>(); + return val + diff; +} // float_next_imp +// +// Special version for some base other than 2: +// +template <class T, class Policy> +T float_next_imp(const T& val, const mpl::false_&, const Policy& pol) +{ + BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); + + BOOST_MATH_STD_USING + boost::intmax_t expon; + static const char* function = "float_next<%1%>(%1%)"; + + int fpclass = (boost::math::fpclassify)(val); + + if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE)) + { + if(val < 0) + return -tools::max_value<T>(); + return policies::raise_domain_error<T>( + function, + "Argument must be finite, but got %1%", val, pol); + } + + if(val >= tools::max_value<T>()) + return policies::raise_overflow_error<T>(function, 0, pol); + + if(val == 0) + return detail::get_smallest_value<T>(); + + if((fpclass != (int)FP_SUBNORMAL) && (fpclass != (int)FP_ZERO) && (fabs(val) < detail::get_min_shift_value<T>()) && (val != -tools::min_value<T>())) + { + // + // Special case: if the value of the least significant bit is a denorm, and the result + // would not be a denorm, then shift the input, increment, and shift back. + // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set. + // + return scalbn(float_next(T(scalbn(val, 2 * std::numeric_limits<T>::digits)), pol), -2 * std::numeric_limits<T>::digits); + } + + expon = 1 + ilogb(val); + if(-1 == scalbn(val, -expon) * std::numeric_limits<T>::radix) + --expon; // reduce exponent when val is a power of base, and negative. + T diff = scalbn(T(1), expon - std::numeric_limits<T>::digits); + if(diff == 0) + diff = detail::get_smallest_value<T>(); + return val + diff; +} // float_next_imp + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type float_next(const T& val, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + return detail::float_next_imp(detail::normalize_value(static_cast<result_type>(val), typename detail::has_hidden_guard_digits<result_type>::type()), mpl::bool_<!std::numeric_limits<result_type>::is_specialized || (std::numeric_limits<result_type>::radix == 2)>(), pol); +} + +#if 0 //def BOOST_MSVC +// +// We used to use ::_nextafter here, but doing so fails when using +// the SSE2 registers if the FTZ or DAZ flags are set, so use our own +// - albeit slower - code instead as at least that gives the correct answer. +// +template <class Policy> +inline double float_next(const double& val, const Policy& pol) +{ + static const char* function = "float_next<%1%>(%1%)"; + + if(!(boost::math::isfinite)(val) && (val > 0)) + return policies::raise_domain_error<double>( + function, + "Argument must be finite, but got %1%", val, pol); + + if(val >= tools::max_value<double>()) + return policies::raise_overflow_error<double>(function, 0, pol); + + return ::_nextafter(val, tools::max_value<double>()); +} +#endif + +template <class T> +inline typename tools::promote_args<T>::type float_next(const T& val) +{ + return float_next(val, policies::policy<>()); +} + +namespace detail{ + +template <class T, class Policy> +T float_prior_imp(const T& val, const mpl::true_&, const Policy& pol) +{ + BOOST_MATH_STD_USING + int expon; + static const char* function = "float_prior<%1%>(%1%)"; + + int fpclass = (boost::math::fpclassify)(val); + + if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE)) + { + if(val > 0) + return tools::max_value<T>(); + return policies::raise_domain_error<T>( + function, + "Argument must be finite, but got %1%", val, pol); + } + + if(val <= -tools::max_value<T>()) + return -policies::raise_overflow_error<T>(function, 0, pol); + + if(val == 0) + return -detail::get_smallest_value<T>(); + + if((fpclass != (int)FP_SUBNORMAL) && (fpclass != (int)FP_ZERO) && (fabs(val) < detail::get_min_shift_value<T>()) && (val != tools::min_value<T>())) + { + // + // Special case: if the value of the least significant bit is a denorm, and the result + // would not be a denorm, then shift the input, increment, and shift back. + // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set. + // + return ldexp(float_prior(T(ldexp(val, 2 * tools::digits<T>())), pol), -2 * tools::digits<T>()); + } + + T remain = frexp(val, &expon); + if(remain == 0.5f) + --expon; // when val is a power of two we must reduce the exponent + T diff = ldexp(T(1), expon - tools::digits<T>()); + if(diff == 0) + diff = detail::get_smallest_value<T>(); + return val - diff; +} // float_prior_imp +// +// Special version for bases other than 2: +// +template <class T, class Policy> +T float_prior_imp(const T& val, const mpl::false_&, const Policy& pol) +{ + BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); + + BOOST_MATH_STD_USING + boost::intmax_t expon; + static const char* function = "float_prior<%1%>(%1%)"; + + int fpclass = (boost::math::fpclassify)(val); + + if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE)) + { + if(val > 0) + return tools::max_value<T>(); + return policies::raise_domain_error<T>( + function, + "Argument must be finite, but got %1%", val, pol); + } + + if(val <= -tools::max_value<T>()) + return -policies::raise_overflow_error<T>(function, 0, pol); + + if(val == 0) + return -detail::get_smallest_value<T>(); + + if((fpclass != (int)FP_SUBNORMAL) && (fpclass != (int)FP_ZERO) && (fabs(val) < detail::get_min_shift_value<T>()) && (val != tools::min_value<T>())) + { + // + // Special case: if the value of the least significant bit is a denorm, and the result + // would not be a denorm, then shift the input, increment, and shift back. + // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set. + // + return scalbn(float_prior(T(scalbn(val, 2 * std::numeric_limits<T>::digits)), pol), -2 * std::numeric_limits<T>::digits); + } + + expon = 1 + ilogb(val); + T remain = scalbn(val, -expon); + if(remain * std::numeric_limits<T>::radix == 1) + --expon; // when val is a power of two we must reduce the exponent + T diff = scalbn(T(1), expon - std::numeric_limits<T>::digits); + if(diff == 0) + diff = detail::get_smallest_value<T>(); + return val - diff; +} // float_prior_imp + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type float_prior(const T& val, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + return detail::float_prior_imp(detail::normalize_value(static_cast<result_type>(val), typename detail::has_hidden_guard_digits<result_type>::type()), mpl::bool_<!std::numeric_limits<result_type>::is_specialized || (std::numeric_limits<result_type>::radix == 2)>(), pol); +} + +#if 0 //def BOOST_MSVC +// +// We used to use ::_nextafter here, but doing so fails when using +// the SSE2 registers if the FTZ or DAZ flags are set, so use our own +// - albeit slower - code instead as at least that gives the correct answer. +// +template <class Policy> +inline double float_prior(const double& val, const Policy& pol) +{ + static const char* function = "float_prior<%1%>(%1%)"; + + if(!(boost::math::isfinite)(val) && (val < 0)) + return policies::raise_domain_error<double>( + function, + "Argument must be finite, but got %1%", val, pol); + + if(val <= -tools::max_value<double>()) + return -policies::raise_overflow_error<double>(function, 0, pol); + + return ::_nextafter(val, -tools::max_value<double>()); +} +#endif + +template <class T> +inline typename tools::promote_args<T>::type float_prior(const T& val) +{ + return float_prior(val, policies::policy<>()); +} + +template <class T, class U, class Policy> +inline typename tools::promote_args<T, U>::type nextafter(const T& val, const U& direction, const Policy& pol) +{ + typedef typename tools::promote_args<T, U>::type result_type; + return val < direction ? boost::math::float_next<result_type>(val, pol) : val == direction ? val : boost::math::float_prior<result_type>(val, pol); +} + +template <class T, class U> +inline typename tools::promote_args<T, U>::type nextafter(const T& val, const U& direction) +{ + return nextafter(val, direction, policies::policy<>()); +} + +namespace detail{ + +template <class T, class Policy> +T float_distance_imp(const T& a, const T& b, const mpl::true_&, const Policy& pol) +{ + BOOST_MATH_STD_USING + // + // Error handling: + // + static const char* function = "float_distance<%1%>(%1%, %1%)"; + if(!(boost::math::isfinite)(a)) + return policies::raise_domain_error<T>( + function, + "Argument a must be finite, but got %1%", a, pol); + if(!(boost::math::isfinite)(b)) + return policies::raise_domain_error<T>( + function, + "Argument b must be finite, but got %1%", b, pol); + // + // Special cases: + // + if(a > b) + return -float_distance(b, a, pol); + if(a == b) + return T(0); + if(a == 0) + return 1 + fabs(float_distance(static_cast<T>((b < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), b, pol)); + if(b == 0) + return 1 + fabs(float_distance(static_cast<T>((a < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), a, pol)); + if(boost::math::sign(a) != boost::math::sign(b)) + return 2 + fabs(float_distance(static_cast<T>((b < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), b, pol)) + + fabs(float_distance(static_cast<T>((a < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), a, pol)); + // + // By the time we get here, both a and b must have the same sign, we want + // b > a and both postive for the following logic: + // + if(a < 0) + return float_distance(static_cast<T>(-b), static_cast<T>(-a), pol); + + BOOST_ASSERT(a >= 0); + BOOST_ASSERT(b >= a); + + int expon; + // + // Note that if a is a denorm then the usual formula fails + // because we actually have fewer than tools::digits<T>() + // significant bits in the representation: + // + frexp(((boost::math::fpclassify)(a) == (int)FP_SUBNORMAL) ? tools::min_value<T>() : a, &expon); + T upper = ldexp(T(1), expon); + T result = T(0); + // + // If b is greater than upper, then we *must* split the calculation + // as the size of the ULP changes with each order of magnitude change: + // + if(b > upper) + { + int expon2; + frexp(b, &expon2); + T upper2 = ldexp(T(0.5), expon2); + result = float_distance(upper2, b); + result += (expon2 - expon - 1) * ldexp(T(1), tools::digits<T>() - 1); + } + // + // Use compensated double-double addition to avoid rounding + // errors in the subtraction: + // + expon = tools::digits<T>() - expon; + T mb, x, y, z; + if(((boost::math::fpclassify)(a) == (int)FP_SUBNORMAL) || (b - a < tools::min_value<T>())) + { + // + // Special case - either one end of the range is a denormal, or else the difference is. + // The regular code will fail if we're using the SSE2 registers on Intel and either + // the FTZ or DAZ flags are set. + // + T a2 = ldexp(a, tools::digits<T>()); + T b2 = ldexp(b, tools::digits<T>()); + mb = -(std::min)(T(ldexp(upper, tools::digits<T>())), b2); + x = a2 + mb; + z = x - a2; + y = (a2 - (x - z)) + (mb - z); + + expon -= tools::digits<T>(); + } + else + { + mb = -(std::min)(upper, b); + x = a + mb; + z = x - a; + y = (a - (x - z)) + (mb - z); + } + if(x < 0) + { + x = -x; + y = -y; + } + result += ldexp(x, expon) + ldexp(y, expon); + // + // Result must be an integer: + // + BOOST_ASSERT(result == floor(result)); + return result; +} // float_distance_imp +// +// Special versions for bases other than 2: +// +template <class T, class Policy> +T float_distance_imp(const T& a, const T& b, const mpl::false_&, const Policy& pol) +{ + BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); + + BOOST_MATH_STD_USING + // + // Error handling: + // + static const char* function = "float_distance<%1%>(%1%, %1%)"; + if(!(boost::math::isfinite)(a)) + return policies::raise_domain_error<T>( + function, + "Argument a must be finite, but got %1%", a, pol); + if(!(boost::math::isfinite)(b)) + return policies::raise_domain_error<T>( + function, + "Argument b must be finite, but got %1%", b, pol); + // + // Special cases: + // + if(a > b) + return -float_distance(b, a, pol); + if(a == b) + return T(0); + if(a == 0) + return 1 + fabs(float_distance(static_cast<T>((b < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), b, pol)); + if(b == 0) + return 1 + fabs(float_distance(static_cast<T>((a < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), a, pol)); + if(boost::math::sign(a) != boost::math::sign(b)) + return 2 + fabs(float_distance(static_cast<T>((b < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), b, pol)) + + fabs(float_distance(static_cast<T>((a < 0) ? T(-detail::get_smallest_value<T>()) : detail::get_smallest_value<T>()), a, pol)); + // + // By the time we get here, both a and b must have the same sign, we want + // b > a and both postive for the following logic: + // + if(a < 0) + return float_distance(static_cast<T>(-b), static_cast<T>(-a), pol); + + BOOST_ASSERT(a >= 0); + BOOST_ASSERT(b >= a); + + boost::intmax_t expon; + // + // Note that if a is a denorm then the usual formula fails + // because we actually have fewer than tools::digits<T>() + // significant bits in the representation: + // + expon = 1 + ilogb(((boost::math::fpclassify)(a) == (int)FP_SUBNORMAL) ? tools::min_value<T>() : a); + T upper = scalbn(T(1), expon); + T result = T(0); + // + // If b is greater than upper, then we *must* split the calculation + // as the size of the ULP changes with each order of magnitude change: + // + if(b > upper) + { + boost::intmax_t expon2 = 1 + ilogb(b); + T upper2 = scalbn(T(1), expon2 - 1); + result = float_distance(upper2, b); + result += (expon2 - expon - 1) * scalbn(T(1), std::numeric_limits<T>::digits - 1); + } + // + // Use compensated double-double addition to avoid rounding + // errors in the subtraction: + // + expon = std::numeric_limits<T>::digits - expon; + T mb, x, y, z; + if(((boost::math::fpclassify)(a) == (int)FP_SUBNORMAL) || (b - a < tools::min_value<T>())) + { + // + // Special case - either one end of the range is a denormal, or else the difference is. + // The regular code will fail if we're using the SSE2 registers on Intel and either + // the FTZ or DAZ flags are set. + // + T a2 = scalbn(a, std::numeric_limits<T>::digits); + T b2 = scalbn(b, std::numeric_limits<T>::digits); + mb = -(std::min)(T(scalbn(upper, std::numeric_limits<T>::digits)), b2); + x = a2 + mb; + z = x - a2; + y = (a2 - (x - z)) + (mb - z); + + expon -= std::numeric_limits<T>::digits; + } + else + { + mb = -(std::min)(upper, b); + x = a + mb; + z = x - a; + y = (a - (x - z)) + (mb - z); + } + if(x < 0) + { + x = -x; + y = -y; + } + result += scalbn(x, expon) + scalbn(y, expon); + // + // Result must be an integer: + // + BOOST_ASSERT(result == floor(result)); + return result; +} // float_distance_imp + +} // namespace detail + +template <class T, class U, class Policy> +inline typename tools::promote_args<T, U>::type float_distance(const T& a, const U& b, const Policy& pol) +{ + typedef typename tools::promote_args<T, U>::type result_type; + return detail::float_distance_imp(detail::normalize_value(static_cast<result_type>(a), typename detail::has_hidden_guard_digits<result_type>::type()), detail::normalize_value(static_cast<result_type>(b), typename detail::has_hidden_guard_digits<result_type>::type()), mpl::bool_<!std::numeric_limits<result_type>::is_specialized || (std::numeric_limits<result_type>::radix == 2)>(), pol); +} + +template <class T, class U> +typename tools::promote_args<T, U>::type float_distance(const T& a, const U& b) +{ + return boost::math::float_distance(a, b, policies::policy<>()); +} + +namespace detail{ + +template <class T, class Policy> +T float_advance_imp(T val, int distance, const mpl::true_&, const Policy& pol) +{ + BOOST_MATH_STD_USING + // + // Error handling: + // + static const char* function = "float_advance<%1%>(%1%, int)"; + + int fpclass = (boost::math::fpclassify)(val); + + if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE)) + return policies::raise_domain_error<T>( + function, + "Argument val must be finite, but got %1%", val, pol); + + if(val < 0) + return -float_advance(-val, -distance, pol); + if(distance == 0) + return val; + if(distance == 1) + return float_next(val, pol); + if(distance == -1) + return float_prior(val, pol); + + if(fabs(val) < detail::get_min_shift_value<T>()) + { + // + // Special case: if the value of the least significant bit is a denorm, + // implement in terms of float_next/float_prior. + // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set. + // + if(distance > 0) + { + do{ val = float_next(val, pol); } while(--distance); + } + else + { + do{ val = float_prior(val, pol); } while(++distance); + } + return val; + } + + int expon; + frexp(val, &expon); + T limit = ldexp((distance < 0 ? T(0.5f) : T(1)), expon); + if(val <= tools::min_value<T>()) + { + limit = sign(T(distance)) * tools::min_value<T>(); + } + T limit_distance = float_distance(val, limit); + while(fabs(limit_distance) < abs(distance)) + { + distance -= itrunc(limit_distance); + val = limit; + if(distance < 0) + { + limit /= 2; + expon--; + } + else + { + limit *= 2; + expon++; + } + limit_distance = float_distance(val, limit); + if(distance && (limit_distance == 0)) + { + return policies::raise_evaluation_error<T>(function, "Internal logic failed while trying to increment floating point value %1%: most likely your FPU is in non-IEEE conforming mode.", val, pol); + } + } + if((0.5f == frexp(val, &expon)) && (distance < 0)) + --expon; + T diff = 0; + if(val != 0) + diff = distance * ldexp(T(1), expon - tools::digits<T>()); + if(diff == 0) + diff = distance * detail::get_smallest_value<T>(); + return val += diff; +} // float_advance_imp +// +// Special version for bases other than 2: +// +template <class T, class Policy> +T float_advance_imp(T val, int distance, const mpl::false_&, const Policy& pol) +{ + BOOST_STATIC_ASSERT(std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT(std::numeric_limits<T>::radix != 2); + + BOOST_MATH_STD_USING + // + // Error handling: + // + static const char* function = "float_advance<%1%>(%1%, int)"; + + int fpclass = (boost::math::fpclassify)(val); + + if((fpclass == (int)FP_NAN) || (fpclass == (int)FP_INFINITE)) + return policies::raise_domain_error<T>( + function, + "Argument val must be finite, but got %1%", val, pol); + + if(val < 0) + return -float_advance(-val, -distance, pol); + if(distance == 0) + return val; + if(distance == 1) + return float_next(val, pol); + if(distance == -1) + return float_prior(val, pol); + + if(fabs(val) < detail::get_min_shift_value<T>()) + { + // + // Special case: if the value of the least significant bit is a denorm, + // implement in terms of float_next/float_prior. + // This avoids issues with the Intel SSE2 registers when the FTZ or DAZ flags are set. + // + if(distance > 0) + { + do{ val = float_next(val, pol); } while(--distance); + } + else + { + do{ val = float_prior(val, pol); } while(++distance); + } + return val; + } + + boost::intmax_t expon = 1 + ilogb(val); + T limit = scalbn(T(1), distance < 0 ? expon - 1 : expon); + if(val <= tools::min_value<T>()) + { + limit = sign(T(distance)) * tools::min_value<T>(); + } + T limit_distance = float_distance(val, limit); + while(fabs(limit_distance) < abs(distance)) + { + distance -= itrunc(limit_distance); + val = limit; + if(distance < 0) + { + limit /= std::numeric_limits<T>::radix; + expon--; + } + else + { + limit *= std::numeric_limits<T>::radix; + expon++; + } + limit_distance = float_distance(val, limit); + if(distance && (limit_distance == 0)) + { + return policies::raise_evaluation_error<T>(function, "Internal logic failed while trying to increment floating point value %1%: most likely your FPU is in non-IEEE conforming mode.", val, pol); + } + } + /*expon = 1 + ilogb(val); + if((1 == scalbn(val, 1 + expon)) && (distance < 0)) + --expon;*/ + T diff = 0; + if(val != 0) + diff = distance * scalbn(T(1), expon - std::numeric_limits<T>::digits); + if(diff == 0) + diff = distance * detail::get_smallest_value<T>(); + return val += diff; +} // float_advance_imp + +} // namespace detail + +template <class T, class Policy> +inline typename tools::promote_args<T>::type float_advance(T val, int distance, const Policy& pol) +{ + typedef typename tools::promote_args<T>::type result_type; + return detail::float_advance_imp(detail::normalize_value(static_cast<result_type>(val), typename detail::has_hidden_guard_digits<result_type>::type()), distance, mpl::bool_<!std::numeric_limits<result_type>::is_specialized || (std::numeric_limits<result_type>::radix == 2)>(), pol); +} + +template <class T> +inline typename tools::promote_args<T>::type float_advance(const T& val, int distance) +{ + return boost::math::float_advance(val, distance, policies::policy<>()); +} + +}} // boost math namespaces + +#endif // BOOST_MATH_SPECIAL_NEXT_HPP + diff --git a/contrib/restricted/boost/math/include/boost/math/special_functions/sign.hpp b/contrib/restricted/boost/math/include/boost/math/special_functions/sign.hpp new file mode 100644 index 0000000000..5cb21bac54 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/special_functions/sign.hpp @@ -0,0 +1,194 @@ +// (C) Copyright John Maddock 2006. +// (C) Copyright Johan Rade 2006. +// (C) Copyright Paul A. Bristow 2011 (added changesign). + +// 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) + +#ifndef BOOST_MATH_TOOLS_SIGN_HPP +#define BOOST_MATH_TOOLS_SIGN_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/tools/config.hpp> +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/special_functions/detail/fp_traits.hpp> + +namespace boost{ namespace math{ + +namespace detail { + + // signbit + +#ifdef BOOST_MATH_USE_STD_FPCLASSIFY + template<class T> + inline int signbit_impl(T x, native_tag const&) + { + return (std::signbit)(x) ? 1 : 0; + } +#endif + + // Generic versions first, note that these do not handle + // signed zero or NaN. + + template<class T> + inline int signbit_impl(T x, generic_tag<true> const&) + { + return x < 0; + } + + template<class T> + inline int signbit_impl(T x, generic_tag<false> const&) + { + return x < 0; + } + +#if defined(__GNUC__) && (LDBL_MANT_DIG == 106) + // + // Special handling for GCC's "double double" type, + // in this case the sign is the same as the sign we + // get by casting to double, no overflow/underflow + // can occur since the exponents are the same magnitude + // for the two types: + // + inline int signbit_impl(long double x, generic_tag<true> const&) + { + return (boost::math::signbit)(static_cast<double>(x)); + } + inline int signbit_impl(long double x, generic_tag<false> const&) + { + return (boost::math::signbit)(static_cast<double>(x)); + } +#endif + + template<class T> + inline int signbit_impl(T x, ieee_copy_all_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + return a & traits::sign ? 1 : 0; + } + + template<class T> + inline int signbit_impl(T x, ieee_copy_leading_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + + return a & traits::sign ? 1 : 0; + } + + // Changesign + + // Generic versions first, note that these do not handle + // signed zero or NaN. + + template<class T> + inline T (changesign_impl)(T x, generic_tag<true> const&) + { + return -x; + } + + template<class T> + inline T (changesign_impl)(T x, generic_tag<false> const&) + { + return -x; + } +#if defined(__GNUC__) && (LDBL_MANT_DIG == 106) + // + // Special handling for GCC's "double double" type, + // in this case we need to change the sign of both + // components of the "double double": + // + inline long double (changesign_impl)(long double x, generic_tag<true> const&) + { + double* pd = reinterpret_cast<double*>(&x); + pd[0] = boost::math::changesign(pd[0]); + pd[1] = boost::math::changesign(pd[1]); + return x; + } + inline long double (changesign_impl)(long double x, generic_tag<false> const&) + { + double* pd = reinterpret_cast<double*>(&x); + pd[0] = boost::math::changesign(pd[0]); + pd[1] = boost::math::changesign(pd[1]); + return x; + } +#endif + + template<class T> + inline T changesign_impl(T x, ieee_copy_all_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::sign_change_type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a ^= traits::sign; + traits::set_bits(x,a); + return x; + } + + template<class T> + inline T (changesign_impl)(T x, ieee_copy_leading_bits_tag const&) + { + typedef BOOST_DEDUCED_TYPENAME fp_traits<T>::sign_change_type traits; + + BOOST_DEDUCED_TYPENAME traits::bits a; + traits::get_bits(x,a); + a ^= traits::sign; + traits::set_bits(x,a); + return x; + } + + +} // namespace detail + +template<class T> int (signbit)(T x) +{ + typedef typename detail::fp_traits<T>::type traits; + typedef typename traits::method method; + // typedef typename boost::is_floating_point<T>::type fp_tag; + typedef typename tools::promote_args_permissive<T>::type result_type; + return detail::signbit_impl(static_cast<result_type>(x), method()); +} + +template <class T> +inline int sign BOOST_NO_MACRO_EXPAND(const T& z) +{ + return (z == 0) ? 0 : (boost::math::signbit)(z) ? -1 : 1; +} + +template <class T> typename tools::promote_args_permissive<T>::type (changesign)(const T& x) +{ //!< \brief return unchanged binary pattern of x, except for change of sign bit. + typedef typename detail::fp_traits<T>::sign_change_type traits; + typedef typename traits::method method; + // typedef typename boost::is_floating_point<T>::type fp_tag; + typedef typename tools::promote_args_permissive<T>::type result_type; + + return detail::changesign_impl(static_cast<result_type>(x), method()); +} + +template <class T, class U> +inline typename tools::promote_args_permissive<T, U>::type + copysign BOOST_NO_MACRO_EXPAND(const T& x, const U& y) +{ + BOOST_MATH_STD_USING + typedef typename tools::promote_args_permissive<T, U>::type result_type; + return (boost::math::signbit)(static_cast<result_type>(x)) != (boost::math::signbit)(static_cast<result_type>(y)) + ? (boost::math::changesign)(static_cast<result_type>(x)) : static_cast<result_type>(x); +} + +} // namespace math +} // namespace boost + + +#endif // BOOST_MATH_TOOLS_SIGN_HPP + + diff --git a/contrib/restricted/boost/math/include/boost/math/special_functions/trunc.hpp b/contrib/restricted/boost/math/include/boost/math/special_functions/trunc.hpp new file mode 100644 index 0000000000..3f80c96fee --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/special_functions/trunc.hpp @@ -0,0 +1,111 @@ +// Copyright John Maddock 2007. +// 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) + +#ifndef BOOST_MATH_TRUNC_HPP +#define BOOST_MATH_TRUNC_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/math/special_functions/math_fwd.hpp> +#include <boost/math/tools/config.hpp> +#include <boost/math/policies/error_handling.hpp> +#include <boost/math/special_functions/fpclassify.hpp> + +namespace boost{ namespace math{ namespace detail{ + +template <class T, class Policy> +inline typename tools::promote_args<T>::type trunc(const T& v, const Policy& pol, const mpl::false_&) +{ + BOOST_MATH_STD_USING + typedef typename tools::promote_args<T>::type result_type; + if(!(boost::math::isfinite)(v)) + return policies::raise_rounding_error("boost::math::trunc<%1%>(%1%)", 0, static_cast<result_type>(v), static_cast<result_type>(v), pol); + return (v >= 0) ? static_cast<result_type>(floor(v)) : static_cast<result_type>(ceil(v)); +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type trunc(const T& v, const Policy&, const mpl::true_&) +{ + return v; +} + +} + +template <class T, class Policy> +inline typename tools::promote_args<T>::type trunc(const T& v, const Policy& pol) +{ + return detail::trunc(v, pol, mpl::bool_<detail::is_integer_for_rounding<T>::value>()); +} +template <class T> +inline typename tools::promote_args<T>::type trunc(const T& v) +{ + return trunc(v, policies::policy<>()); +} +// +// The following functions will not compile unless T has an +// implicit convertion to the integer types. For user-defined +// number types this will likely not be the case. In that case +// these functions should either be specialized for the UDT in +// question, or else overloads should be placed in the same +// namespace as the UDT: these will then be found via argument +// dependent lookup. See our concept archetypes for examples. +// +template <class T, class Policy> +inline int itrunc(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + typedef typename tools::promote_args<T>::type result_type; + result_type r = boost::math::trunc(v, pol); + if((r > (std::numeric_limits<int>::max)()) || (r < (std::numeric_limits<int>::min)())) + return static_cast<int>(policies::raise_rounding_error("boost::math::itrunc<%1%>(%1%)", 0, static_cast<result_type>(v), 0, pol)); + return static_cast<int>(r); +} +template <class T> +inline int itrunc(const T& v) +{ + return itrunc(v, policies::policy<>()); +} + +template <class T, class Policy> +inline long ltrunc(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + typedef typename tools::promote_args<T>::type result_type; + result_type r = boost::math::trunc(v, pol); + if((r > (std::numeric_limits<long>::max)()) || (r < (std::numeric_limits<long>::min)())) + return static_cast<long>(policies::raise_rounding_error("boost::math::ltrunc<%1%>(%1%)", 0, static_cast<result_type>(v), 0L, pol)); + return static_cast<long>(r); +} +template <class T> +inline long ltrunc(const T& v) +{ + return ltrunc(v, policies::policy<>()); +} + +#ifdef BOOST_HAS_LONG_LONG + +template <class T, class Policy> +inline boost::long_long_type lltrunc(const T& v, const Policy& pol) +{ + BOOST_MATH_STD_USING + typedef typename tools::promote_args<T>::type result_type; + result_type r = boost::math::trunc(v, pol); + if((r > (std::numeric_limits<boost::long_long_type>::max)()) || (r < (std::numeric_limits<boost::long_long_type>::min)())) + return static_cast<boost::long_long_type>(policies::raise_rounding_error("boost::math::lltrunc<%1%>(%1%)", 0, v, static_cast<boost::long_long_type>(0), pol)); + return static_cast<boost::long_long_type>(r); +} +template <class T> +inline boost::long_long_type lltrunc(const T& v) +{ + return lltrunc(v, policies::policy<>()); +} + +#endif + +}} // namespaces + +#endif // BOOST_MATH_TRUNC_HPP diff --git a/contrib/restricted/boost/math/include/boost/math/tools/config.hpp b/contrib/restricted/boost/math/include/boost/math/tools/config.hpp new file mode 100644 index 0000000000..016211cfa8 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/tools/config.hpp @@ -0,0 +1,469 @@ +// Copyright (c) 2006-7 John Maddock +// 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) + +#ifndef BOOST_MATH_TOOLS_CONFIG_HPP +#define BOOST_MATH_TOOLS_CONFIG_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/config.hpp> +#include <boost/predef.h> +#include <boost/cstdint.hpp> // for boost::uintmax_t +#include <boost/detail/workaround.hpp> +#include <boost/type_traits/is_integral.hpp> +#include <algorithm> // for min and max +#include <boost/config/no_tr1/cmath.hpp> +#include <climits> +#include <cfloat> +#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) +# include <math.h> +#endif +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS +# include <limits> +#endif + +#include <boost/math/tools/user.hpp> + +#if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \ + || (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \ + && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#endif +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) +// +// Borland post 5.8.2 uses Dinkumware's std C lib which +// doesn't have true long double precision. Earlier +// versions are problematic too: +// +# define BOOST_MATH_NO_REAL_CONCEPT_TESTS +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +# define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM) +# include <float.h> +#endif +#ifdef __IBMCPP__ +// +// For reasons I don't unserstand, the tests with IMB's compiler all +// pass at long double precision, but fail with real_concept, those tests +// are disabled for now. (JM 2012). +# define BOOST_MATH_NO_REAL_CONCEPT_TESTS +#endif +#ifdef sun +// Any use of __float128 in program startup code causes a segfault (tested JM 2015, Solaris 11). +# define BOOST_MATH_DISABLE_FLOAT128 +#endif +#ifdef __HAIKU__ +// +// Not sure what's up with the math detection on Haiku, but linking fails with +// float128 code enabled, and we don't have an implementation of __expl, so +// disabling long double functions for now as well. +# define BOOST_MATH_DISABLE_FLOAT128 +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#endif +#if (defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) +// +// Darwin's rather strange "double double" is rather hard to +// support, it should be possible given enough effort though... +// +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#endif +#if defined(unix) && defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1000) && !defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) +// +// Intel compiler prior to version 10 has sporadic problems +// calling the long double overloads of the std lib math functions: +// calling ::powl is OK, but std::pow(long double, long double) +// may segfault depending upon the value of the arguments passed +// and the specific Linux distribution. +// +// We'll be conservative and disable long double support for this compiler. +// +// Comment out this #define and try building the tests to determine whether +// your Intel compiler version has this issue or not. +// +# define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#endif +#if defined(unix) && defined(__INTEL_COMPILER) +// +// Intel compiler has sporadic issues compiling std::fpclassify depending on +// the exact OS version used. Use our own code for this as we know it works +// well on Intel processors: +// +#define BOOST_MATH_DISABLE_STD_FPCLASSIFY +#endif + +#if defined(BOOST_MSVC) && !defined(_WIN32_WCE) + // Better safe than sorry, our tests don't support hardware exceptions: +# define BOOST_MATH_CONTROL_FP _control87(MCW_EM,MCW_EM) +#endif + +#ifdef __IBMCPP__ +# define BOOST_MATH_NO_DEDUCED_FUNCTION_POINTERS +#endif + +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) +# define BOOST_MATH_USE_C99 +#endif + +#if (defined(__hpux) && !defined(__hppa)) +# define BOOST_MATH_USE_C99 +#endif + +#if defined(__GNUC__) && defined(_GLIBCXX_USE_C99) +# define BOOST_MATH_USE_C99 +#endif + +#if defined(_LIBCPP_VERSION) && !defined(_MSC_VER) +# define BOOST_MATH_USE_C99 +#endif + +#if defined(__CYGWIN__) || defined(__HP_aCC) || defined(BOOST_INTEL) \ + || defined(BOOST_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY) \ + || (defined(__GNUC__) && !defined(BOOST_MATH_USE_C99))\ + || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS) +# define BOOST_MATH_NO_NATIVE_LONG_DOUBLE_FP_CLASSIFY +#endif + +#if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) + +# include "boost/type.hpp" +# include "boost/non_type.hpp" + +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) boost::type<t>* = 0 +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) boost::type<t>* +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) boost::non_type<t, v>* = 0 +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) boost::non_type<t, v>* + +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) \ + , BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + +#else + +// no workaround needed: expand to nothing + +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_MATH_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE_SPEC(t) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE(t, v) +# define BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_NON_TYPE_SPEC(t, v) + + +#endif // __SUNPRO_CC + +#if (defined(__SUNPRO_CC) || defined(__hppa) || defined(__GNUC__)) && !defined(BOOST_MATH_SMALL_CONSTANT) +// Sun's compiler emits a hard error if a constant underflows, +// as does aCC on PA-RISC, while gcc issues a large number of warnings: +# define BOOST_MATH_SMALL_CONSTANT(x) 0.0 +#else +# define BOOST_MATH_SMALL_CONSTANT(x) x +#endif + + +#if BOOST_WORKAROUND(BOOST_MSVC, < 1400) +// +// Define if constants too large for a float cause "bad" +// values to be stored in the data, rather than infinity +// or a suitably large value. +// +# define BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS +#endif +// +// Tune performance options for specific compilers: +// +#ifdef BOOST_MSVC +# define BOOST_MATH_POLY_METHOD 2 +# define BOOST_MATH_RATIONAL_METHOD 1 +#elif defined(BOOST_INTEL) +# define BOOST_MATH_POLY_METHOD 2 +# define BOOST_MATH_RATIONAL_METHOD 1 +#elif defined(__GNUC__) +#if __GNUC__ < 4 +# define BOOST_MATH_POLY_METHOD 3 +# define BOOST_MATH_RATIONAL_METHOD 3 +# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT +# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L +#else +# define BOOST_MATH_POLY_METHOD 3 +# define BOOST_MATH_RATIONAL_METHOD 1 +#endif +#endif + +#if defined(BOOST_NO_LONG_LONG) && !defined(BOOST_MATH_INT_TABLE_TYPE) +# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) RT +# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##.0L +#endif + +// +// constexpr support, early GCC implementations can't cope so disable +// constexpr for them: +// +#if !defined(__clang) && defined(__GNUC__) +#if (__GNUC__ * 100 + __GNUC_MINOR__) < 490 +# define BOOST_MATH_DISABLE_CONSTEXPR +#endif +#endif + +#ifdef BOOST_MATH_DISABLE_CONSTEXPR +# define BOOST_MATH_CONSTEXPR +#else +# define BOOST_MATH_CONSTEXPR BOOST_CONSTEXPR +#endif + +// +// noexcept support: +// +#ifndef BOOST_NO_CXX11_NOEXCEPT +#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS +#include <type_traits> +# define BOOST_MATH_NOEXCEPT(T) noexcept(std::is_floating_point<T>::value) +# define BOOST_MATH_IS_FLOAT(T) (std::is_floating_point<T>::value) +#else +#include <boost/type_traits/is_floating_point.hpp> +# define BOOST_MATH_NOEXCEPT(T) noexcept(boost::is_floating_point<T>::value) +# define BOOST_MATH_IS_FLOAT(T) (boost::is_floating_point<T>::value) +#endif +#else +# define BOOST_MATH_NOEXCEPT(T) +# define BOOST_MATH_IS_FLOAT(T) false +#endif + +// +// The maximum order of polynomial that will be evaluated +// via an unrolled specialisation: +// +#ifndef BOOST_MATH_MAX_POLY_ORDER +# define BOOST_MATH_MAX_POLY_ORDER 20 +#endif +// +// Set the method used to evaluate polynomials and rationals: +// +#ifndef BOOST_MATH_POLY_METHOD +# define BOOST_MATH_POLY_METHOD 2 +#endif +#ifndef BOOST_MATH_RATIONAL_METHOD +# define BOOST_MATH_RATIONAL_METHOD 1 +#endif +// +// decide whether to store constants as integers or reals: +// +#ifndef BOOST_MATH_INT_TABLE_TYPE +# define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT +#endif +#ifndef BOOST_MATH_INT_VALUE_SUFFIX +# define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF +#endif +// +// And then the actual configuration: +// +#if defined(_GLIBCXX_USE_FLOAT128) && defined(BOOST_GCC) && !defined(__STRICT_ANSI__) \ + && !defined(BOOST_MATH_DISABLE_FLOAT128) || defined(BOOST_MATH_USE_FLOAT128) +// +// Only enable this when the compiler really is GCC as clang and probably +// intel too don't support __float128 yet :-( +// +#ifndef BOOST_MATH_USE_FLOAT128 +# define BOOST_MATH_USE_FLOAT128 +#endif + +# if defined(BOOST_INTEL) && defined(BOOST_INTEL_CXX_VERSION) && (BOOST_INTEL_CXX_VERSION >= 1310) && defined(__GNUC__) +# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) +# define BOOST_MATH_FLOAT128_TYPE __float128 +# endif +# elif defined(__GNUC__) +# define BOOST_MATH_FLOAT128_TYPE __float128 +# endif + +# ifndef BOOST_MATH_FLOAT128_TYPE +# define BOOST_MATH_FLOAT128_TYPE _Quad +# endif +#endif +// +// Check for WinCE with no iostream support: +// +#if defined(_WIN32_WCE) && !defined(__SGI_STL_PORT) +# define BOOST_MATH_NO_LEXICAL_CAST +#endif + +// +// Helper macro for controlling the FP behaviour: +// +#ifndef BOOST_MATH_CONTROL_FP +# define BOOST_MATH_CONTROL_FP +#endif +// +// Helper macro for using statements: +// +#define BOOST_MATH_STD_USING_CORE \ + using std::abs;\ + using std::acos;\ + using std::cos;\ + using std::fmod;\ + using std::modf;\ + using std::tan;\ + using std::asin;\ + using std::cosh;\ + using std::frexp;\ + using std::pow;\ + using std::tanh;\ + using std::atan;\ + using std::exp;\ + using std::ldexp;\ + using std::sin;\ + using std::atan2;\ + using std::fabs;\ + using std::log;\ + using std::sinh;\ + using std::ceil;\ + using std::floor;\ + using std::log10;\ + using std::sqrt; + +#define BOOST_MATH_STD_USING BOOST_MATH_STD_USING_CORE + +namespace boost{ namespace math{ +namespace tools +{ + +template <class T> +inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c) BOOST_MATH_NOEXCEPT(T) +{ + return (std::max)((std::max)(a, b), c); +} + +template <class T> +inline T max BOOST_PREVENT_MACRO_SUBSTITUTION(T a, T b, T c, T d) BOOST_MATH_NOEXCEPT(T) +{ + return (std::max)((std::max)(a, b), (std::max)(c, d)); +} + +} // namespace tools + +template <class T> +void suppress_unused_variable_warning(const T&) BOOST_MATH_NOEXCEPT(T) +{ +} + +namespace detail{ + +template <class T> +struct is_integer_for_rounding +{ + static const bool value = boost::is_integral<T>::value +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + || (std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::is_integer) +#endif + ; +}; + +} + +}} // namespace boost namespace math + +#ifdef __GLIBC_PREREQ +# if __GLIBC_PREREQ(2,14) +# define BOOST_MATH_HAVE_FIXED_GLIBC +# endif +#endif + +#if ((defined(__linux__) && !defined(__UCLIBC__) && !defined(BOOST_MATH_HAVE_FIXED_GLIBC)) || defined(__QNX__) || defined(__IBMCPP__)) && !defined(BOOST_NO_FENV_H) +// +// This code was introduced in response to this glibc bug: http://sourceware.org/bugzilla/show_bug.cgi?id=2445 +// Basically powl and expl can return garbage when the result is small and certain exception flags are set +// on entrance to these functions. This appears to have been fixed in Glibc 2.14 (May 2011). +// Much more information in this message thread: https://groups.google.com/forum/#!topic/boost-list/ZT99wtIFlb4 +// + + #include <boost/detail/fenv.hpp> + +# ifdef FE_ALL_EXCEPT + +namespace boost{ namespace math{ + namespace detail + { + struct fpu_guard + { + fpu_guard() + { + fegetexceptflag(&m_flags, FE_ALL_EXCEPT); + feclearexcept(FE_ALL_EXCEPT); + } + ~fpu_guard() + { + fesetexceptflag(&m_flags, FE_ALL_EXCEPT); + } + private: + fexcept_t m_flags; + }; + + } // namespace detail + }} // namespaces + +# define BOOST_FPU_EXCEPTION_GUARD boost::math::detail::fpu_guard local_guard_object; +# define BOOST_MATH_INSTRUMENT_FPU do{ fexcept_t cpu_flags; fegetexceptflag(&cpu_flags, FE_ALL_EXCEPT); BOOST_MATH_INSTRUMENT_VARIABLE(cpu_flags); } while(0); + +# else + +# define BOOST_FPU_EXCEPTION_GUARD +# define BOOST_MATH_INSTRUMENT_FPU + +# endif + +#else // All other platforms. +# define BOOST_FPU_EXCEPTION_GUARD +# define BOOST_MATH_INSTRUMENT_FPU +#endif + +#ifdef BOOST_MATH_INSTRUMENT + +# include <iostream> +# include <iomanip> +# include <typeinfo> + +# define BOOST_MATH_INSTRUMENT_CODE(x) \ + std::cout << std::setprecision(35) << __FILE__ << ":" << __LINE__ << " " << x << std::endl; +# define BOOST_MATH_INSTRUMENT_VARIABLE(name) BOOST_MATH_INSTRUMENT_CODE(BOOST_STRINGIZE(name) << " = " << name) + +#else + +# define BOOST_MATH_INSTRUMENT_CODE(x) +# define BOOST_MATH_INSTRUMENT_VARIABLE(name) + +#endif + +// +// Thread local storage: +// +#if !defined(BOOST_NO_CXX11_THREAD_LOCAL) && !defined(BOOST_INTEL) +# define BOOST_MATH_THREAD_LOCAL thread_local +#else +# define BOOST_MATH_THREAD_LOCAL +#endif + +// +// Can we have constexpr tables? +// +#if (!defined(BOOST_NO_CXX11_HDR_ARRAY) && !defined(BOOST_NO_CXX14_CONSTEXPR)) || BOOST_WORKAROUND(BOOST_MSVC, >= 1910) +#define BOOST_MATH_HAVE_CONSTEXPR_TABLES +#define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION constexpr +#else +#define BOOST_MATH_CONSTEXPR_TABLE_FUNCTION +#endif + + +#endif // BOOST_MATH_TOOLS_CONFIG_HPP + + + + diff --git a/contrib/restricted/boost/math/include/boost/math/tools/precision.hpp b/contrib/restricted/boost/math/include/boost/math/tools/precision.hpp new file mode 100644 index 0000000000..6538083b99 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/tools/precision.hpp @@ -0,0 +1,409 @@ +// Copyright John Maddock 2005-2006. +// 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) + +#ifndef BOOST_MATH_TOOLS_PRECISION_INCLUDED +#define BOOST_MATH_TOOLS_PRECISION_INCLUDED + +#ifdef _MSC_VER +#pragma once +#endif + +#include <boost/limits.hpp> +#include <boost/assert.hpp> +#include <boost/static_assert.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/if.hpp> +#include <boost/math/policies/policy.hpp> + +// These two are for LDBL_MAN_DIG: +#include <limits.h> +#include <math.h> + +namespace boost{ namespace math +{ +namespace tools +{ +// If T is not specialized, the functions digits, max_value and min_value, +// all get synthesised automatically from std::numeric_limits. +// However, if numeric_limits is not specialised for type RealType, +// for example with NTL::RR type, then you will get a compiler error +// when code tries to use these functions, unless you explicitly specialise them. + +// For example if the precision of RealType varies at runtime, +// then numeric_limits support may not be appropriate, +// see boost/math/tools/ntl.hpp for examples like +// template <> NTL::RR max_value<NTL::RR> ... +// See Conceptual Requirements for Real Number Types. + +template <class T> +inline BOOST_MATH_CONSTEXPR int digits(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) BOOST_NOEXCEPT +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); + BOOST_ASSERT(::std::numeric_limits<T>::radix == 2 || ::std::numeric_limits<T>::radix == 10); +#endif + return std::numeric_limits<T>::radix == 2 + ? std::numeric_limits<T>::digits + : ((std::numeric_limits<T>::digits + 1) * 1000L) / 301L; +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T max_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + return (std::numeric_limits<T>::max)(); +} // Also used as a finite 'infinite' value for - and +infinity, for example: +// -max_value<double> = -1.79769e+308, max_value<double> = 1.79769e+308. + +template <class T> +inline BOOST_MATH_CONSTEXPR T min_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + BOOST_STATIC_ASSERT( ::std::numeric_limits<T>::is_specialized); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); +#endif + return (std::numeric_limits<T>::min)(); +} + +namespace detail{ +// +// Logarithmic limits come next, note that although +// we can compute these from the log of the max value +// that is not in general thread safe (if we cache the value) +// so it's better to specialise these: +// +// For type float first: +// +template <class T> +inline BOOST_MATH_CONSTEXPR T log_max_value(const mpl::int_<128>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + return 88.0f; +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T log_min_value(const mpl::int_<128>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + return -87.0f; +} +// +// Now double: +// +template <class T> +inline BOOST_MATH_CONSTEXPR T log_max_value(const mpl::int_<1024>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + return 709.0; +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T log_min_value(const mpl::int_<1024>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + return -708.0; +} +// +// 80 and 128-bit long doubles: +// +template <class T> +inline BOOST_MATH_CONSTEXPR T log_max_value(const mpl::int_<16384>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + return 11356.0L; +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T log_min_value(const mpl::int_<16384>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + return -11355.0L; +} + +template <class T> +inline T log_max_value(const mpl::int_<0>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + BOOST_MATH_STD_USING +#ifdef __SUNPRO_CC + static const T m = boost::math::tools::max_value<T>(); + static const T val = log(m); +#else + static const T val = log(boost::math::tools::max_value<T>()); +#endif + return val; +} + +template <class T> +inline T log_min_value(const mpl::int_<0>& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + BOOST_MATH_STD_USING +#ifdef __SUNPRO_CC + static const T m = boost::math::tools::min_value<T>(); + static const T val = log(m); +#else + static const T val = log(boost::math::tools::min_value<T>()); +#endif + return val; +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T epsilon(const mpl::true_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_MATH_NOEXCEPT(T) +{ + return std::numeric_limits<T>::epsilon(); +} + +#if defined(__GNUC__) && ((LDBL_MANT_DIG == 106) || (__LDBL_MANT_DIG__ == 106)) +template <> +inline BOOST_MATH_CONSTEXPR long double epsilon<long double>(const mpl::true_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(long double)) BOOST_MATH_NOEXCEPT(long double) +{ + // numeric_limits on Darwin (and elsewhere) tells lies here: + // the issue is that long double on a few platforms is + // really a "double double" which has a non-contiguous + // mantissa: 53 bits followed by an unspecified number of + // zero bits, followed by 53 more bits. Thus the apparent + // precision of the type varies depending where it's been. + // Set epsilon to the value that a 106 bit fixed mantissa + // type would have, as that will give us sensible behaviour everywhere. + // + // This static assert fails for some unknown reason, so + // disabled for now... + // BOOST_STATIC_ASSERT(std::numeric_limits<long double>::digits == 106); + return 2.4651903288156618919116517665087e-32L; +} +#endif + +template <class T> +inline T epsilon(const mpl::false_& BOOST_MATH_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) +{ + // Note: don't cache result as precision may vary at runtime: + BOOST_MATH_STD_USING // for ADL of std names + return ldexp(static_cast<T>(1), 1-policies::digits<T, policies::policy<> >()); +} + +template <class T> +struct log_limit_traits +{ + typedef typename mpl::if_c< + (std::numeric_limits<T>::radix == 2) && + (std::numeric_limits<T>::max_exponent == 128 + || std::numeric_limits<T>::max_exponent == 1024 + || std::numeric_limits<T>::max_exponent == 16384), + mpl::int_<(std::numeric_limits<T>::max_exponent > INT_MAX ? INT_MAX : static_cast<int>(std::numeric_limits<T>::max_exponent))>, + mpl::int_<0> + >::type tag_type; + BOOST_STATIC_CONSTANT(bool, value = tag_type::value ? true : false); + BOOST_STATIC_ASSERT(::std::numeric_limits<T>::is_specialized || (value == 0)); +}; + +template <class T, bool b> struct log_limit_noexcept_traits_imp : public log_limit_traits<T> {}; +template <class T> struct log_limit_noexcept_traits_imp<T, false> : public boost::integral_constant<bool, false> {}; + +template <class T> +struct log_limit_noexcept_traits : public log_limit_noexcept_traits_imp<T, BOOST_MATH_IS_FLOAT(T)> {}; + +} // namespace detail + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4309) +#endif + +template <class T> +inline BOOST_MATH_CONSTEXPR T log_max_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT_IF(detail::log_limit_noexcept_traits<T>::value) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + return detail::log_max_value<T>(typename detail::log_limit_traits<T>::tag_type()); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); + BOOST_MATH_STD_USING + static const T val = log((std::numeric_limits<T>::max)()); + return val; +#endif +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T log_min_value(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE(T)) BOOST_NOEXCEPT_IF(detail::log_limit_noexcept_traits<T>::value) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + return detail::log_min_value<T>(typename detail::log_limit_traits<T>::tag_type()); +#else + BOOST_ASSERT(::std::numeric_limits<T>::is_specialized); + BOOST_MATH_STD_USING + static const T val = log((std::numeric_limits<T>::min)()); + return val; +#endif +} + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +template <class T> +inline BOOST_MATH_CONSTEXPR T epsilon(BOOST_MATH_EXPLICIT_TEMPLATE_TYPE_SPEC(T)) BOOST_MATH_NOEXCEPT(T) +{ +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + return detail::epsilon<T>(mpl::bool_< ::std::numeric_limits<T>::is_specialized>()); +#else + return ::std::numeric_limits<T>::is_specialized ? + detail::epsilon<T>(mpl::true_()) : + detail::epsilon<T>(mpl::false_()); +#endif +} + +namespace detail{ + +template <class T> +inline BOOST_MATH_CONSTEXPR T root_epsilon_imp(const mpl::int_<24>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.00034526698300124390839884978618400831996329879769945L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T root_epsilon_imp(const T*, const mpl::int_<53>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.1490116119384765625e-7L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T root_epsilon_imp(const T*, const mpl::int_<64>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.32927225399135962333569506281281311031656150598474e-9L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T root_epsilon_imp(const T*, const mpl::int_<113>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.1387778780781445675529539585113525390625e-16L); +} + +template <class T, class Tag> +inline T root_epsilon_imp(const T*, const Tag&) +{ + BOOST_MATH_STD_USING + static const T r_eps = sqrt(tools::epsilon<T>()); + return r_eps; +} + +template <class T> +inline T root_epsilon_imp(const T*, const mpl::int_<0>&) +{ + BOOST_MATH_STD_USING + return sqrt(tools::epsilon<T>()); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T cbrt_epsilon_imp(const mpl::int_<24>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.0049215666011518482998719164346805794944150447839903L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T cbrt_epsilon_imp(const T*, const mpl::int_<53>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(6.05545445239333906078989272793696693569753008995e-6L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T cbrt_epsilon_imp(const T*, const mpl::int_<64>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(4.76837158203125e-7L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T cbrt_epsilon_imp(const T*, const mpl::int_<113>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(5.7749313854154005630396773604745549542403508090496e-12L); +} + +template <class T, class Tag> +inline T cbrt_epsilon_imp(const T*, const Tag&) +{ + BOOST_MATH_STD_USING; + static const T cbrt_eps = pow(tools::epsilon<T>(), T(1) / 3); + return cbrt_eps; +} + +template <class T> +inline T cbrt_epsilon_imp(const T*, const mpl::int_<0>&) +{ + BOOST_MATH_STD_USING; + return pow(tools::epsilon<T>(), T(1) / 3); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T forth_root_epsilon_imp(const T*, const mpl::int_<24>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.018581361171917516667460937040007436176452688944747L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T forth_root_epsilon_imp(const T*, const mpl::int_<53>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.0001220703125L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T forth_root_epsilon_imp(const T*, const mpl::int_<64>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.18145860519450699870567321328132261891067079047605e-4L); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T forth_root_epsilon_imp(const T*, const mpl::int_<113>&) BOOST_MATH_NOEXCEPT(T) +{ + return static_cast<T>(0.37252902984619140625e-8L); +} + +template <class T, class Tag> +inline T forth_root_epsilon_imp(const T*, const Tag&) +{ + BOOST_MATH_STD_USING + static const T r_eps = sqrt(sqrt(tools::epsilon<T>())); + return r_eps; +} + +template <class T> +inline T forth_root_epsilon_imp(const T*, const mpl::int_<0>&) +{ + BOOST_MATH_STD_USING + return sqrt(sqrt(tools::epsilon<T>())); +} + +template <class T> +struct root_epsilon_traits +{ + typedef mpl::int_< (::std::numeric_limits<T>::radix == 2) ? std::numeric_limits<T>::digits : 0> tag_type; + BOOST_STATIC_CONSTANT(bool, has_noexcept = (tag_type::value == 113) || (tag_type::value == 64) || (tag_type::value == 53) || (tag_type::value == 24)); +}; + +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T root_epsilon() BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && detail::root_epsilon_traits<T>::has_noexcept) +{ + return detail::root_epsilon_imp(static_cast<T const*>(0), typename detail::root_epsilon_traits<T>::tag_type()); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T cbrt_epsilon() BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && detail::root_epsilon_traits<T>::has_noexcept) +{ + return detail::cbrt_epsilon_imp(static_cast<T const*>(0), typename detail::root_epsilon_traits<T>::tag_type()); +} + +template <class T> +inline BOOST_MATH_CONSTEXPR T forth_root_epsilon() BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && detail::root_epsilon_traits<T>::has_noexcept) +{ + return detail::forth_root_epsilon_imp(static_cast<T const*>(0), typename detail::root_epsilon_traits<T>::tag_type()); +} + +} // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_PRECISION_INCLUDED + diff --git a/contrib/restricted/boost/math/include/boost/math/tools/promotion.hpp b/contrib/restricted/boost/math/include/boost/math/tools/promotion.hpp new file mode 100644 index 0000000000..494d7f99e2 --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/tools/promotion.hpp @@ -0,0 +1,182 @@ +// boost\math\tools\promotion.hpp + +// Copyright John Maddock 2006. +// Copyright Paul A. Bristow 2006. + +// 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) + +// Promote arguments functions to allow math functions to have arguments +// provided as integer OR real (floating-point, built-in or UDT) +// (called ArithmeticType in functions that use promotion) +// that help to reduce the risk of creating multiple instantiations. +// Allows creation of an inline wrapper that forwards to a foo(RT, RT) function, +// so you never get to instantiate any mixed foo(RT, IT) functions. + +#ifndef BOOST_MATH_PROMOTION_HPP +#define BOOST_MATH_PROMOTION_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +// Boost type traits: +#include <boost/math/tools/config.hpp> +#include <boost/type_traits/is_floating_point.hpp> // for boost::is_floating_point; +#include <boost/type_traits/is_integral.hpp> // for boost::is_integral +#include <boost/type_traits/is_convertible.hpp> // for boost::is_convertible +#include <boost/type_traits/is_same.hpp>// for boost::is_same +#include <boost/type_traits/remove_cv.hpp>// for boost::remove_cv +// Boost Template meta programming: +#include <boost/mpl/if.hpp> // for boost::mpl::if_c. +#include <boost/mpl/and.hpp> // for boost::mpl::if_c. +#include <boost/mpl/or.hpp> // for boost::mpl::if_c. +#include <boost/mpl/not.hpp> // for boost::mpl::if_c. + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +#include <boost/static_assert.hpp> +#endif + +namespace boost +{ + namespace math + { + namespace tools + { + // If either T1 or T2 is an integer type, + // pretend it was a double (for the purposes of further analysis). + // Then pick the wider of the two floating-point types + // as the actual signature to forward to. + // For example: + // foo(int, short) -> double foo(double, double); + // foo(int, float) -> double foo(double, double); + // Note: NOT float foo(float, float) + // foo(int, double) -> foo(double, double); + // foo(double, float) -> double foo(double, double); + // foo(double, float) -> double foo(double, double); + // foo(any-int-or-float-type, long double) -> foo(long double, long double); + // but ONLY float foo(float, float) is unchanged. + // So the only way to get an entirely float version is to call foo(1.F, 2.F), + // But since most (all?) the math functions convert to double internally, + // probably there would not be the hoped-for gain by using float here. + + // This follows the C-compatible conversion rules of pow, etc + // where pow(int, float) is converted to pow(double, double). + + template <class T> + struct promote_arg + { // If T is integral type, then promote to double. + typedef typename mpl::if_<is_integral<T>, double, T>::type type; + }; + // These full specialisations reduce mpl::if_ usage and speed up + // compilation: + template <> struct promote_arg<float> { typedef float type; }; + template <> struct promote_arg<double>{ typedef double type; }; + template <> struct promote_arg<long double> { typedef long double type; }; + template <> struct promote_arg<int> { typedef double type; }; + + template <class T1, class T2> + struct promote_args_2 + { // Promote, if necessary, & pick the wider of the two floating-point types. + // for both parameter types, if integral promote to double. + typedef typename promote_arg<T1>::type T1P; // T1 perhaps promoted. + typedef typename promote_arg<T2>::type T2P; // T2 perhaps promoted. + + typedef typename mpl::if_< + typename mpl::and_<is_floating_point<T1P>, is_floating_point<T2P> >::type, // both T1P and T2P are floating-point? +#ifdef BOOST_MATH_USE_FLOAT128 + typename mpl::if_< typename mpl::or_<is_same<__float128, T1P>, is_same<__float128, T2P> >::type, // either long double? + __float128, +#endif + typename mpl::if_< typename mpl::or_<is_same<long double, T1P>, is_same<long double, T2P> >::type, // either long double? + long double, // then result type is long double. + typename mpl::if_< typename mpl::or_<is_same<double, T1P>, is_same<double, T2P> >::type, // either double? + double, // result type is double. + float // else result type is float. + >::type +#ifdef BOOST_MATH_USE_FLOAT128 + >::type +#endif + >::type, + // else one or the other is a user-defined type: + typename mpl::if_< typename mpl::and_<mpl::not_<is_floating_point<T2P> >, ::boost::is_convertible<T1P, T2P> >, T2P, T1P>::type>::type type; + }; // promote_arg2 + // These full specialisations reduce mpl::if_ usage and speed up + // compilation: + template <> struct promote_args_2<float, float> { typedef float type; }; + template <> struct promote_args_2<double, double>{ typedef double type; }; + template <> struct promote_args_2<long double, long double> { typedef long double type; }; + template <> struct promote_args_2<int, int> { typedef double type; }; + template <> struct promote_args_2<int, float> { typedef double type; }; + template <> struct promote_args_2<float, int> { typedef double type; }; + template <> struct promote_args_2<int, double> { typedef double type; }; + template <> struct promote_args_2<double, int> { typedef double type; }; + template <> struct promote_args_2<int, long double> { typedef long double type; }; + template <> struct promote_args_2<long double, int> { typedef long double type; }; + template <> struct promote_args_2<float, double> { typedef double type; }; + template <> struct promote_args_2<double, float> { typedef double type; }; + template <> struct promote_args_2<float, long double> { typedef long double type; }; + template <> struct promote_args_2<long double, float> { typedef long double type; }; + template <> struct promote_args_2<double, long double> { typedef long double type; }; + template <> struct promote_args_2<long double, double> { typedef long double type; }; + + template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float> + struct promote_args + { + typedef typename promote_args_2< + typename remove_cv<T1>::type, + typename promote_args_2< + typename remove_cv<T2>::type, + typename promote_args_2< + typename remove_cv<T3>::type, + typename promote_args_2< + typename remove_cv<T4>::type, + typename promote_args_2< + typename remove_cv<T5>::type, typename remove_cv<T6>::type + >::type + >::type + >::type + >::type + >::type type; + +#ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + // + // Guard against use of long double if it's not supported: + // + BOOST_STATIC_ASSERT_MSG((0 == ::boost::is_same<type, long double>::value), "Sorry, but this platform does not have sufficient long double support for the special functions to be reliably implemented."); +#endif + }; + + // + // This struct is the same as above, but has no static assert on long double usage, + // it should be used only on functions that can be implemented for long double + // even when std lib support is missing or broken for that type. + // + template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float> + struct promote_args_permissive + { + typedef typename promote_args_2< + typename remove_cv<T1>::type, + typename promote_args_2< + typename remove_cv<T2>::type, + typename promote_args_2< + typename remove_cv<T3>::type, + typename promote_args_2< + typename remove_cv<T4>::type, + typename promote_args_2< + typename remove_cv<T5>::type, typename remove_cv<T6>::type + >::type + >::type + >::type + >::type + >::type type; + }; + + } // namespace tools + } // namespace math +} // namespace boost + +#endif // BOOST_MATH_PROMOTION_HPP + diff --git a/contrib/restricted/boost/math/include/boost/math/tools/real_cast.hpp b/contrib/restricted/boost/math/include/boost/math/tools/real_cast.hpp new file mode 100644 index 0000000000..873e60259b --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/tools/real_cast.hpp @@ -0,0 +1,31 @@ +// Copyright John Maddock 2006. +// 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) + +#ifndef BOOST_MATH_TOOLS_REAL_CAST_HPP +#define BOOST_MATH_TOOLS_REAL_CAST_HPP + +#include <boost/math/tools/config.hpp> + +#ifdef _MSC_VER +#pragma once +#endif + +namespace boost{ namespace math +{ + namespace tools + { + template <class To, class T> + inline BOOST_MATH_CONSTEXPR To real_cast(T t) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && BOOST_MATH_IS_FLOAT(To)) + { + return static_cast<To>(t); + } + } // namespace tools +} // namespace math +} // namespace boost + +#endif // BOOST_MATH_TOOLS_REAL_CAST_HPP + + + diff --git a/contrib/restricted/boost/math/include/boost/math/tools/user.hpp b/contrib/restricted/boost/math/include/boost/math/tools/user.hpp new file mode 100644 index 0000000000..08a7e53d9e --- /dev/null +++ b/contrib/restricted/boost/math/include/boost/math/tools/user.hpp @@ -0,0 +1,105 @@ +// Copyright John Maddock 2007. +// Copyright Paul A. Bristow 2007. + +// 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) + +#ifndef BOOST_MATH_TOOLS_USER_HPP +#define BOOST_MATH_TOOLS_USER_HPP + +#ifdef _MSC_VER +#pragma once +#endif + +// This file can be modified by the user to change the default policies. +// See "Changing the Policy Defaults" in documentation. + +// define this if the platform has no long double functions, +// or if the long double versions have only double precision: +// +// #define BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS +// +// Performance tuning options: +// +// #define BOOST_MATH_POLY_METHOD 3 +// #define BOOST_MATH_RATIONAL_METHOD 3 +// +// The maximum order of polynomial that will be evaluated +// via an unrolled specialisation: +// +// #define BOOST_MATH_MAX_POLY_ORDER 17 +// +// decide whether to store constants as integers or reals: +// +// #define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT + +// +// Default policies follow: +// +// Domain errors: +// +// #define BOOST_MATH_DOMAIN_ERROR_POLICY throw_on_error +// +// Pole errors: +// +// #define BOOST_MATH_POLE_ERROR_POLICY throw_on_error +// +// Overflow Errors: +// +// #define BOOST_MATH_OVERFLOW_ERROR_POLICY throw_on_error +// +// Internal Evaluation Errors: +// +// #define BOOST_MATH_EVALUATION_ERROR_POLICY throw_on_error +// +// Underfow: +// +// #define BOOST_MATH_UNDERFLOW_ERROR_POLICY ignore_error +// +// Denorms: +// +// #define BOOST_MATH_DENORM_ERROR_POLICY ignore_error +// +// Max digits to use for internal calculations: +// +// #define BOOST_MATH_DIGITS10_POLICY 0 +// +// Promote floats to doubles internally? +// +// #define BOOST_MATH_PROMOTE_FLOAT_POLICY true +// +// Promote doubles to long double internally: +// +// #define BOOST_MATH_PROMOTE_DOUBLE_POLICY true +// +// What do discrete quantiles return? +// +// #define BOOST_MATH_DISCRETE_QUANTILE_POLICY integer_round_outwards +// +// If a function is mathematically undefined +// (for example the Cauchy distribution has no mean), +// then do we stop the code from compiling? +// +// #define BOOST_MATH_ASSERT_UNDEFINED_POLICY true +// +// Maximum series iterstions permitted: +// +// #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 1000000 +// +// Maximum root finding steps permitted: +// +// define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 200 +// +// Enable use of __float128 in numeric constants: +// +// #define BOOST_MATH_USE_FLOAT128 +// +// Disable use of __float128 in numeric_constants even if the compiler looks to support it: +// +// #define BOOST_MATH_DISABLE_FLOAT128 + +#endif // BOOST_MATH_TOOLS_USER_HPP + + |