RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
sine.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_SINE_HH
22 #define RFFGEN_CMATH_SINE_HH
23 
24 #include <cmath>
25 #include "../Util/base.hh"
26 #include "../Util/chainer.hh"
27 
28 namespace RFFGen
29 {
30  namespace CMath
31  {
40  struct Sin : Base , Chainer<Sin>
41  {
42  using Chainer<Sin>::operator ();
43 
48  explicit Sin(double x=0)
49  {
50  update(x);
51  }
52 
54  void update(double x)
55  {
56  sinx = ::sin(x);
57  cosx = ::cos(x);
58  }
59 
61  double d0() const noexcept { return sinx; }
62 
64  template < int = -1 >
65  double d1(double dx=1.) const { return cosx*dx; }
66 
68  template < int = -1 , int = -1 >
69  double d2(double dx=1., double dy=1.) const { return -sinx*dx*dy; }
70 
72  template < int = -1 , int = -1 , int = -1>
73  double d3(double dx=1., double dy=1., double dz=1.) const { return -cosx*dx*dy*dz; }
74 
75  private:
76  double sinx, cosx;
77  };
78 
83  template <class Function, class = std::enable_if_t<std::is_base_of<Base,Function>::value> >
84  auto sin(const Function& f)
85  {
86  return Sin()(f);
87  }
88  }
89 }
90 
91 #endif // RFFGEN_CMATH_SINE_HH
double d2(double dx=1., double dy=1.) const
Second (directional) derivative.
Definition: sine.hh:69
double d3(double dx=1., double dy=1., double dz=1.) const
Third (directional) derivative.
Definition: sine.hh:73
double d0() const noexcept
Function value.
Definition: sine.hh:61
void update(double x)
Reset point of evaluation.
Definition: sine.hh:54
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
double d1(double dx=1.) const
First (directional) derivative.
Definition: sine.hh:65
Sine function including first three derivatives (based on sin(double) in <cmath>).
Definition: sine.hh:40
Sin(double x=0)
Constructor.
Definition: sine.hh:48