Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/units/pow.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Boost.Units - A C++ library for zero-overhead dimensional analysis and 
0002 // unit/quantity manipulation and conversion
0003 //
0004 // Copyright (C) 2003-2008 Matthias Christian Schabel
0005 // Copyright (C) 2008 Steven Watanabe
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See
0008 // accompanying file LICENSE_1_0.txt or copy at
0009 // http://www.boost.org/LICENSE_1_0.txt)
0010 
0011 #ifndef BOOST_UNITS_POW_HPP 
0012 #define BOOST_UNITS_POW_HPP
0013 
0014 #include <boost/type_traits/is_integral.hpp>
0015 
0016 #include <boost/units/operators.hpp>
0017 #include <boost/units/static_rational.hpp>
0018 #include <boost/units/detail/static_rational_power.hpp>
0019 
0020 /// \file 
0021 /// \brief Raise values to exponents known at compile-time.
0022 
0023 namespace boost {
0024 
0025 namespace units {
0026 
0027 /// raise a value to a @c static_rational power.
0028 template<class Rat,class Y>
0029 BOOST_CONSTEXPR
0030 inline typename power_typeof_helper<Y,Rat>::type
0031 pow(const Y& x)
0032 {
0033     return power_typeof_helper<Y,Rat>::value(x);
0034 }
0035 
0036 /// raise a value to an integer power.
0037 template<long N,class Y>
0038 BOOST_CONSTEXPR
0039 inline typename power_typeof_helper<Y,static_rational<N> >::type
0040 pow(const Y& x)
0041 {
0042     return power_typeof_helper<Y,static_rational<N> >::value(x);
0043 }
0044 
0045 #ifndef BOOST_UNITS_DOXYGEN
0046 
0047 /// raise @c T to a @c static_rational power.
0048 template<class T, long N,long D> 
0049 struct power_typeof_helper<T, static_rational<N,D> >                
0050 { 
0051     typedef typename mpl::if_<boost::is_integral<T>, double, T>::type internal_type;
0052     typedef detail::static_rational_power_impl<static_rational<N, D>, internal_type> impl;
0053     typedef typename impl::type type; 
0054     
0055     static BOOST_CONSTEXPR type value(const T& x)  
0056     {
0057         return impl::call(x);
0058     }
0059 };
0060 
0061 /// raise @c float to a @c static_rational power.
0062 template<long N,long D> 
0063 struct power_typeof_helper<float, static_rational<N,D> >
0064 {
0065     // N.B.  pathscale doesn't accept inheritance for some reason.
0066     typedef power_typeof_helper<double, static_rational<N,D> > base;
0067     typedef typename base::type type;
0068     static BOOST_CONSTEXPR type value(const double& x)
0069     {
0070         return base::value(x);
0071     }
0072 };
0073 
0074 #endif
0075 
0076 /// take the @c static_rational root of a value.
0077 template<class Rat,class Y>
0078 BOOST_CONSTEXPR
0079 typename root_typeof_helper<Y,Rat>::type
0080 root(const Y& x)
0081 {
0082     return root_typeof_helper<Y,Rat>::value(x);
0083 }
0084 
0085 /// take the integer root of a value.
0086 template<long N,class Y>
0087 BOOST_CONSTEXPR
0088 typename root_typeof_helper<Y,static_rational<N> >::type
0089 root(const Y& x)
0090 {
0091     return root_typeof_helper<Y,static_rational<N> >::value(x);
0092 }
0093 
0094 #ifndef BOOST_UNITS_DOXYGEN
0095 
0096 /// take @c static_rational root of an @c T
0097 template<class T, long N,long D> 
0098 struct root_typeof_helper<T,static_rational<N,D> >
0099 {
0100     // N.B.  pathscale doesn't accept inheritance for some reason.
0101     typedef power_typeof_helper<T, static_rational<D,N> > base;
0102     typedef typename base::type type;
0103     static BOOST_CONSTEXPR type value(const T& x)
0104     {
0105         return(base::value(x));
0106     }
0107 };
0108 
0109 #endif
0110 
0111 } // namespace units
0112 
0113 } // namespace boost
0114 
0115 #endif // BOOST_UNITS_STATIC_RATIONAL_HPP