Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:05

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2010, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
0005 //
0006 // This Source Code Form is subject to the terms of the Mozilla
0007 // Public License v. 2.0. If a copy of the MPL was not distributed
0008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0009 
0010 #ifndef EIGEN_STEM_FUNCTION
0011 #define EIGEN_STEM_FUNCTION
0012 
0013 namespace Eigen { 
0014 
0015 namespace internal {
0016 
0017 /** \brief The exponential function (and its derivatives). */
0018 template <typename Scalar>
0019 Scalar stem_function_exp(Scalar x, int)
0020 {
0021   using std::exp;
0022   return exp(x);
0023 }
0024 
0025 /** \brief Cosine (and its derivatives). */
0026 template <typename Scalar>
0027 Scalar stem_function_cos(Scalar x, int n)
0028 {
0029   using std::cos;
0030   using std::sin;
0031   Scalar res;
0032 
0033   switch (n % 4) {
0034   case 0: 
0035     res = std::cos(x);
0036     break;
0037   case 1:
0038     res = -std::sin(x);
0039     break;
0040   case 2:
0041     res = -std::cos(x);
0042     break;
0043   case 3:
0044     res = std::sin(x);
0045     break;
0046   }
0047   return res;
0048 }
0049 
0050 /** \brief Sine (and its derivatives). */
0051 template <typename Scalar>
0052 Scalar stem_function_sin(Scalar x, int n)
0053 {
0054   using std::cos;
0055   using std::sin;
0056   Scalar res;
0057 
0058   switch (n % 4) {
0059   case 0:
0060     res = std::sin(x);
0061     break;
0062   case 1:
0063     res = std::cos(x);
0064     break;
0065   case 2:
0066     res = -std::sin(x);
0067     break;
0068   case 3:
0069     res = -std::cos(x);
0070     break;
0071   }
0072   return res;
0073 }
0074 
0075 /** \brief Hyperbolic cosine (and its derivatives). */
0076 template <typename Scalar>
0077 Scalar stem_function_cosh(Scalar x, int n)
0078 {
0079   using std::cosh;
0080   using std::sinh;
0081   Scalar res;
0082   
0083   switch (n % 2) {
0084   case 0:
0085     res = std::cosh(x);
0086     break;
0087   case 1:
0088     res = std::sinh(x);
0089     break;
0090   }
0091   return res;
0092 }
0093     
0094 /** \brief Hyperbolic sine (and its derivatives). */
0095 template <typename Scalar>
0096 Scalar stem_function_sinh(Scalar x, int n)
0097 {
0098   using std::cosh;
0099   using std::sinh;
0100   Scalar res;
0101   
0102   switch (n % 2) {
0103   case 0:
0104     res = std::sinh(x);
0105     break;
0106   case 1:
0107     res = std::cosh(x);
0108     break;
0109   }
0110   return res;
0111 }
0112 
0113 } // end namespace internal
0114 
0115 } // end namespace Eigen
0116 
0117 #endif // EIGEN_STEM_FUNCTION