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:
@ -3193,6 +3193,8 @@ inline bool run_test08()
|
||||
template <typename T>
|
||||
struct myfunc : public exprtk::ifunction<T>
|
||||
{
|
||||
using exprtk::ifunction<T>::operator();
|
||||
|
||||
myfunc() : exprtk::ifunction<T>(2) {}
|
||||
|
||||
inline T operator()(const T& v1, const T& v2)
|
||||
@ -4272,7 +4274,9 @@ inline bool run_test10()
|
||||
"7 == (for (var i := 0; i < 10; i += 1) { ~{break[7]; continue; i += i} })",
|
||||
"0 == (for (var i := 0; i < 10; i += 1) { ~{break[i]; continue; i += i} })",
|
||||
"0 == (for (var i := 0; i < 10; i += 1) { ~{continue; break[7]; i += i} })",
|
||||
"1 == (for (var i := 0; i < 10; i += 1) { ~{break[i += 1]; continue; i += i} })"
|
||||
"1 == (for (var i := 0; i < 10; i += 1) { ~{break[i += 1]; continue; i += i} })",
|
||||
|
||||
"var x[10^6] := null; var y[10^7] := null; 0 * (min(x) + min(y)) + x[] + y[] == 10^7 + 10^6"
|
||||
};
|
||||
|
||||
const std::size_t expression_list_size = sizeof(expression_list) / sizeof(std::string);
|
||||
@ -4286,6 +4290,7 @@ inline bool run_test10()
|
||||
|
||||
symbol_table.add_variable("zero",zero);
|
||||
symbol_table.add_variable("one" , one);
|
||||
symbol_table.add_pi();
|
||||
|
||||
bool failed = false;
|
||||
|
||||
@ -4548,6 +4553,8 @@ inline bool run_test12()
|
||||
template <typename T>
|
||||
struct sine_deg : public exprtk::ifunction<T>
|
||||
{
|
||||
using exprtk::ifunction<T>::operator();
|
||||
|
||||
sine_deg() : exprtk::ifunction<T>(1) {}
|
||||
|
||||
inline T operator()(const T& v)
|
||||
@ -4559,6 +4566,8 @@ struct sine_deg : public exprtk::ifunction<T>
|
||||
template <typename T>
|
||||
struct cosine_deg : public exprtk::ifunction<T>
|
||||
{
|
||||
using exprtk::ifunction<T>::operator();
|
||||
|
||||
cosine_deg() : exprtk::ifunction<T>(1) {}
|
||||
|
||||
inline T operator()(const T& v)
|
||||
@ -4945,6 +4954,8 @@ inline bool run_test15()
|
||||
template <typename T>
|
||||
struct base_func : public exprtk::ifunction<T>
|
||||
{
|
||||
using exprtk::ifunction<T>::operator();
|
||||
|
||||
typedef const T& type;
|
||||
base_func(const std::size_t& n) : exprtk::ifunction<T>(n) {}
|
||||
inline T operator()(type v0, type v1, type v2, type v3, type v4) { return (v0 + v1 + v2 + v3 + v4); }
|
||||
@ -5251,6 +5262,8 @@ struct gen_func : public exprtk::igeneric_function<T>
|
||||
typedef typename generic_type::vector_view vector_t;
|
||||
typedef typename generic_type::string_view string_t;
|
||||
|
||||
using exprtk::igeneric_function<T>::operator();
|
||||
|
||||
gen_func()
|
||||
: scalar_count(0),
|
||||
vector_count(0),
|
||||
@ -5301,10 +5314,12 @@ struct gen_func2 : public exprtk::igeneric_function<T>
|
||||
{
|
||||
typedef typename exprtk::igeneric_function<T>::parameter_list_t parameter_list_t;
|
||||
|
||||
using exprtk::igeneric_function<T>::operator();
|
||||
|
||||
gen_func2()
|
||||
{}
|
||||
|
||||
inline T operator()(parameter_list_t&)
|
||||
inline T operator()(parameter_list_t)
|
||||
{
|
||||
return T(0);
|
||||
}
|
||||
@ -5325,6 +5340,8 @@ struct inc_func : public exprtk::igeneric_function<T>
|
||||
typedef typename generic_type::vector_view vector_t;
|
||||
typedef typename generic_type::string_view string_t;
|
||||
|
||||
using exprtk::igeneric_function<T>::operator();
|
||||
|
||||
inc_func()
|
||||
{}
|
||||
|
||||
@ -5383,6 +5400,8 @@ struct rem_space_and_uppercase : public exprtk::igeneric_function<T>
|
||||
typedef typename igenfunc_t::parameter_list_t parameter_list_t;
|
||||
typedef typename generic_type::string_view string_t;
|
||||
|
||||
using exprtk::igeneric_function<T>::operator();
|
||||
|
||||
rem_space_and_uppercase()
|
||||
: igenfunc_t("S",igenfunc_t::e_rtrn_string)
|
||||
{}
|
||||
@ -5426,6 +5445,8 @@ struct vararg_func : public exprtk::igeneric_function<T>
|
||||
typedef typename generic_type::scalar_view scalar_t;
|
||||
typedef typename generic_type::vector_view vector_t;
|
||||
|
||||
using exprtk::igeneric_function<T>::operator();
|
||||
|
||||
vararg_func()
|
||||
: exprtk::igeneric_function<T>("Z|T*|V")
|
||||
{}
|
||||
@ -7022,6 +7043,47 @@ inline bool run_test19()
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
symbol_table_t symbol_table;
|
||||
|
||||
symbol_table.add_constants();
|
||||
|
||||
std::string expression_str[] =
|
||||
{
|
||||
"var delta := 10^-7; var total := 0; for (var i := 0; i <= 3; i += delta) { total += "
|
||||
"erf(i) }; abs((delta * total) - (3 * erf(3) + (1 / exp(9) - 1) / sqrt(pi))) < 0.000001",
|
||||
|
||||
"var delta := 10^-7; var total := 0; for (var i := 0; i <= 3; i += delta) { total += "
|
||||
"erfc(i) }; abs((delta * total) - (3 * erfc(3) + ((1 - 1 / exp(9)) / sqrt(pi)))) < 0.000001"
|
||||
};
|
||||
|
||||
expression_t e[2];
|
||||
|
||||
parser_t parser;
|
||||
|
||||
for (std::size_t i = 0; i < 2; ++i)
|
||||
{
|
||||
e[i].register_symbol_table(symbol_table);
|
||||
|
||||
if (!parser.compile(expression_str[i],e[i]))
|
||||
{
|
||||
printf("run_test19() - Error: %s Expression: %s\n",
|
||||
parser.error().c_str(),
|
||||
expression_str[i].c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (T(1) != e[i].value())
|
||||
{
|
||||
printf("run_test19() - erf/erfc computation error %d",
|
||||
static_cast<unsigned int>(i));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user