History

libavutil/eval: Add round function to expression parser

We have floor, ceil, and trunc. Let's add round.

Kevin Mark committed 9 years ago

Commit 482566c1 parent 850cbd42 files · +7 −1Browse files

Unified · Split

2 files
  1. doc/utils.texi +3 −0
  2. libavutil/eval.c +4 −1
doc/utils.texi+3−0
@@ -914,6 +914,9 @@ various input values that the expression can access through · 913 unmodified lines
914914 @code{ld(0)}. When the expression evaluates to 0 then the
915915 corresponding input value will be returned.
916916
917+@item round(expr)
918+Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0".
919+
917920 @item sin(x)
918921 Compute sine of @var{x}.
919922
libavutil/eval.c+4−1
@@ -153,7 +153,7 @@ struct AVExpr { · 152 unmodified lines
153153 e_squish, e_gauss, e_ld, e_isnan, e_isinf,
154154 e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_lte, e_lt,
155155 e_pow, e_mul, e_div, e_add,
156− e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc,
156+ e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round,
157157 e_sqrt, e_not, e_random, e_hypot, e_gcd,
158158 e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2
159159 } type;
@@ -189,6 +189,7 @@ static double eval_expr(Parser *p, AVExpr *e) · 29 unmodified lines
189189 case e_floor: return e->value * floor(eval_expr(p, e->param[0]));
190190 case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));
191191 case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));
192+ case e_round: return e->value * round(eval_expr(p, e->param[0]));
192193 case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));
193194 case e_not: return e->value * (eval_expr(p, e->param[0]) == 0);
194195 case e_if: return e->value * (eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
@@ -440,6 +441,7 @@ static int parse_primary(AVExpr **e, Parser *p) · 245 unmodified lines
440441 else if (strmatch(next, "floor" )) d->type = e_floor;
441442 else if (strmatch(next, "ceil" )) d->type = e_ceil;
442443 else if (strmatch(next, "trunc" )) d->type = e_trunc;
444+ else if (strmatch(next, "round" )) d->type = e_round;
443445 else if (strmatch(next, "sqrt" )) d->type = e_sqrt;
444446 else if (strmatch(next, "not" )) d->type = e_not;
445447 else if (strmatch(next, "pow" )) d->type = e_pow;
@@ -637,6 +639,7 @@ static int verify_expr(AVExpr *e) · 191 unmodified lines
637639 case e_floor:
638640 case e_ceil:
639641 case e_trunc:
642+ case e_round:
640643 case e_sqrt:
641644 case e_not:
642645 case e_random:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t