Dune Core Modules (2.6.0)

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 
18  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 namespace.
Definition: alignedallocator.hh:10
Compute power for a run-time mantissa and a compile-time integer exponent.
Definition: power.hh:47
Calculates m^p at compile time.
Definition: power.hh:20
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 19, 22:31, 2024)