[FFmpeg-devel] [PATCH] eval: add sqrt function for computing the squared root

Stefano Sabatini stefano.sabatini-lala at poste.it
Tue May 3 23:32:08 CEST 2011


---
 doc/eval.texi    |    3 +++
 libavutil/eval.c |    4 ++++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/doc/eval.texi b/doc/eval.texi
index d0e04c0..fe3eea6 100644
--- a/doc/eval.texi
+++ b/doc/eval.texi
@@ -72,6 +72,9 @@ integer. For example, "floor(-1.5)" is "-2.0".
 @item trunc(expr)
 Round the value of expression @var{expr} towards zero to the nearest
 integer. For example, "trunc(-1.5)" is "-1.0".
+
+ at item sqrt(expr)
+Compute the squared root of @var{expr}.
 @end table
 
 Note that:
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 494b936..164100d 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -122,6 +122,7 @@ struct AVExpr {
         e_mod, e_max, e_min, e_eq, e_gt, e_gte,
         e_pow, e_mul, e_div, e_add,
         e_last, e_st, e_while, e_floor, e_ceil, e_trunc,
+        e_sqrt,
     } type;
     double value; // is sign in other types
     union {
@@ -148,6 +149,7 @@ static double eval_expr(Parser *p, AVExpr *e)
         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_sqrt:   return e->value * sqrt (eval_expr(p, e->param[0]));
         case e_while: {
             double d = NAN;
             while (eval_expr(p, e->param[0]))
@@ -282,6 +284,7 @@ static int parse_primary(AVExpr **e, Parser *p)
     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 if (strmatch(next, "sqrt"  )) d->type = e_sqrt;
     else {
         for (i=0; p->func1_names && p->func1_names[i]; i++) {
             if (strmatch(next, p->func1_names[i])) {
@@ -449,6 +452,7 @@ static int verify_expr(AVExpr *e)
         case e_floor:
         case e_ceil:
         case e_trunc:
+        case e_sqrt:
             return verify_expr(e->param[0]);
         default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
     }
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list