PR #26093 opened by alvarorichard URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26093 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26093.patch
Fixes #26061. `root()`, `taylor()`, `while()`, `random()` and `randomi()` fail to apply the sign stored in `e->value`, causing expressions with a leading minus to return an incorrect result. The other cases in `eval_expr()` multiply their results by `e->value`, but these five cases return the raw result. This patch applies `e->value` to the return value of all five cases and adds regression tests for each function. | Expression | Before | After | |---|---:|---:| | `-taylor(1, 1)` | 2.718282 | -2.718282 | | `100-root(ld(0)-3, 10)` | 103.000000 | 97.000000 | | `100-while(lt(ld(0), 3), ...)` | 106.000000 | 94.000000 | | `ld(1)-random(0)` | 1.040158 | 0.000000 | | `100-randomi(0, 10, 20)` | 115.200791 | 84.799209 | Tested on Windows with GCC 15.2 and NASM 3.02: - Full `make fate`: 5924 tests passed. - Full `make fate` with `--disable-x86asm`: 5916 tests passed. - Existing eval expressions produce unchanged results. >From b33a73f8f33f7498c13ea6c176bcd853257085bb Mon Sep 17 00:00:00 2001 From: alvarorichard <[email protected]> Date: Mon, 16 Nov 2026 01:06:03 -0300 Subject: [PATCH] avutil/eval: apply the sign to root, taylor, while, random and randomi These five cases in eval_expr() returned their result without multiplying it by e->value, so a leading minus was dropped and "A - f(x)" was evaluated as "A + f(x)". Fixes #26061. Reported-by: yutong Signed-off-by: alvarorichard <[email protected]> --- libavutil/eval.c | 10 +++++----- libavutil/tests/eval.c | 5 +++++ tests/ref/fate/eval | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libavutil/eval.c b/libavutil/eval.c index 9b5ad218495..a62b9c50ced 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -256,19 +256,19 @@ static double eval_expr(Parser *p, AVExpr *e) case e_random: { COMPUTE_NEXT_RANDOM(); - return r * (1.0/UINT64_MAX); + return e->value * r * (1.0/UINT64_MAX); } case e_randomi: { double min = eval_expr(p, e->param[1]); double max = eval_expr(p, e->param[2]); COMPUTE_NEXT_RANDOM(); - return min + (max - min) * r / UINT64_MAX; + return e->value * (min + (max - min) * r / UINT64_MAX); } case e_while: { double d = NAN; while (eval_expr(p, e->param[0])) d=eval_expr(p, e->param[1]); - return d; + return e->value * d; } case e_taylor: { double t = 1, d = 0, v; @@ -286,7 +286,7 @@ static double eval_expr(Parser *p, AVExpr *e) t *= x / (i+1); } p->var[id] = var0; - return d; + return e->value * d; } case e_root: { int i, j; @@ -328,7 +328,7 @@ static double eval_expr(Parser *p, AVExpr *e) } } p->var[0] = var0; - return -low_v<high_v ? low : high; + return e->value * (-low_v<high_v ? low : high); } default: { double d = eval_expr(p, e->param[0]); diff --git a/libavutil/tests/eval.c b/libavutil/tests/eval.c index c81aeb9ee70..0da4dcbb55a 100644 --- a/libavutil/tests/eval.c +++ b/libavutil/tests/eval.c @@ -125,6 +125,11 @@ int main(int argc, char **argv) "root(sin(ld(0))-1, 2)", "root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)", "7000000B*random(0)", + "-taylor(1, 1)", + "100-root(ld(0)-3, 10)", + "st(0, 0); 100-while(lt(ld(0), 3), st(0, ld(0)+1)*2)", + "st(0, 42); st(1, random(0)); st(0, 42); ld(1)-random(0)", + "st(0, 42); 100-randomi(0, 10, 20)", "squish(2)", "-squish(2)", "gauss(0.1)", diff --git a/tests/ref/fate/eval b/tests/ref/fate/eval index 196c1b5c86e..d07cc6ed007 100644 --- a/tests/ref/fate/eval +++ b/tests/ref/fate/eval @@ -259,6 +259,21 @@ Evaluating 'root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)' Evaluating '7000000B*random(0)' '7000000B*random(0)' -> 12864914.486611 +Evaluating '-taylor(1, 1)' +'-taylor(1, 1)' -> -2.718282 + +Evaluating '100-root(ld(0)-3, 10)' +'100-root(ld(0)-3, 10)' -> 97.000000 + +Evaluating 'st(0, 0); 100-while(lt(ld(0), 3), st(0, ld(0)+1)*2)' +'st(0, 0); 100-while(lt(ld(0), 3), st(0, ld(0)+1)*2)' -> 94.000000 + +Evaluating 'st(0, 42); st(1, random(0)); st(0, 42); ld(1)-random(0)' +'st(0, 42); st(1, random(0)); st(0, 42); ld(1)-random(0)' -> 0.000000 + +Evaluating 'st(0, 42); 100-randomi(0, 10, 20)' +'st(0, 42); 100-randomi(0, 10, 20)' -> 84.799209 + Evaluating 'squish(2)' 'squish(2)' -> 0.000335 -- 2.54.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
