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

This commit is contained in:
Arash Partow 2014-06-01 13:03:29 +10:00
parent 1bf1073cd8
commit 4aa02953f8
2 changed files with 16 additions and 6 deletions

View File

@ -30,7 +30,7 @@ void savitzky_golay_filter()
typedef exprtk::expression<T> expression_t;
typedef exprtk::parser<T> parser_t;
std::string gsfilter_program =
std::string sgfilter_program =
" var weight[9] := "
" { "
" -21, 14, 39, "
@ -38,20 +38,27 @@ void savitzky_golay_filter()
" 39, 14, -21 "
" }; "
" "
" var lower_bound := trunc(weight[] / 2); "
" var upper_bound := v_in[] - lower_bound; "
" "
" if (v_in[] >= weight[]) "
" { "
" var lower_bound := trunc(weight[] / 2); "
" var upper_bound := v_in[] - lower_bound; "
" "
" for (i := lower_bound; i < upper_bound; i += 1) "
" { "
" v_out[i] := 0; "
" for (j := 0; j < weight[]; j += 1) "
" { "
" v_out[i] += weight[j] * v_in[i + j]; "
" var index := i + j - lower_bound; "
" v_out[i] += weight[j] * v_in[index]; "
" }; "
" v_out[i] /= 231; "
" }; "
" "
" for (i := 0; i < lower_bound; i += 1) "
" { "
" v_out[i] := 0; "
" v_out[v_out[] - i - 1] := 0; "
" }; "
" } ";
const std::size_t n = 1024;
@ -81,7 +88,7 @@ void savitzky_golay_filter()
parser_t parser;
parser.compile(gsfilter_program,expression);
parser.compile(sgfilter_program,expression);
expression.value();

View File

@ -261,6 +261,9 @@ of C++ compilers:
| | r0 < r1. If x is within the range it will snap to the |
| | closest bound. (eg: iclamp(r0,x,r1) |
+----------+---------------------------------------------------------+
| inrange | In-range returns 'true' when x is within the range r0 |
| | and r1. Where r0 < r1. (eg: inrange(r0,x,r1) |
+----------+---------------------------------------------------------+
| log | Natural logarithm of x. (eg: log(x)) |
+----------+---------------------------------------------------------+
| log10 | Base 10 logarithm of x. (eg: log10(x)) |