// 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 namespace boost { namespace math { namespace detail { template struct positive_power; template <> struct positive_power<2> { template static double result(T base) { return base*base; } }; template <> struct positive_power<0> { template static double result(T) { return 1; } }; template struct positive_power { template static double result(T base) { return (N%2) ? base*positive_power::result(base) : positive_power<2>::result( positive_power::result(base) ); } }; template struct power_if_positive { template static double result(T base) { return positive_power::result(base); } }; template struct power_if_positive { template static double result(T base) { return 1/positive_power<-N>::result(base); } }; } // namespace detail template double pow(T base) { typedef typename mpl::greater_equal< mpl::int_, mpl::int_<0> >::type is_positive; return detail::power_if_positive::result(base); } } // namespace math } // namespace boost #endif