1 @chapter Expression Evaluation
2 @c man begin EXPRESSION EVALUATION
4 When evaluating an arithmetic expression, FFmpeg uses an internal
5 formula evaluator, implemented through the @file{libavutil/eval.h}
8 An expression may contain unary, binary operators, constants, and
11 Two expressions @var{expr1} and @var{expr2} can be combined to form
12 another expression "@var{expr1};@var{expr2}".
13 @var{expr1} and @var{expr2} are evaluated in turn, and the new
14 expression evaluates to the value of @var{expr2}.
16 The following binary operators are available: @code{+}, @code{-},
17 @code{*}, @code{/}, @code{^}.
19 The following unary operators are available: @code{+}, @code{-}.
21 The following functions are available:
38 Return 1.0 if @var{x} is +/-INFINITY, 0.0 otherwise.
40 Return 1.0 if @var{x} is NAN, 0.0 otherwise.
51 Allow to store the value of the expression @var{expr} in an internal
52 variable. @var{var} specifies the number of the variable where to
53 store the value, and it is a value ranging from 0 to 9. The function
54 returns the value stored in the internal variable.
55 Note, Variables are currently not shared between expressions.
58 Allow to load the value of the internal variable with number
59 @var{var}, which was previously stored with st(@var{var}, @var{expr}).
60 The function returns the loaded value.
62 @item while(cond, expr)
63 Evaluate expression @var{expr} while the expression @var{cond} is
64 non-zero, and returns the value of the last @var{expr} evaluation, or
65 NAN if @var{cond} was always false.
68 Round the value of expression @var{expr} upwards to the nearest
69 integer. For example, "ceil(1.5)" is "2.0".
72 Round the value of expression @var{expr} downwards to the nearest
73 integer. For example, "floor(-1.5)" is "-2.0".
76 Round the value of expression @var{expr} towards zero to the nearest
77 integer. For example, "trunc(-1.5)" is "-1.0".
80 Compute the square root of @var{expr}. This is equivalent to
84 Return 1.0 if @var{expr} is zero, 0.0 otherwise.
87 Compute the power of @var{x} elevated @var{y}, it is equivalent to
88 "(@var{x})^(@var{y})".
91 Return a pseudo random value between 0.0 and 1.0. @var{x} is the index of the
92 internal variable which will be used to save the seed/state.
95 This function is similar to the C function with the same name; it returns
96 "sqrt(@var{x}*@var{x} + @var{y}*@var{y})", the length of the hypotenuse of a
97 right triangle with sides of length @var{x} and @var{y}, or the distance of the
98 point (@var{x}, @var{y}) from the origin.
101 Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
102 @var{y} are 0 or either or both are less than zero then behavior is undefined.
105 Evaluate @var{x}, and if the result is non-zero return the result of
106 the evaluation of @var{y}, return 0 otherwise.
109 Evaluate @var{x}, and if the result is zero return the result of the
110 evaluation of @var{y}, return 0 otherwise.
112 @item taylor(expr, x) taylor(expr, x, id)
113 Evaluate a taylor series at x.
114 expr represents the LD(id)-th derivates of f(x) at 0. If id is not specified
116 note, when you have the derivatives at y instead of 0
117 taylor(expr, x-y) can be used
118 When the series does not converge the results are undefined.
120 @item root(expr, max)
121 Finds x where f(x)=0 in the interval 0..max.
122 f() must be continuous or the result is undefined.
125 The following constants are available:
128 area of the unit disc, approximately 3.14
130 exp(1) (Euler's number), approximately 2.718
132 golden ratio (1+sqrt(5))/2, approximately 1.618
135 Assuming that an expression is considered "true" if it has a non-zero
138 @code{*} works like AND
140 @code{+} works like OR
151 In your C code, you can extend the list of unary and binary functions,
152 and define recognized constants, so that they are available for your
155 The evaluator also recognizes the International System number
156 postfixes. If 'i' is appended after the postfix, powers of 2 are used
157 instead of powers of 10. The 'B' postfix multiplies the value for 8,
158 and can be appended after another postfix or used alone. This allows
159 using for example 'KB', 'MiB', 'G' and 'B' as postfix.
161 Follows the list of available International System postfixes, with
162 indication of the corresponding powers of 10 and of 2.