Skip to content

Commit

Permalink
C++ Mathematical Expression Library (ExprTk) http://www.partow.net/pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
ArashPartow committed Jan 21, 2016
1 parent c97139e commit bc53259
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
89 changes: 52 additions & 37 deletions exprtk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down Expand Up @@ -405,14 +405,14 @@ 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);

static const std::string arithmetic_ops_list[] =
{
"+", "-", "*", "/", "%", "^"
"+", "-", "*", "/", "%", "^"
};

static const std::size_t arithmetic_ops_list_size = sizeof(arithmetic_ops_list) / sizeof(std::string);
Expand Down Expand Up @@ -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]))
{
Expand Down Expand Up @@ -2401,9 +2401,10 @@ namespace exprtk
8. 123.456E-3
*/
const char* initial_itr = s_itr_;
bool dot_found = false;
bool e_found = false;
bool post_e_sign_found = false;
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_))
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]);
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand All @@ -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))
{
Expand All @@ -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))
{
Expand All @@ -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))
{
Expand All @@ -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())
{
Expand All @@ -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())
{
Expand All @@ -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())
{
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion exprtk_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_03.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_05.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_06.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: *
Expand Down
Loading

0 comments on commit bc53259

Please sign in to comment.