C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html

This commit is contained in:
Arash Partow 2013-10-25 08:02:51 +11:00
parent 58c2b0805e
commit 8bad05fa8c
3 changed files with 11 additions and 15 deletions

View File

@ -248,11 +248,6 @@ namespace exprtk
return data_; return data_;
} }
inline operator const char* () const
{
return data_.data();
}
private: private:
std::string data_; std::string data_;
@ -417,6 +412,8 @@ namespace exprtk
10000000000000000.0, 10000000000000000.0,
}; };
static const std::size_t pow10_size = sizeof(pow10) / sizeof(double);
namespace numeric namespace numeric
{ {
namespace constant namespace constant
@ -607,14 +604,13 @@ namespace exprtk
return ((v < T(0)) ? std::ceil(v - T(0.5)) : std::floor(v + T(0.5))); return ((v < T(0)) ? std::ceil(v - T(0.5)) : std::floor(v + T(0.5)));
} }
template <typename T> template <typename T>
inline T roundn_impl(const T v0, const T v1, real_type_tag) inline T roundn_impl(const T v0, const T v1, real_type_tag)
{ {
// 0 <= index <= sizeof(pow10) const int index = std::max<int>(0, std::min<int>(pow10_size - 1, (int)std::floor(v1)));
const int index = std::max<int>(0,std::min<int>(sizeof(pow10),(int)std::floor(v1))); const T p10 = T(pow10[index]);
const T p10 = pow10[index]; return T(std::floor((v0 * p10) + T(0.5)) / p10);
return T(std::floor((v0 * p10) + T(0.5)) / p10); }
}
template <typename T> template <typename T>
inline T roundn_impl(const T v0, const T, int_type_tag) inline T roundn_impl(const T v0, const T, int_type_tag)

View File

@ -249,7 +249,7 @@ struct native
static inline T func13(Type x, Type y) static inline T func13(Type x, Type y)
{ {
return (x + (std::cos(y - std::sin(2 / x * pi)) - std::sin(x - std::cos(2 * y / pi))) - y); return (x + (std::cos(y - std::sin(T(2) / x * pi)) - std::sin(x - std::cos(T(2) * y / pi))) - y);
} }
static inline T func14(Type x, Type y) static inline T func14(Type x, Type y)

View File

@ -481,7 +481,7 @@ correctly optimize such expressions for a given architecture.
$f41(x,y,z) | x * log10(y)-z $f88(x,y,z,w) | x*y^7 + z*w^7 $f41(x,y,z) | x * log10(y)-z $f88(x,y,z,w) | x*y^7 + z*w^7
$f42(x,y,z) | x * sin(y)+z $f89(x,y,z,w) | x*y^8 + z*w^8 $f42(x,y,z) | x * sin(y)+z $f89(x,y,z,w) | x*y^8 + z*w^8
$f43(x,y,z) | x * sin(y)-z $f90(x,y,z,w) | x*y^9 + z*w^9 $f43(x,y,z) | x * sin(y)-z $f90(x,y,z,w) | x*y^9 + z*w^9
$f44(x,y,z) | x * cos(y)+z $f91(x,y,z,w) | (x and y) ? z $f44(x,y,z) | x * cos(y)+z $f91(x,y,z,w) | (x and y) ? z : w
$f45(x,y,z) | x * cos(y)-z $f92(x,y,z,w) | (x or y) ? z : w $f45(x,y,z) | x * cos(y)-z $f92(x,y,z,w) | (x or y) ? z : w
$f46(x,y,z) | x ? y : z $f93(x,y,z,w) | (x < y) ? z : w $f46(x,y,z) | x ? y : z $f93(x,y,z,w) | (x < y) ? z : w
$f94(x,y,z,w) | (x <= y) ? z : w $f94(x,y,z,w) | (x <= y) ? z : w