RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
cosine.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen 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 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* RFFGen 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 RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_CMATH_COSINE_HH
22 #define RFFGEN_CMATH_COSINE_HH
23 
24 #include <cmath>
25 #include "../Util/base.hh"
26 #include "../Util/chainer.hh"
27 
28 namespace RFFGen
29 {
30  namespace CMath
31  {
42  struct Cos : Base , Chainer<Cos>
43  {
44  using Chainer<Cos>::operator ();
49  explicit Cos(double x=0.)
50  {
51  update(x);
52  }
53 
55  void update(const double& x)
56  {
57  sinx = ::sin(x);
58  cosx = ::cos(x);
59  }
60 
62  double d0() const noexcept { return cosx; }
63 
65  template < int = -1 >
66  double d1(double dx=1.) const { return -sinx*dx; }
67 
69  template < int = -1 , int = -1 >
70  double d2(double dx=1., double dy=1.) const { return -cosx*dx*dy; }
71 
73  template < int = -1, int = -1 , int = -1 >
74  double d3(double dx=1., double dy=1., double dz=1.) const { return sinx*dx*dy*dz; }
75 
76  private:
77  double sinx, cosx;
78  };
79 
84  template < class Function ,
85  class = std::enable_if_t< std::is_base_of<Base,Function>::value > >
86  auto cos(const Function& f)
87  {
88  return Cos()(f);
89  }
90  }
91 }
92 
93 #endif // RFFGEN_CMATH_COSINE_HH
double d1(double dx=1.) const
First (directional) derivative.
Definition: cosine.hh:66
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Cosine function including first three derivatives (based on cos(double) in <cmath>).
Definition: cosine.hh:42
double d2(double dx=1., double dy=1.) const
Second (directional) derivative.
Definition: cosine.hh:70
Cos(double x=0.)
Constructor.
Definition: cosine.hh:49
double d3(double dx=1., double dy=1., double dz=1.) const
Third (directional) derivative.
Definition: cosine.hh:74
void update(const double &x)
Reset point of evaluation.
Definition: cosine.hh:55
double d0() const noexcept
Function value.
Definition: cosine.hh:62