Changeset 1288
- Timestamp:
- Apr 25, 2008, 12:07:57 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/utility_test.cc
r1275 r1288 27 27 28 28 #include "yat/utility/utility.h" 29 #include "yat/utility/stl_utility.h" 29 30 30 31 #include <fstream> … … 104 105 utility::convert<double>("NaN"); 105 106 107 { 108 utility::Log f; 109 utility::Log f2(1.3); 110 f(2.0); 111 utility::Exp e; 112 e(3.2); 113 } 114 106 115 return suite.return_value(); 107 116 } -
trunk/yat/utility/stl_utility.h
r1275 r1288 37 37 38 38 #include <algorithm> 39 #include <cmath> 39 40 #include <functional> 40 41 #include <ostream> … … 117 118 return compose_f_gx_hy<F,G,H>(f,g,h); 118 119 } 120 121 /** 122 Functor class to exponentiate values using std::exp 123 */ 124 template<typename T> 125 struct Exp : std::unary_function<T, T> 126 { 127 /** 128 \return absolute value 129 */ 130 inline T operator()(T x) const 131 { return std::exp(x); } 132 }; 133 134 /** 135 Functor class to take logarithm 136 */ 137 template<typename T> 138 class Log : std::unary_function<T, T> 139 { 140 public: 141 /** 142 Default constructor using natural base \f$ e \f$ 143 */ 144 Log(void) 145 : log_base_(1.0) {} 146 147 /** 148 \param base Taking logarithm in which base, e.g. 2 or 10. 149 */ 150 explicit Log(double base) : log_base_(std::log(base)) {} 151 152 /** 153 \return absolute value 154 */ 155 inline T operator()(T x) const 156 { return std::log(x)/log_base_; } 157 158 private: 159 double log_base_; 160 }; 119 161 120 162 /**
Note: See TracChangeset
for help on using the changeset viewer.