We have floor, ceil, and trunc. Let's add round.
Unified · Split
| @@ -914,6 +914,9 @@ various input values that the expression can access through · 913 unmodified lines | ||
| 914 | 914 | @code{ld(0)}. When the expression evaluates to 0 then the |
| 915 | 915 | corresponding input value will be returned. |
| 916 | 916 | |
| 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 | + | |
| 917 | 920 | @item sin(x) |
| 918 | 921 | Compute sine of @var{x}. |
| 919 | 922 | |
| @@ -153,7 +153,7 @@ struct AVExpr { · 152 unmodified lines | ||
| 153 | 153 | e_squish, e_gauss, e_ld, e_isnan, e_isinf, |
| 154 | 154 | e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_lte, e_lt, |
| 155 | 155 | 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, | |
| 157 | 157 | e_sqrt, e_not, e_random, e_hypot, e_gcd, |
| 158 | 158 | e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2 |
| 159 | 159 | } type; |
| @@ -189,6 +189,7 @@ static double eval_expr(Parser *p, AVExpr *e) · 29 unmodified lines | ||
| 189 | 189 | case e_floor: return e->value * floor(eval_expr(p, e->param[0])); |
| 190 | 190 | case e_ceil : return e->value * ceil (eval_expr(p, e->param[0])); |
| 191 | 191 | 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])); | |
| 192 | 193 | case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0])); |
| 193 | 194 | case e_not: return e->value * (eval_expr(p, e->param[0]) == 0); |
| 194 | 195 | 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 | ||
| 440 | 441 | else if (strmatch(next, "floor" )) d->type = e_floor; |
| 441 | 442 | else if (strmatch(next, "ceil" )) d->type = e_ceil; |
| 442 | 443 | else if (strmatch(next, "trunc" )) d->type = e_trunc; |
| 444 | + else if (strmatch(next, "round" )) d->type = e_round; | |
| 443 | 445 | else if (strmatch(next, "sqrt" )) d->type = e_sqrt; |
| 444 | 446 | else if (strmatch(next, "not" )) d->type = e_not; |
| 445 | 447 | else if (strmatch(next, "pow" )) d->type = e_pow; |
| @@ -637,6 +639,7 @@ static int verify_expr(AVExpr *e) · 191 unmodified lines | ||
| 637 | 639 | case e_floor: |
| 638 | 640 | case e_ceil: |
| 639 | 641 | case e_trunc: |
| 642 | + case e_round: | |
| 640 | 643 | case e_sqrt: |
| 641 | 644 | case e_not: |
| 642 | 645 | case e_random: |