RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
tan.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_TAN_HH
22 #define RFFGEN_CMATH_TAN_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 Tan : Base , Chainer<Tan>
41  {
42  using Chainer<Tan>::operator ();
47  explicit Tan(double x=0.) { update(x); }
48 
50  void update(double x)
51  {
52  value = ::tan(x);
53  firstDerivative = 1 + ( value * value );
54  }
55 
57  double d0() const noexcept
58  {
59  return value;
60  }
61 
63  template < int = -1 >
64  double d1(double dx = 1.) const
65  {
66  return firstDerivative * dx;
67  }
68 
70  template < int = -1 , int = -1 >
71  double d2(double dx = 1., double dy = 1.) const
72  {
73  return ( 2 * value * firstDerivative ) * dx * dy;
74  }
75 
77  template < int = -1 , int = -1 , int = -1 >
78  double d3(double dx = 1., double dy = 1., double dz = 1.) const
79  {
80  return 2 * firstDerivative * ( 1 + ( 3 * value * value ) ) * dx * dy * dz;
81  }
82 
83  private:
84  double value = 0., firstDerivative = 1.;
85  };
86 
91  template <class Function, class = std::enable_if_t<std::is_base_of<Base,Function>::value> >
92  auto tan(const Function& f)
93  {
94  return Tan()(f);
95  }
96  }
97 }
98 
99 #endif // RFFGEN_CMATH_TAN_HH
double d3(double dx=1., double dy=1., double dz=1.) const
Third (directional) derivative.
Definition: tan.hh:78
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Tan(double x=0.)
Constructor.
Definition: tan.hh:47
double d2(double dx=1., double dy=1.) const
Second (directinal) derivative.
Definition: tan.hh:71
double d1(double dx=1.) const
First (directional) derivative.
Definition: tan.hh:64
void update(double x)
Reset point of evaluation.
Definition: tan.hh:50
double d0() const noexcept
Function value.
Definition: tan.hh:57
Tangent function including first three derivatives.
Definition: tan.hh:40