MADNESS 0.10.1
power.h
Go to the documentation of this file.
1/*
2 This file is part of MADNESS.
3
4 Copyright (C) 2007,2010 Oak Ridge National Laboratory
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 For more information please contact:
21
22 Robert J. Harrison
23 Oak Ridge National Laboratory
24 One Bethel Valley Road
25 P.O. Box 2008, MS-6367
26
27 email: harrisonrj@ornl.gov
28 tel: 865-241-3937
29 fax: 865-572-0680
30
31
32 $Id$
33*/
34
35
36#ifndef MADNESS_MRA_POWER_H__INCLUDED
37#define MADNESS_MRA_POWER_H__INCLUDED
38
39
40namespace madness {
41
42 template <int D>
43 inline int power(int base = 2) {
44 return (int) std::pow((double) base, (int) D);
45 }
46
47 template <>
48 inline int power<0>(int base) {
49 return 1;
50 }
51
52 template <>
53 inline int power<1>(int base) {
54 return base;
55 }
56
57 template <>
58 inline int power<2>(int base) {
59 return (int)(base*base);
60 }
61
62 template <>
63 inline int power<3>(int base) {
64 return (int)(base*base*base);
65 }
66
67 template <>
68 inline int power<4>(int base) {
69 return power<2>(power<2>(base));
70 }
71
72 template <>
73 inline int power<5>(int base) {
74 return (power<2>(base)*power<3>(base));
75 }
76
77 template <>
78 inline int power<6>(int base) {
79 return power<2>(power<3>(base));
80 }
81
82 template <>
83 inline int power<7>(int base) {
84 return (power<4>(base)*power<3>(base));
85 }
86
87 template <>
88 inline int power<8>(int base) {
89 return (power<2>(power<4>(base)));
90 }
91
92 template <>
93 inline int power<9>(int base) {
94 return (power<3>(power<3>(base)));
95 }
96
97 template <>
98 inline int power<10>(int base) {
99 return (power<2>(power<5>(base)));
100 }
101
102 template <>
103 inline int power<12>(int base) {
104 return (power<3>(power<4>(base)));
105 }
106
107
108 // Florian: following code from the internet (stackoverflow)
109 namespace detail {
110 template<class T, int N>
111 struct helper {
112 static T pow(const T x){
113 return helper<T, N-1>::pow(x) * x;
114 }
115 };
116
117 template<class T>
118 struct helper<T, 1> {
119 static T pow(const T x){
120 return x;
121 }
122 };
123
124 template<class T>
125 struct helper<T, 0> {
126 static T pow(const T x){
127 return 1;
128 }
129 };
130 }
131
132 template<int N, class T>
133 T power(T const x) {
135 }
136
137}
138
139#endif
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
int power(int base=2)
Definition power.h:43
int power< 4 >(int base)
Definition power.h:68
int power< 5 >(int base)
Definition power.h:73
int power< 0 >(int base)
Definition power.h:48
int power< 12 >(int base)
Definition power.h:103
int power< 2 >(int base)
Definition power.h:58
int power< 10 >(int base)
Definition power.h:98
int power< 7 >(int base)
Definition power.h:83
int power< 3 >(int base)
Definition power.h:63
int power< 1 >(int base)
Definition power.h:53
int power< 9 >(int base)
Definition power.h:93
int power< 6 >(int base)
Definition power.h:78
int power< 8 >(int base)
Definition power.h:88
Definition test_ar.cc:204
static T pow(const T x)
Definition power.h:126
static T pow(const T x)
Definition power.h:119
Definition power.h:111
static T pow(const T x)
Definition power.h:112