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

This commit is contained in:
Arash Partow 2016-01-21 19:15:46 +11:00
parent c97139ed60
commit bc532593ba
21 changed files with 80 additions and 57 deletions

View File

@ -2,7 +2,7 @@
# **************************************************************
# * C++ Mathematical Expression Toolkit Library *
# * *
# * Author: Arash Partow (1999-2015) *
# * Author: Arash Partow (1999-2016) *
# * URL: http://www.partow.net/programming/exprtk/index.html *
# * *
# * Copyright notice: *

View File

@ -2,7 +2,7 @@
******************************************************************
* C++ Mathematical Expression Toolkit Library *
* *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *
@ -405,7 +405,7 @@ namespace exprtk
static const std::string cntrl_struct_list[] =
{
"for", "if", "repeat", "switch", "while"
"if", "switch", "for", "while", "repeat"
};
static const std::size_t cntrl_struct_list_size = sizeof(cntrl_struct_list) / sizeof(std::string);
@ -488,7 +488,7 @@ namespace exprtk
inline bool is_logic_opr(const std::string& lgc_opr)
{
for (std::size_t i = 0; i < cntrl_struct_list_size; ++i)
for (std::size_t i = 0; i < logic_ops_list_size; ++i)
{
if (imatch(lgc_opr,logic_ops_list[i]))
{
@ -2404,6 +2404,7 @@ namespace exprtk
bool dot_found = false;
bool e_found = false;
bool post_e_sign_found = false;
bool post_e_digit_found = false;
token_t t;
while (!is_end(s_itr_))
@ -2450,7 +2451,7 @@ namespace exprtk
continue;
}
else if (e_found && details::is_sign(*s_itr_))
else if (e_found && details::is_sign(*s_itr_) && !post_e_digit_found)
{
if (post_e_sign_found)
{
@ -2465,6 +2466,13 @@ namespace exprtk
continue;
}
else if (e_found && details::is_digit(*s_itr_))
{
post_e_digit_found = true;
++s_itr_;
continue;
}
else if (('.' != (*s_itr_)) && !details::is_digit(*s_itr_))
break;
else
@ -17708,7 +17716,7 @@ namespace exprtk
{
if (
(e_bf_unknown != bf) &&
(static_cast<std::size_t>(bf) < details::base_function_list_size)
(static_cast<std::size_t>(bf) < (details::base_function_list_size + 1))
)
{
disabled_func_set_.insert(details::base_function_list[bf - 1]);
@ -17721,7 +17729,7 @@ namespace exprtk
{
if (
(e_ctrl_unknown != ctrl_struct) &&
(static_cast<std::size_t>(ctrl_struct) < details::cntrl_struct_list_size)
(static_cast<std::size_t>(ctrl_struct) < (details::cntrl_struct_list_size + 1))
)
{
disabled_ctrl_set_.insert(details::cntrl_struct_list[ctrl_struct - 1]);
@ -17734,7 +17742,7 @@ namespace exprtk
{
if (
(e_logic_unknown != logic) &&
(static_cast<std::size_t>(logic) < details::logic_ops_list_size)
(static_cast<std::size_t>(logic) < (details::logic_ops_list_size + 1))
)
{
disabled_logic_set_.insert(details::logic_ops_list[logic - 1]);
@ -17747,7 +17755,7 @@ namespace exprtk
{
if (
(e_arith_unknown != arithmetic) &&
(static_cast<std::size_t>(arithmetic) < details::arithmetic_ops_list_size)
(static_cast<std::size_t>(arithmetic) < (details::arithmetic_ops_list_size + 1))
)
{
disabled_arithmetic_set_.insert(details::arithmetic_ops_list[arithmetic - 1]);
@ -17760,7 +17768,7 @@ namespace exprtk
{
if (
(e_assign_unknown != assignment) &&
(static_cast<std::size_t>(assignment) < details::assignment_ops_list_size)
(static_cast<std::size_t>(assignment) < (details::assignment_ops_list_size + 1))
)
{
disabled_assignment_set_.insert(details::assignment_ops_list[assignment - 1]);
@ -17773,7 +17781,7 @@ namespace exprtk
{
if (
(e_ineq_unknown != inequality) &&
(static_cast<std::size_t>(inequality) < details::inequality_ops_list_size)
(static_cast<std::size_t>(inequality) < (details::inequality_ops_list_size + 1))
)
{
disabled_inequality_set_.insert(details::inequality_ops_list[inequality - 1]);
@ -17786,7 +17794,7 @@ namespace exprtk
{
if (
(e_bf_unknown != bf) &&
(static_cast<std::size_t>(bf) < details::base_function_list_size)
(static_cast<std::size_t>(bf) < (details::base_function_list_size + 1))
)
{
des_itr_t itr = disabled_func_set_.find(details::base_function_list[bf - 1]);
@ -17804,7 +17812,7 @@ namespace exprtk
{
if (
(e_ctrl_unknown != ctrl_struct) &&
(static_cast<std::size_t>(ctrl_struct) < details::cntrl_struct_list_size)
(static_cast<std::size_t>(ctrl_struct) < (details::cntrl_struct_list_size + 1))
)
{
des_itr_t itr = disabled_ctrl_set_.find(details::cntrl_struct_list[ctrl_struct - 1]);
@ -17822,7 +17830,7 @@ namespace exprtk
{
if (
(e_logic_unknown != logic) &&
(static_cast<std::size_t>(logic) < details::logic_ops_list_size)
(static_cast<std::size_t>(logic) < (details::logic_ops_list_size + 1))
)
{
des_itr_t itr = disabled_logic_set_.find(details::logic_ops_list[logic - 1]);
@ -17840,7 +17848,7 @@ namespace exprtk
{
if (
(e_arith_unknown != arithmetic) &&
(static_cast<std::size_t>(arithmetic) < details::arithmetic_ops_list_size)
(static_cast<std::size_t>(arithmetic) < (details::arithmetic_ops_list_size + 1))
)
{
des_itr_t itr = disabled_arithmetic_set_.find(details::arithmetic_ops_list[arithmetic - 1]);
@ -17858,7 +17866,7 @@ namespace exprtk
{
if (
(e_assign_unknown != assignment) &&
(static_cast<std::size_t>(assignment) < details::assignment_ops_list_size)
(static_cast<std::size_t>(assignment) < (details::assignment_ops_list_size + 1))
)
{
des_itr_t itr = disabled_assignment_set_.find(details::assignment_ops_list[assignment - 1]);
@ -17876,7 +17884,7 @@ namespace exprtk
{
if (
(e_ineq_unknown != inequality) &&
(static_cast<std::size_t>(inequality) < details::inequality_ops_list_size)
(static_cast<std::size_t>(inequality) < (details::inequality_ops_list_size + 1))
)
{
des_itr_t itr = disabled_inequality_set_.find(details::inequality_ops_list[inequality - 1]);
@ -19018,6 +19026,10 @@ namespace exprtk
template <std::size_t NumberofParameters>
inline expression_node_ptr parse_function_call(ifunction<T>* function, const std::string& function_name)
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127)
#endif
if (0 == NumberofParameters)
{
set_error(
@ -19027,6 +19039,9 @@ namespace exprtk
return error_node();
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
expression_node_ptr branch[NumberofParameters];
expression_node_ptr result = error_node();
@ -21904,7 +21919,7 @@ namespace exprtk
return error_node();
}
else if ((scope_element::e_string == se.type))
else if (scope_element::e_string == se.type)
{
str_node = se.str_node;
se.active = true;
@ -22090,7 +22105,7 @@ namespace exprtk
return error_node();
}
else if ((scope_element::e_variable == se.type))
else if (scope_element::e_variable == se.type)
{
var_node = se.var_node;
se.active = true;
@ -32019,7 +32034,7 @@ namespace exprtk
};
template <typename T>
inline T integrate(expression<T>& e,
inline T integrate(const expression<T>& e,
T& x,
const T& r0, const T& r1,
const std::size_t number_of_intervals = 1000000)
@ -32043,12 +32058,12 @@ namespace exprtk
}
template <typename T>
inline T integrate(expression<T>& e,
inline T integrate(const expression<T>& e,
const std::string& variable_name,
const T& r0, const T& r1,
const std::size_t number_of_intervals = 1000000)
{
symbol_table<T>& sym_table = e.get_symbol_table();
const symbol_table<T>& sym_table = e.get_symbol_table();
if (!sym_table.valid())
return std::numeric_limits<T>::quiet_NaN();
@ -32069,7 +32084,7 @@ namespace exprtk
}
template <typename T>
inline T derivative(expression<T>& e,
inline T derivative(const expression<T>& e,
T& x,
const T& h = T(0.00000001))
{
@ -32088,7 +32103,7 @@ namespace exprtk
}
template <typename T>
inline T second_derivative(expression<T>& e,
inline T second_derivative(const expression<T>& e,
T& x,
const T& h = T(0.00001))
{
@ -32108,7 +32123,7 @@ namespace exprtk
}
template <typename T>
inline T third_derivative(expression<T>& e,
inline T third_derivative(const expression<T>& e,
T& x,
const T& h = T(0.0001))
{
@ -32127,11 +32142,11 @@ namespace exprtk
}
template <typename T>
inline T derivative(expression<T>& e,
inline T derivative(const expression<T>& e,
const std::string& variable_name,
const T& h = T(0.00000001))
{
symbol_table<T>& sym_table = e.get_symbol_table();
const symbol_table<T>& sym_table = e.get_symbol_table();
if (!sym_table.valid())
{
@ -32154,11 +32169,11 @@ namespace exprtk
}
template <typename T>
inline T second_derivative(expression<T>& e,
inline T second_derivative(const expression<T>& e,
const std::string& variable_name,
const T& h = T(0.00001))
{
symbol_table<T>& sym_table = e.get_symbol_table();
const symbol_table<T>& sym_table = e.get_symbol_table();
if (!sym_table.valid())
{
@ -32181,11 +32196,11 @@ namespace exprtk
}
template <typename T>
inline T third_derivative(expression<T>& e,
inline T third_derivative(const expression<T>& e,
const std::string& variable_name,
const T& h = T(0.0001))
{
symbol_table<T>& sym_table = e.get_symbol_table();
const symbol_table<T>& sym_table = e.get_symbol_table();
if (!sym_table.valid())
{
@ -33706,9 +33721,9 @@ namespace exprtk
namespace information
{
static const char* library = "Mathematical Expression Toolkit";
static const char* version = "2.7182818284590452353602874713526"
"624977572470936999595749669676277";
static const char* date = "20150731";
static const char* version = "2.71828182845904523536028747135266"
"2497757247093699959574966967627724";
static const char* date = "20160113";
static inline std::string data()
{

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* ExprTk vs Native Benchmarks *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 1 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 2 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 3 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 4 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 5 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 6 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 7 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 8 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 9 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 10 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 11 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 12 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 13 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 14 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 15 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 16 *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Examples and Unit-Tests *
* Author: Arash Partow (1999-2015) *
* Author: Arash Partow (1999-2016) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *
@ -301,6 +301,14 @@ static const test_t global_test_list[] =
test_t("( 7 + 2 )",9.0),
test_t("( 8 + 1 )",9.0),
test_t("( 9 + 0 )",9.0),
test_t("1E1+1",11.0),
test_t("1e1+1",11.0),
test_t("1E1-1", 9.0),
test_t("1e1-1", 9.0),
test_t("1E01+1",11.0),
test_t("1e01+1",11.0),
test_t("1E01-1", 9.0),
test_t("1e01-1", 9.0),
test_t("1+2",+3.0),
test_t("1-2",-1.0),
test_t("1*2",+2.0),

View File

@ -1886,7 +1886,7 @@ will not contain symbols denoting functions.
[17 - ENABLING AND DISABLING FEATURES]
The parser can be configured via its settings instance to either allow
or disallow certain features that are available within the ExprTk
grammar. The features fall into one of the following three categories:
grammar. The features fall into one of the following six categories:
(1) Base Functions
(2) Control Flow Structures