Chris@16: // Boost.Units - A C++ library for zero-overhead dimensional analysis and Chris@16: // unit/quantity manipulation and conversion Chris@16: // Chris@16: // Copyright (C) 2003-2008 Matthias Christian Schabel Chris@16: // Copyright (C) 2008 Steven Watanabe Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_UNITS_POW_HPP Chris@16: #define BOOST_UNITS_POW_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: /// \file Chris@16: /// \brief Raise values to exponents known at compile-time. Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: namespace units { Chris@16: Chris@16: /// raise a value to a @c static_rational power. Chris@16: template Chris@16: inline typename power_typeof_helper::type Chris@16: pow(const Y& x) Chris@16: { Chris@16: return power_typeof_helper::value(x); Chris@16: } Chris@16: Chris@16: /// raise a value to an integer power. Chris@16: template Chris@16: inline typename power_typeof_helper >::type Chris@16: pow(const Y& x) Chris@16: { Chris@16: return power_typeof_helper >::value(x); Chris@16: } Chris@16: Chris@16: #ifndef BOOST_UNITS_DOXYGEN Chris@16: Chris@16: /// raise @c T to a @c static_rational power. Chris@16: template Chris@16: struct power_typeof_helper > Chris@16: { Chris@16: typedef typename mpl::if_, double, T>::type internal_type; Chris@16: typedef detail::static_rational_power_impl, internal_type> impl; Chris@16: typedef typename impl::type type; Chris@16: Chris@16: static type value(const T& x) Chris@16: { Chris@16: return impl::call(x); Chris@16: } Chris@16: }; Chris@16: Chris@16: /// raise @c float to a @c static_rational power. Chris@16: template Chris@16: struct power_typeof_helper > Chris@16: { Chris@16: // N.B. pathscale doesn't accept inheritance for some reason. Chris@16: typedef power_typeof_helper > base; Chris@16: typedef typename base::type type; Chris@16: static type value(const double& x) Chris@16: { Chris@16: return base::value(x); Chris@16: } Chris@16: }; Chris@16: Chris@16: #endif Chris@16: Chris@16: /// take the @c static_rational root of a value. Chris@16: template Chris@16: typename root_typeof_helper::type Chris@16: root(const Y& x) Chris@16: { Chris@16: return root_typeof_helper::value(x); Chris@16: } Chris@16: Chris@16: /// take the integer root of a value. Chris@16: template Chris@16: typename root_typeof_helper >::type Chris@16: root(const Y& x) Chris@16: { Chris@16: return root_typeof_helper >::value(x); Chris@16: } Chris@16: Chris@16: #ifndef BOOST_UNITS_DOXYGEN Chris@16: Chris@16: /// take @c static_rational root of an @c T Chris@16: template Chris@16: struct root_typeof_helper > Chris@16: { Chris@16: // N.B. pathscale doesn't accept inheritance for some reason. Chris@16: typedef power_typeof_helper > base; Chris@16: typedef typename base::type type; Chris@16: static type value(const T& x) Chris@16: { Chris@16: return(base::value(x)); Chris@16: } Chris@16: }; Chris@16: Chris@16: #endif Chris@16: Chris@16: } // namespace units Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_UNITS_STATIC_RATIONAL_HPP