00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MLN_METAL_MATH_POW_HH
00027 # define MLN_METAL_MATH_POW_HH
00028
00034 # include <mln/metal/bool.hh>
00035 # include <mln/metal/int.hh>
00036
00037
00038 # define mlc_pow(X, N) typename mln::metal::math::pow< X, N >::ret
00039 # define mlc_pow_int(x, n) mln::metal::math::pow_int< x, n >::value
00040
00041
00042
00043 namespace mln
00044 {
00045
00046 namespace metal
00047 {
00048
00049 namespace math
00050 {
00051
00052
00053
00054 namespace impl
00055 {
00056
00057 template <int x, int n>
00058 struct pow_int_
00059 {
00060 enum res_ { value = x * pow_int_<x, n-1>::value };
00061 };
00062
00063 template <int x>
00064 struct pow_int_< x, 0 >
00065 {
00066 enum res_ { value = 1 };
00067 };
00068
00069 template <>
00070 struct pow_int_< 0, 0 >;
00071
00072
00073
00074
00075 template <int x, int n, bool b>
00076 struct pow_int_if_ : pow_int_<x, n>
00077 {
00078 };
00079
00080 template <int x, int n>
00081 struct pow_int_if_< x, n, false >
00082 {
00083 };
00084
00085 }
00086
00087 template <int x, int n>
00088 struct pow_int : impl::pow_int_if_< x, n,
00089 (n >= 0 && ! (x == 0 && n == 0)) >
00090 {
00091 };
00092
00093
00094
00095
00096 template <typename X, typename N>
00097 struct pow;
00098
00099 template <int x, int n>
00100 struct pow< int_<x>, int_<n> >
00101 {
00102 typedef int_< pow_int<x, n>::value > ret;
00103 };
00104
00105
00106 }
00107
00108 }
00109
00110 }
00111
00112
00113 #endif // ! MLN_METAL_MATH_POW_HH