C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
56cb1186b7
commit
55759bb04c
3
Makefile
3
Makefile
|
@ -24,7 +24,8 @@ 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)
|
||||
USAN_OPT := -g -fsanitize=undefined -fno-omit-frame-pointer
|
||||
BUILD_SRC := $(sort $(wildcard exprtk_*.cpp))
|
||||
BUILD_LIST := $(BUILD_SRC:%.cpp=%)
|
||||
|
||||
|
||||
|
|
12
exprtk.hpp
12
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
|
||||
|
@ -5963,12 +5963,10 @@ namespace exprtk
|
|||
else
|
||||
return ((T(2) * arg1 <= (arg2 + arg0)) ? arg0 : arg2);
|
||||
|
||||
default : {
|
||||
exprtk_debug(("trinary_node::value() - Error: Invalid operation\n"));
|
||||
default : exprtk_debug(("trinary_node::value() - Error: Invalid operation\n"));
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline typename expression_node<T>::node_type type() const
|
||||
{
|
||||
|
|
|
@ -47,7 +47,7 @@ void newton_sqrt()
|
|||
"newton_sqrt",
|
||||
" switch "
|
||||
" { "
|
||||
" case x < 0 : -inf; "
|
||||
" case x < 0 : null; "
|
||||
" case x == 0 : 0; "
|
||||
" case x == 1 : 1; "
|
||||
" default: "
|
||||
|
@ -55,9 +55,10 @@ void newton_sqrt()
|
|||
" 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]; "
|
||||
" else "
|
||||
" sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); "
|
||||
" until ((z -= 1) <= 0); "
|
||||
" }; "
|
||||
" } ",
|
||||
|
@ -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