|
|
@ -121,7 +121,7 @@ struct AVExpr { |
|
|
|
e_squish, e_gauss, e_ld, e_isnan, |
|
|
|
e_squish, e_gauss, e_ld, e_isnan, |
|
|
|
e_mod, e_max, e_min, e_eq, e_gt, e_gte, |
|
|
|
e_mod, e_max, e_min, e_eq, e_gt, e_gte, |
|
|
|
e_pow, e_mul, e_div, e_add, |
|
|
|
e_pow, e_mul, e_div, e_add, |
|
|
|
e_last, e_st, e_while, |
|
|
|
e_last, e_st, e_while, e_floor, e_ceil, e_trunc, |
|
|
|
} type; |
|
|
|
} type; |
|
|
|
double value; // is sign in other types
|
|
|
|
double value; // is sign in other types
|
|
|
|
union { |
|
|
|
union { |
|
|
@ -145,6 +145,9 @@ static double eval_expr(Parser *p, AVExpr *e) |
|
|
|
case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); } |
|
|
|
case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); } |
|
|
|
case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)]; |
|
|
|
case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)]; |
|
|
|
case e_isnan: return e->value * !!isnan(eval_expr(p, e->param[0])); |
|
|
|
case e_isnan: return e->value * !!isnan(eval_expr(p, e->param[0])); |
|
|
|
|
|
|
|
case e_floor: return e->value * floor(eval_expr(p, e->param[0])); |
|
|
|
|
|
|
|
case e_ceil : return e->value * ceil (eval_expr(p, e->param[0])); |
|
|
|
|
|
|
|
case e_trunc: return e->value * trunc(eval_expr(p, e->param[0])); |
|
|
|
case e_while: { |
|
|
|
case e_while: { |
|
|
|
double d = NAN; |
|
|
|
double d = NAN; |
|
|
|
while (eval_expr(p, e->param[0])) |
|
|
|
while (eval_expr(p, e->param[0])) |
|
|
@ -276,6 +279,9 @@ static int parse_primary(AVExpr **e, Parser *p) |
|
|
|
else if (strmatch(next, "isnan" )) d->type = e_isnan; |
|
|
|
else if (strmatch(next, "isnan" )) d->type = e_isnan; |
|
|
|
else if (strmatch(next, "st" )) d->type = e_st; |
|
|
|
else if (strmatch(next, "st" )) d->type = e_st; |
|
|
|
else if (strmatch(next, "while" )) d->type = e_while; |
|
|
|
else if (strmatch(next, "while" )) d->type = e_while; |
|
|
|
|
|
|
|
else if (strmatch(next, "floor" )) d->type = e_floor; |
|
|
|
|
|
|
|
else if (strmatch(next, "ceil" )) d->type = e_ceil; |
|
|
|
|
|
|
|
else if (strmatch(next, "trunc" )) d->type = e_trunc; |
|
|
|
else { |
|
|
|
else { |
|
|
|
for (i=0; p->func1_names && p->func1_names[i]; i++) { |
|
|
|
for (i=0; p->func1_names && p->func1_names[i]; i++) { |
|
|
|
if (strmatch(next, p->func1_names[i])) { |
|
|
|
if (strmatch(next, p->func1_names[i])) { |
|
|
@ -439,7 +445,11 @@ static int verify_expr(AVExpr *e) |
|
|
|
case e_squish: |
|
|
|
case e_squish: |
|
|
|
case e_ld: |
|
|
|
case e_ld: |
|
|
|
case e_gauss: |
|
|
|
case e_gauss: |
|
|
|
case e_isnan: return verify_expr(e->param[0]); |
|
|
|
case e_isnan: |
|
|
|
|
|
|
|
case e_floor: |
|
|
|
|
|
|
|
case e_ceil: |
|
|
|
|
|
|
|
case e_trunc: |
|
|
|
|
|
|
|
return verify_expr(e->param[0]); |
|
|
|
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); |
|
|
|
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -611,6 +621,13 @@ int main(void) |
|
|
|
"st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))", |
|
|
|
"st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))", |
|
|
|
"isnan(1)", |
|
|
|
"isnan(1)", |
|
|
|
"isnan(NAN)", |
|
|
|
"isnan(NAN)", |
|
|
|
|
|
|
|
"floor(NAN)", |
|
|
|
|
|
|
|
"floor(123.123)", |
|
|
|
|
|
|
|
"floor(-123.123)", |
|
|
|
|
|
|
|
"trunc(123.123)", |
|
|
|
|
|
|
|
"trunc(-123.123)", |
|
|
|
|
|
|
|
"ceil(123.123)", |
|
|
|
|
|
|
|
"ceil(-123.123)", |
|
|
|
NULL |
|
|
|
NULL |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|