diff mbox

[FFmpeg-devel] avutil/eval: add sgn()

Message ID 20191011194540.13019-1-onemda@gmail.com
State Accepted
Commit 961d6493e8c2846032dfda6f9dba557a98b02de4
Headers show

Commit Message

Paul B Mahol Oct. 11, 2019, 7:45 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 doc/utils.texi   | 3 +++
 libavutil/eval.c | 4 ++++
 2 files changed, 7 insertions(+)

Comments

Liu Steven Oct. 12, 2019, 3:17 a.m. UTC | #1
> 在 2019年10月12日,03:45,Paul B Mahol <onemda@gmail.com> 写道:
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
> doc/utils.texi   | 3 +++
> libavutil/eval.c | 4 ++++
> 2 files changed, 7 insertions(+)
> 
> diff --git a/doc/utils.texi b/doc/utils.texi
> index d55dd315c3..4e2e713505 100644
> --- a/doc/utils.texi
> +++ b/doc/utils.texi
> @@ -920,6 +920,9 @@ corresponding input value will be returned.
> @item round(expr)
> Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0".
> 
> +@item sgn(x)
> +Compute sign of @var{x}.
> +
> @item sin(x)
> Compute sine of @var{x}.
> 
> diff --git a/libavutil/eval.c b/libavutil/eval.c
> index 5da9a6d83b..48832979e2 100644
> --- a/libavutil/eval.c
> +++ b/libavutil/eval.c
> @@ -163,6 +163,7 @@ struct AVExpr {
>         e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round,
>         e_sqrt, e_not, e_random, e_hypot, e_gcd,
>         e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2, e_lerp,
> +        e_sgn,
>     } type;
>     double value; // is sign in other types
>     union {
> @@ -197,6 +198,7 @@ static double eval_expr(Parser *p, AVExpr *e)
>         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_round:  return e->value * round(eval_expr(p, e->param[0]));
> +        case e_sgn:    return e->value * FFDIFFSIGN(eval_expr(p, e->param[0]), 0);
>         case e_sqrt:   return e->value * sqrt (eval_expr(p, e->param[0]));
>         case e_not:    return e->value * (eval_expr(p, e->param[0]) == 0);
>         case e_if:     return e->value * (eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
> @@ -470,6 +472,7 @@ static int parse_primary(AVExpr **e, Parser *p)
>     else if (strmatch(next, "clip"  )) d->type = e_clip;
>     else if (strmatch(next, "atan2" )) d->type = e_atan2;
>     else if (strmatch(next, "lerp"  )) d->type = e_lerp;
> +    else if (strmatch(next, "sgn"   )) d->type = e_sgn;
>     else {
>         for (i=0; p->func1_names && p->func1_names[i]; i++) {
>             if (strmatch(next, p->func1_names[i])) {
> @@ -657,6 +660,7 @@ static int verify_expr(AVExpr *e)
>         case e_sqrt:
>         case e_not:
>         case e_random:
> +        case e_sgn:
>             return verify_expr(e->param[0]) && !e->param[1];
>         case e_print:
>             return verify_expr(e->param[0])
> -- 
> 2.17.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

lgtm

Thanks
Steven
James Darnley Oct. 12, 2019, 9:42 a.m. UTC | #2
On 2019-10-11 21:45, Paul B Mahol wrote:

> diff --git a/doc/utils.texi b/doc/utils.texi
> index d55dd315c3..4e2e713505 100644
> --- a/doc/utils.texi
> +++ b/doc/utils.texi
> @@ -920,6 +920,9 @@ corresponding input value will be returned.
>  @item round(expr)
>  Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0".
>  
> +@item sgn(x)
> +Compute sign of @var{x}.
> +
>  @item sin(x)
>  Compute sine of @var{x}.
>  

Too late now but, since we have round() just above it which is 5 chars,
couldn't you have made this sign()?
Carl Eugen Hoyos Oct. 12, 2019, 3:36 p.m. UTC | #3
> Am 12.10.2019 um 11:42 schrieb James Darnley <james.darnley@gmail.com>:
> 
>> On 2019-10-11 21:45, Paul B Mahol wrote:
>> 
>> diff --git a/doc/utils.texi b/doc/utils.texi
>> index d55dd315c3..4e2e713505 100644
>> --- a/doc/utils.texi
>> +++ b/doc/utils.texi
>> @@ -920,6 +920,9 @@ corresponding input value will be returned.
>> @item round(expr)
>> Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0".
>> 
>> +@item sgn(x)
>> +Compute sign of @var{x}.
>> +
>> @item sin(x)
>> Compute sine of @var{x}.
>> 
> 
> Too late now but, since we have round() just above it which is 5 chars,
> couldn't you have made this sign()?

It’s not too late if we agree that it should be changed (sounds good to me).

Carl Eugen
diff mbox

Patch

diff --git a/doc/utils.texi b/doc/utils.texi
index d55dd315c3..4e2e713505 100644
--- a/doc/utils.texi
+++ b/doc/utils.texi
@@ -920,6 +920,9 @@  corresponding input value will be returned.
 @item round(expr)
 Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0".
 
+@item sgn(x)
+Compute sign of @var{x}.
+
 @item sin(x)
 Compute sine of @var{x}.
 
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 5da9a6d83b..48832979e2 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -163,6 +163,7 @@  struct AVExpr {
         e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round,
         e_sqrt, e_not, e_random, e_hypot, e_gcd,
         e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2, e_lerp,
+        e_sgn,
     } type;
     double value; // is sign in other types
     union {
@@ -197,6 +198,7 @@  static double eval_expr(Parser *p, AVExpr *e)
         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_round:  return e->value * round(eval_expr(p, e->param[0]));
+        case e_sgn:    return e->value * FFDIFFSIGN(eval_expr(p, e->param[0]), 0);
         case e_sqrt:   return e->value * sqrt (eval_expr(p, e->param[0]));
         case e_not:    return e->value * (eval_expr(p, e->param[0]) == 0);
         case e_if:     return e->value * (eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
@@ -470,6 +472,7 @@  static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "clip"  )) d->type = e_clip;
     else if (strmatch(next, "atan2" )) d->type = e_atan2;
     else if (strmatch(next, "lerp"  )) d->type = e_lerp;
+    else if (strmatch(next, "sgn"   )) d->type = e_sgn;
     else {
         for (i=0; p->func1_names && p->func1_names[i]; i++) {
             if (strmatch(next, p->func1_names[i])) {
@@ -657,6 +660,7 @@  static int verify_expr(AVExpr *e)
         case e_sqrt:
         case e_not:
         case e_random:
+        case e_sgn:
             return verify_expr(e->param[0]) && !e->param[1];
         case e_print:
             return verify_expr(e->param[0])