C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
56cb1186b7
commit
55759bb04c
9
Makefile
9
Makefile
|
@ -21,10 +21,11 @@ OPTIMIZATION_OPT := -O1
|
|||
BASE_OPTIONS := -pedantic-errors -Wall -Wextra -Werror -Wno-long-long
|
||||
OPTIONS := $(BASE_OPTIONS) $(OPTIMIZATION_OPT)
|
||||
LINKER_OPT := -L/usr/lib -lstdc++ -lm
|
||||
ASAN_OPT := -g -fsanitize=address -fno-omit-frame-pointer
|
||||
MSAN_OPT := -g -fsanitize=memory -fno-omit-frame-pointer
|
||||
LSAN_OPT := -g -fsanitize=leak -fno-omit-frame-pointer
|
||||
BUILD_SRC := $(wildcard exprtk_*.cpp)
|
||||
ASAN_OPT := -g -fsanitize=address -fno-omit-frame-pointer
|
||||
MSAN_OPT := -g -fsanitize=memory -fno-omit-frame-pointer
|
||||
LSAN_OPT := -g -fsanitize=leak -fno-omit-frame-pointer
|
||||
USAN_OPT := -g -fsanitize=undefined -fno-omit-frame-pointer
|
||||
BUILD_SRC := $(sort $(wildcard exprtk_*.cpp))
|
||||
BUILD_LIST := $(BUILD_SRC:%.cpp=%)
|
||||
|
||||
|
||||
|
|
18
exprtk.hpp
18
exprtk.hpp
|
@ -67,7 +67,7 @@ namespace exprtk
|
|||
#define exprtk_error_location \
|
||||
"exprtk.hpp:" + details::to_str(__LINE__) \
|
||||
|
||||
#if __GNUC__ >= 7
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
|
||||
#define exprtk_disable_fallthrough_begin \
|
||||
_Pragma ("GCC diagnostic push") \
|
||||
|
@ -1320,8 +1320,8 @@ namespace exprtk
|
|||
template <typename T> inline T frac_impl(const T v, real_type_tag) { return (v - static_cast<long long>(v)); }
|
||||
template <typename T> inline T trunc_impl(const T v, real_type_tag) { return T(static_cast<long long>(v)); }
|
||||
|
||||
template <typename T> inline T const_pi_impl(real_type_tag) { return numeric::constant::pi; }
|
||||
template <typename T> inline T const_e_impl (real_type_tag) { return numeric::constant::e; }
|
||||
template <typename T> inline T const_pi_impl(real_type_tag) { return T(numeric::constant::pi); }
|
||||
template <typename T> inline T const_e_impl (real_type_tag) { return T(numeric::constant::e); }
|
||||
|
||||
template <typename T> inline T abs_impl(const T v, int_type_tag) { return ((v >= T(0)) ? v : -v); }
|
||||
template <typename T> inline T exp_impl(const T v, int_type_tag) { return std::exp (v); }
|
||||
|
@ -2780,7 +2780,7 @@ namespace exprtk
|
|||
Note: The following 'awkward' conditional is
|
||||
due to various broken msvc compilers.
|
||||
*/
|
||||
#if _MSC_VER == 1600
|
||||
#if defined(_MSC_VER) && (_MSC_VER == 1600)
|
||||
const bool within_range = !is_end(s_itr_ + 2) &&
|
||||
!is_end(s_itr_ + 3) ;
|
||||
#else
|
||||
|
@ -3761,7 +3761,7 @@ namespace exprtk
|
|||
case lexer::token::e_sub : return false;
|
||||
case lexer::token::e_colon : return false;
|
||||
case lexer::token::e_ternary : return false;
|
||||
default : return true;
|
||||
default : return true ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3775,7 +3775,7 @@ namespace exprtk
|
|||
case lexer::token::e_eof : return false;
|
||||
case lexer::token::e_colon : return false;
|
||||
case lexer::token::e_ternary : return false;
|
||||
default : return true;
|
||||
default : return true ;
|
||||
}
|
||||
}
|
||||
else if (details::is_left_bracket(static_cast<char>(t)))
|
||||
|
@ -5963,10 +5963,8 @@ namespace exprtk
|
|||
else
|
||||
return ((T(2) * arg1 <= (arg2 + arg0)) ? arg0 : arg2);
|
||||
|
||||
default : {
|
||||
exprtk_debug(("trinary_node::value() - Error: Invalid operation\n"));
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
}
|
||||
default : exprtk_debug(("trinary_node::value() - Error: Invalid operation\n"));
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,22 +45,23 @@ void newton_sqrt()
|
|||
.add(
|
||||
function_t( // define function: newton_sqrt(x)
|
||||
"newton_sqrt",
|
||||
" switch "
|
||||
" { "
|
||||
" case x < 0 : -inf; "
|
||||
" case x == 0 : 0; "
|
||||
" case x == 1 : 1; "
|
||||
" default: "
|
||||
" ~{ "
|
||||
" var z := 100; "
|
||||
" var sqrt_x := x / 2; "
|
||||
" repeat "
|
||||
" sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); "
|
||||
" if (equal(sqrt_x^2, x)) "
|
||||
" break[sqrt_x]; "
|
||||
" until ((z -= 1) <= 0); "
|
||||
" }; "
|
||||
" } ",
|
||||
" switch "
|
||||
" { "
|
||||
" case x < 0 : null; "
|
||||
" case x == 0 : 0; "
|
||||
" case x == 1 : 1; "
|
||||
" default: "
|
||||
" ~{ "
|
||||
" var z := 100; "
|
||||
" var sqrt_x := x / 2; "
|
||||
" repeat "
|
||||
" if (equal(sqrt_x^2, x)) "
|
||||
" break[sqrt_x]; "
|
||||
" else "
|
||||
" sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); "
|
||||
" until ((z -= 1) <= 0); "
|
||||
" }; "
|
||||
" } ",
|
||||
"x"));
|
||||
|
||||
std::string expression_str = "newton_sqrt(x)";
|
||||
|
@ -77,7 +78,7 @@ void newton_sqrt()
|
|||
|
||||
T result = expression.value();
|
||||
|
||||
printf("sqrt(%03d) - Result: %12.10f\tReal: %12.10f\n",
|
||||
printf("sqrt(%03d) - Result: %15.13f\tReal: %15.13f\n",
|
||||
static_cast<unsigned int>(i),
|
||||
result,
|
||||
std::sqrt(x));
|
||||
|
|
Loading…
Reference in New Issue