From 143f1e92034429e0b87a24bca0f98da81f17d38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Sun, 1 Jul 2012 16:11:23 +0300 Subject: [PATCH] eval: Add the isinf() function and tests for it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- doc/eval.texi | 2 ++ libavutil/avutil.h | 2 +- libavutil/eval.c | 9 ++++++++- tests/ref/fate/eval | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/eval.texi b/doc/eval.texi index 7f8f3653b3..e1fd7ee484 100644 --- a/doc/eval.texi +++ b/doc/eval.texi @@ -34,6 +34,8 @@ The following functions are available: @item abs(x) @item squish(x) @item gauss(x) +@item isinf(x) +Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise. @item isnan(x) Return 1.0 if @var{x} is NAN, 0.0 otherwise. diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 351e8279ac..69c5727fb2 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -153,7 +153,7 @@ #define LIBAVUTIL_VERSION_MAJOR 51 #define LIBAVUTIL_VERSION_MINOR 34 -#define LIBAVUTIL_VERSION_MICRO 0 +#define LIBAVUTIL_VERSION_MICRO 1 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ diff --git a/libavutil/eval.c b/libavutil/eval.c index 36b5ce5dda..f2d619f5c9 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -120,7 +120,7 @@ static int strmatch(const char *s, const char *prefix) struct AVExpr { enum { e_value, e_const, e_func0, e_func1, e_func2, - e_squish, e_gauss, e_ld, e_isnan, + e_squish, e_gauss, e_ld, e_isnan, e_isinf, 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, @@ -148,6 +148,7 @@ 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_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_isinf: return e->value * !!isinf(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])); @@ -282,6 +283,7 @@ static int parse_primary(AVExpr **e, Parser *p) else if (strmatch(next, "lt" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; } else if (strmatch(next, "ld" )) d->type = e_ld; else if (strmatch(next, "isnan" )) d->type = e_isnan; + else if (strmatch(next, "isinf" )) d->type = e_isinf; else if (strmatch(next, "st" )) d->type = e_st; else if (strmatch(next, "while" )) d->type = e_while; else if (strmatch(next, "floor" )) d->type = e_floor; @@ -453,6 +455,7 @@ static int verify_expr(AVExpr *e) case e_ld: case e_gauss: case e_isnan: + case e_isinf: case e_floor: case e_ceil: case e_trunc: @@ -601,6 +604,10 @@ int main(int argc, char **argv) "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))", "isnan(1)", "isnan(NAN)", + "isnan(INF)", + "isinf(1)", + "isinf(NAN)", + "isinf(INF)", "floor(NAN)", "floor(123.123)", "floor(-123.123)", diff --git a/tests/ref/fate/eval b/tests/ref/fate/eval index ef50292024..b6ca0fa383 100644 --- a/tests/ref/fate/eval +++ b/tests/ref/fate/eval @@ -112,6 +112,18 @@ Evaluating 'isnan(1)' Evaluating 'isnan(NAN)' 'isnan(NAN)' -> 1.000000 +Evaluating 'isnan(INF)' +'isnan(INF)' -> 0.000000 + +Evaluating 'isinf(1)' +'isinf(1)' -> 0.000000 + +Evaluating 'isinf(NAN)' +'isinf(NAN)' -> 0.000000 + +Evaluating 'isinf(INF)' +'isinf(INF)' -> 1.000000 + Evaluating 'floor(NAN)' 'floor(NAN)' -> nan