X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=boost%2Fmath%2Fspecial_functions%2Fpow.hpp;fp=boost%2Fmath%2Fspecial_functions%2Fpow.hpp;h=5423e9c8e409f7f826c30938f9a611cbe1f231cf;hp=0000000000000000000000000000000000000000;hb=2d71eb92104693ca9baa5a2e1c23eeca776d8fd3;hpb=da57529b92adbb7ae74a89861cb39fb35ac7c62d diff --git a/boost/math/special_functions/pow.hpp b/boost/math/special_functions/pow.hpp new file mode 100644 index 0000000..5423e9c --- /dev/null +++ b/boost/math/special_functions/pow.hpp @@ -0,0 +1,140 @@ +// Boost pow.hpp header file +// Computes a power with exponent known at compile-time + +// (C) Copyright Bruno Lalande 2008. +// 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) + +// See http://www.boost.org for updates, documentation, and revision history. + + +#ifndef BOOST_MATH_POW_HPP +#define BOOST_MATH_POW_HPP + + +#include +#include +#include +#include + + +namespace boost { +namespace math { + + +namespace detail { + + +template +struct positive_power +{ + template + static T result(T base) + { + T power = positive_power::result(base); + return power * power; + } +}; + +template +struct positive_power +{ + template + static T result(T base) + { + T power = positive_power::result(base); + return base * power * power; + } +}; + +template <> +struct positive_power<1, 1> +{ + template + static T result(T base){ return base; } +}; + + +template +struct power_if_positive +{ + template + static T result(T base, const Policy&) + { return positive_power::result(base); } +}; + +template +struct power_if_positive +{ + template + static T result(T base, const Policy& policy) + { + if (base == 0) + { + return policies::raise_overflow_error( + "boost::math::pow(%1%)", + "Attempted to compute a negative power of 0", + policy + ); + } + + return T(1) / positive_power<-N>::result(base); + } +}; + +template <> +struct power_if_positive<0, true> +{ + template + static T result(T base, const Policy& policy) + { + if (base == 0) + { + return policies::raise_indeterminate_result_error( + "boost::math::pow(%1%)", + "The result of pow<0>(%1%) is undetermined", + base, + T(1), + policy + ); + } + + return T(1); + } +}; + + +template +struct select_power_if_positive +{ + typedef typename mpl::greater_equal< + mpl::int_, + mpl::int_<0> + >::type is_positive; + + typedef power_if_positive type; +}; + + +} // namespace detail + + +template +inline typename tools::promote_args::type pow(T base, const Policy& policy) +{ + typedef typename tools::promote_args::type result_type; + return detail::select_power_if_positive::type::result(static_cast(base), policy); +} + + +template +inline typename tools::promote_args::type pow(T base) +{ return pow(base, policies::policy<>()); } + + +} // namespace math +} // namespace boost + + +#endif