dune-common
2.6-git
dune
common
power.hh
Go to the documentation of this file.
1
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
// vi: set et ts=4 sw=2 sts=2:
3
#ifndef DUNE_COMMON_POWER_HH
4
#define DUNE_COMMON_POWER_HH
5
10
namespace
Dune
{
11
17
template
<
int
m,
int
p>
19
struct
StaticPower
20
{
22
enum
{
power
= (m *
StaticPower
<m,p-1>
::power
) };
23
};
24
26
template
<
int
m>
27
struct
StaticPower
< m , 0>
28
{
30
enum
{
power
= 1 };
31
};
32
33
34
#ifndef DOXYGEN
35
template
<
int
p,
bool
odd = p%2>
36
struct
PowerImp {};
37
#endif
38
45
template
<
int
p>
46
struct
Power
47
{
48
template
<
typename
T>
49
static
T
eval
(
const
T & a)
50
{
51
return
PowerImp<p>::eval(a);
52
}
53
};
54
55
#ifndef DOXYGEN
56
template
<
int
p>
57
struct
PowerImp<p,false>
58
{
59
template
<
typename
T>
60
static
T eval(
const
T & a)
61
{
62
T t = Power<p/2>::eval(a);
63
return
t*t;
64
}
65
};
66
67
template
<
int
p>
68
struct
PowerImp<p,true>
69
{
70
template
<
typename
T>
71
static
T eval(
const
T & a)
72
{
73
return
a*
Power<p-1>::eval
(a);;
74
}
75
};
76
77
template
<>
78
struct
PowerImp<1,true>
79
{
80
template
<
typename
T>
81
static
T eval(
const
T & a)
82
{
83
return
a;
84
}
85
};
86
#endif
87
88
}
89
90
#endif
Dune
Dune namespace.
Definition:
alignedallocator.hh:9
Dune::Power
Compute power for a run-time mantissa and a compile-time integer exponent.
Definition:
power.hh:46
Dune::StaticPower::power
@ power
Definition:
power.hh:22
Dune::Power::eval
static T eval(const T &a)
Definition:
power.hh:49
Dune::StaticPower
Calculates m^p at compile time.
Definition:
power.hh:19
Generated by
1.8.17