![]() |
Eigen-unsupported
3.3.3
|
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2010, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk> 00005 // 00006 // This Source Code Form is subject to the terms of the Mozilla 00007 // Public License v. 2.0. If a copy of the MPL was not distributed 00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00009 00010 #ifndef EIGEN_STEM_FUNCTION 00011 #define EIGEN_STEM_FUNCTION 00012 00013 namespace Eigen { 00014 00015 namespace internal { 00016 00018 template <typename Scalar> 00019 Scalar stem_function_exp(Scalar x, int) 00020 { 00021 using std::exp; 00022 return exp(x); 00023 } 00024 00026 template <typename Scalar> 00027 Scalar stem_function_cos(Scalar x, int n) 00028 { 00029 using std::cos; 00030 using std::sin; 00031 Scalar res; 00032 00033 switch (n % 4) { 00034 case 0: 00035 res = std::cos(x); 00036 break; 00037 case 1: 00038 res = -std::sin(x); 00039 break; 00040 case 2: 00041 res = -std::cos(x); 00042 break; 00043 case 3: 00044 res = std::sin(x); 00045 break; 00046 } 00047 return res; 00048 } 00049 00051 template <typename Scalar> 00052 Scalar stem_function_sin(Scalar x, int n) 00053 { 00054 using std::cos; 00055 using std::sin; 00056 Scalar res; 00057 00058 switch (n % 4) { 00059 case 0: 00060 res = std::sin(x); 00061 break; 00062 case 1: 00063 res = std::cos(x); 00064 break; 00065 case 2: 00066 res = -std::sin(x); 00067 break; 00068 case 3: 00069 res = -std::cos(x); 00070 break; 00071 } 00072 return res; 00073 } 00074 00076 template <typename Scalar> 00077 Scalar stem_function_cosh(Scalar x, int n) 00078 { 00079 using std::cosh; 00080 using std::sinh; 00081 Scalar res; 00082 00083 switch (n % 2) { 00084 case 0: 00085 res = std::cosh(x); 00086 break; 00087 case 1: 00088 res = std::sinh(x); 00089 break; 00090 } 00091 return res; 00092 } 00093 00095 template <typename Scalar> 00096 Scalar stem_function_sinh(Scalar x, int n) 00097 { 00098 using std::cosh; 00099 using std::sinh; 00100 Scalar res; 00101 00102 switch (n % 2) { 00103 case 0: 00104 res = std::sinh(x); 00105 break; 00106 case 1: 00107 res = std::cosh(x); 00108 break; 00109 } 00110 return res; 00111 } 00112 00113 } // end namespace internal 00114 00115 } // end namespace Eigen 00116 00117 #endif // EIGEN_STEM_FUNCTION