StemFunction.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
5 //
6 // Eigen is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // Alternatively, you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of
14 // the License, or (at your option) any later version.
15 //
16 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License and a copy of the GNU General Public License along with
23 // Eigen. If not, see <http://www.gnu.org/licenses/>.
24 
25 #ifndef EIGEN_STEM_FUNCTION
26 #define EIGEN_STEM_FUNCTION
27 
28 namespace Eigen {
29 
33 template <typename Scalar>
35 {
36  public:
37 
39  static Scalar exp(Scalar x, int)
40  {
41  return std::exp(x);
42  }
43 
45  static Scalar cos(Scalar x, int n)
46  {
47  Scalar res;
48  switch (n % 4) {
49  case 0:
50  res = std::cos(x);
51  break;
52  case 1:
53  res = -std::sin(x);
54  break;
55  case 2:
56  res = -std::cos(x);
57  break;
58  case 3:
59  res = std::sin(x);
60  break;
61  }
62  return res;
63  }
64 
66  static Scalar sin(Scalar x, int n)
67  {
68  Scalar res;
69  switch (n % 4) {
70  case 0:
71  res = std::sin(x);
72  break;
73  case 1:
74  res = std::cos(x);
75  break;
76  case 2:
77  res = -std::sin(x);
78  break;
79  case 3:
80  res = -std::cos(x);
81  break;
82  }
83  return res;
84  }
85 
87  static Scalar cosh(Scalar x, int n)
88  {
89  Scalar res;
90  switch (n % 2) {
91  case 0:
92  res = std::cosh(x);
93  break;
94  case 1:
95  res = std::sinh(x);
96  break;
97  }
98  return res;
99  }
100 
102  static Scalar sinh(Scalar x, int n)
103  {
104  Scalar res;
105  switch (n % 2) {
106  case 0:
107  res = std::sinh(x);
108  break;
109  case 1:
110  res = std::cosh(x);
111  break;
112  }
113  return res;
114  }
115 
116 }; // end of class StdStemFunctions
117 
118 } // end namespace Eigen
119 
120 #endif // EIGEN_STEM_FUNCTION