MIRA
base
include
math
Power.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2012 by
3
* MetraLabs GmbH (MLAB), GERMANY
4
* and
5
* Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6
* All rights reserved.
7
*
8
* Contact: info@mira-project.org
9
*
10
* Commercial Usage:
11
* Licensees holding valid commercial licenses may use this file in
12
* accordance with the commercial license agreement provided with the
13
* software or, alternatively, in accordance with the terms contained in
14
* a written agreement between you and MLAB or NICR.
15
*
16
* GNU General Public License Usage:
17
* Alternatively, this file may be used under the terms of the GNU
18
* General Public License version 3.0 as published by the Free Software
19
* Foundation and appearing in the file LICENSE.GPL3 included in the
20
* packaging of this file. Please review the following information to
21
* ensure the GNU General Public License version 3.0 requirements will be
22
* met: http://www.gnu.org/copyleft/gpl.html.
23
* Alternatively you may (at your option) use any later version of the GNU
24
* General Public License if such license has been publicly approved by
25
* MLAB and NICR (or its successors, if any).
26
*
27
* IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28
* INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29
* THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30
* "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*
32
* "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35
* ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37
*/
38
48
#ifndef _MIRA_POWER_H_
49
#define _MIRA_POWER_H_
50
51
#include <cmath>
52
53
namespace
mira
{
54
56
57
namespace
detail {
58
59
template
<
typename
T,
int
N>
60
struct
PowerComputer
61
{
62
inline
static
T
eval
(T base) {
63
return
PowerComputer<T,N-1>::eval
(base)*base;
64
}
65
};
66
67
template
<
typename
T>
68
struct
PowerComputer
<T,1>
69
{
70
inline
static
T
eval
(T base) {
71
return
base;
72
}
73
};
74
75
template
<
typename
T>
76
struct
PowerComputer
<T,0>
77
{
78
inline
static
T
eval
(T base) {
79
return
1;
80
}
81
};
82
83
}
85
103
template
<
int
exponent,
typename
T>
104
inline
T
pow
(T base)
105
{
106
return
detail::PowerComputer<T,exponent>::eval
(base);
107
}
108
113
template
<
typename
T>
114
inline
T
pow2
(T base)
115
{
116
return
base*base;
117
}
118
123
template
<
typename
T>
124
inline
T
pow3
(T base)
125
{
126
return
base*base*base;
127
}
128
130
142
template
<
int
base,
int
exponent>
143
struct
TPower
{
144
enum
{
145
value
=
TPower
<base,exponent-1>
::value
* base
146
};
147
};
148
149
template
<
int
base>
150
struct
TPower
<base,0> {
151
enum
{
152
value
= 1
153
};
154
};
155
156
158
159
// two workarounds for those guys that use the old C pow(double,double) method -
160
// this now delegate those calls to the preferred std::pow() methods
161
template
<
typename
T,
typename
U>
162
inline
T
pow
(T base, U exponent)
163
{
164
return
std::pow
(base,exponent);
165
}
166
167
template
<
typename
T>
168
inline
T
pow
(T base, T exponent)
169
{
170
return
std::pow
(base,exponent);
171
}
172
174
175
}
// namespace
176
177
#endif
mira::detail::PowerComputer
Definition:
Power.h:60
mira
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition:
IOService.h:67
mira::pow3
T pow3(T base)
Computes base^3.
Definition:
Power.h:124
mira::detail::PowerComputer< T, 1 >::eval
static T eval(T base)
Definition:
Power.h:70
mira::detail::PowerComputer< T, 0 >::eval
static T eval(T base)
Definition:
Power.h:78
mira::pow
T pow(T base, T exponent)
Definition:
Power.h:168
mira::detail::PowerComputer::eval
static T eval(T base)
Definition:
Power.h:62
mira::TPower
Computes the power base^exponent at compile time.
Definition:
Power.h:143
mira::pow
T pow(T base)
Computes the power of 'base' with a constant integral exponent.
Definition:
Power.h:104
mira::TPower::value
Definition:
Power.h:145
mira::pow2
T pow2(T base)
Computes base^2.
Definition:
Power.h:114
SVN-r10557 , Generated on Sat Nov 23 2024 03:33:33 for MIRA by
1.8.14