fix doc example typo
[boost.git] / boost / units / pow.hpp
blobed0b3e4af40b9c57e7ac8d83754b5ef620da61d6
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
3 //
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_UNITS_POW_HPP
12 #define BOOST_UNITS_POW_HPP
14 #include <boost/math_fwd.hpp>
15 #include <boost/type_traits/is_integral.hpp>
17 #include <boost/units/operators.hpp>
18 #include <boost/units/static_rational.hpp>
19 #include <boost/units/detail/static_rational_power.hpp>
21 /// \file
22 /// \brief Raise values to exponents known at compile-time
24 namespace boost {
26 namespace units {
28 /// raise a value to a @c static_rational power
29 template<class Rat,class Y>
30 inline typename power_typeof_helper<Y,Rat>::type
31 pow(const Y& x)
33 return power_typeof_helper<Y,Rat>::value(x);
36 /// raise a value to an integer power
37 template<long N,class Y>
38 inline typename power_typeof_helper<Y,static_rational<N> >::type
39 pow(const Y& x)
41 return power_typeof_helper<Y,static_rational<N> >::value(x);
44 #ifndef BOOST_UNITS_DOXYGEN
46 /// raise @c T to a @c static_rational power
47 template<class T, long N,long D>
48 struct power_typeof_helper<T, static_rational<N,D> >
50 typedef typename mpl::if_<boost::is_integral<T>, double, T>::type internal_type;
51 typedef detail::static_rational_power_impl<static_rational<N, D>, internal_type> impl;
52 typedef typename impl::type type;
54 static type value(const T& x)
56 return impl::call(x);
60 /// raise @c float to a @c static_rational power
61 template<long N,long D>
62 struct power_typeof_helper<float, static_rational<N,D> >
64 // N.B. pathscale doesn't accept inheritence for some reason.
65 typedef power_typeof_helper<double, static_rational<N,D> > base;
66 typedef typename base::type type;
67 static type value(const double& x)
69 return base::value(x);
73 #endif
75 /// take the @c static_rational root of a value
76 template<class Rat,class Y>
77 typename root_typeof_helper<Y,Rat>::type
78 root(const Y& x)
80 return root_typeof_helper<Y,Rat>::value(x);
83 /// take the integer root of a value
84 template<long N,class Y>
85 typename root_typeof_helper<Y,static_rational<N> >::type
86 root(const Y& x)
88 return root_typeof_helper<Y,static_rational<N> >::value(x);
91 #ifndef BOOST_UNITS_DOXYGEN
93 /// take @c static_rational root of an @c T
94 template<class T, long N,long D>
95 struct root_typeof_helper<T,static_rational<N,D> >
97 // N.B. pathscale doesn't accept inheritence for some reason.
98 typedef power_typeof_helper<T, static_rational<D,N> > base;
99 typedef typename base::type type;
100 static type value(const T& x)
102 return(base::value(x));
106 #endif
108 } // namespace units
110 } // namespace boost
112 #endif // BOOST_UNITS_STATIC_RATIONAL_HPP