mirror of
https://github.com/ArashPartow/exprtk.git
synced 2025-06-12 16:27:23 +00:00
C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
43
exprtk.hpp
43
exprtk.hpp
@ -21334,6 +21334,7 @@ namespace exprtk
|
||||
if (result)
|
||||
{
|
||||
brkcnt_list_.push_front(false);
|
||||
|
||||
if (0 == (loop_body = parse_multi_sequence("for-loop")))
|
||||
{
|
||||
set_error(
|
||||
@ -36256,6 +36257,45 @@ namespace exprtk
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class nthelement : public exprtk::igeneric_function<T>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename exprtk::igeneric_function<T> igfun_t;
|
||||
typedef typename igfun_t::parameter_list_t parameter_list_t;
|
||||
typedef typename igfun_t::generic_type generic_type;
|
||||
typedef typename generic_type::scalar_view scalar_t;
|
||||
typedef typename generic_type::vector_view vector_t;
|
||||
|
||||
using exprtk::igeneric_function<T>::operator();
|
||||
|
||||
nthelement()
|
||||
: exprtk::igeneric_function<T>("VT|VTTT")
|
||||
{}
|
||||
|
||||
inline T operator()(const std::size_t& ps_index, parameter_list_t parameters)
|
||||
{
|
||||
vector_t vec(parameters[0]);
|
||||
|
||||
std::size_t n = 0;
|
||||
std::size_t r0 = 0;
|
||||
std::size_t r1 = vec.size() - 1;
|
||||
|
||||
if (!scalar_t(parameters[1]).to_uint(n))
|
||||
return T(0);
|
||||
|
||||
if ((1 == ps_index) && !details::load_vector_range<T>::process(parameters,r0,r1,2,3))
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
else if (details::invalid_range(vec,r0,r1))
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
|
||||
std::nth_element(vec.begin() + r0, vec.begin() + r0 + n , vec.begin() + r1 + 1);
|
||||
|
||||
return T(1);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class sumk : public exprtk::igeneric_function<T>
|
||||
{
|
||||
@ -36666,6 +36706,7 @@ namespace exprtk
|
||||
shift_left <T> sl;
|
||||
shift_right<T> sr;
|
||||
sort <T> st;
|
||||
nthelement <T> ne;
|
||||
sumk <T> sk;
|
||||
axpy <T> b1_axpy;
|
||||
axpby <T> b1_axpby;
|
||||
@ -36703,6 +36744,8 @@ namespace exprtk
|
||||
return false;
|
||||
else if (!symtab.add_function("sort" ,st))
|
||||
return false;
|
||||
else if (!symtab.add_function("nth_element" ,ne))
|
||||
return false;
|
||||
else if (!symtab.add_function("sumk" ,sk))
|
||||
return false;
|
||||
else if (!symtab.add_function("axpy" ,b1_axpy))
|
||||
|
Reference in New Issue
Block a user