]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/units/include/boost/units/pow.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / units / include / boost / units / pow.hpp
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)
10
11 #ifndef BOOST_UNITS_POW_HPP
12 #define BOOST_UNITS_POW_HPP
13
14 #include <boost/math_fwd.hpp>
15 #include <boost/type_traits/is_integral.hpp>
16
17 #include <boost/units/operators.hpp>
18 #include <boost/units/static_rational.hpp>
19 #include <boost/units/detail/static_rational_power.hpp>
20
21 /// \file
22 /// \brief Raise values to exponents known at compile-time.
23
24 namespace boost {
25
26 namespace units {
27
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)
32 {
33 return power_typeof_helper<Y,Rat>::value(x);
34 }
35
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)
40 {
41 return power_typeof_helper<Y,static_rational<N> >::value(x);
42 }
43
44 #ifndef BOOST_UNITS_DOXYGEN
45
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> >
49 {
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;
53
54 static type value(const T& x)
55 {
56 return impl::call(x);
57 }
58 };
59
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> >
63 {
64 // N.B. pathscale doesn't accept inheritance 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)
68 {
69 return base::value(x);
70 }
71 };
72
73 #endif
74
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)
79 {
80 return root_typeof_helper<Y,Rat>::value(x);
81 }
82
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)
87 {
88 return root_typeof_helper<Y,static_rational<N> >::value(x);
89 }
90
91 #ifndef BOOST_UNITS_DOXYGEN
92
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> >
96 {
97 // N.B. pathscale doesn't accept inheritance 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)
101 {
102 return(base::value(x));
103 }
104 };
105
106 #endif
107
108 } // namespace units
109
110 } // namespace boost
111
112 #endif // BOOST_UNITS_STATIC_RATIONAL_HPP