1@chapter Expression Evaluation 2@c man begin EXPRESSION EVALUATION 3 4When evaluating an arithmetic expression, Libav uses an internal 5formula evaluator, implemented through the @file{libavutil/eval.h} 6interface. 7 8An expression may contain unary, binary operators, constants, and 9functions. 10 11Two expressions @var{expr1} and @var{expr2} can be combined to form 12another expression "@var{expr1};@var{expr2}". 13@var{expr1} and @var{expr2} are evaluated in turn, and the new 14expression evaluates to the value of @var{expr2}. 15 16The following binary operators are available: @code{+}, @code{-}, 17@code{*}, @code{/}, @code{^}. 18 19The following unary operators are available: @code{+}, @code{-}. 20 21The following functions are available: 22@table @option 23@item sinh(x) 24@item cosh(x) 25@item tanh(x) 26@item sin(x) 27@item cos(x) 28@item tan(x) 29@item atan(x) 30@item asin(x) 31@item acos(x) 32@item exp(x) 33@item log(x) 34@item abs(x) 35@item squish(x) 36@item gauss(x) 37@item isnan(x) 38Return 1.0 if @var{x} is NAN, 0.0 otherwise. 39 40@item mod(x, y) 41@item max(x, y) 42@item min(x, y) 43@item eq(x, y) 44@item gte(x, y) 45@item gt(x, y) 46@item lte(x, y) 47@item lt(x, y) 48@item st(var, expr) 49Allow to store the value of the expression @var{expr} in an internal 50variable. @var{var} specifies the number of the variable where to 51store the value, and it is a value ranging from 0 to 9. The function 52returns the value stored in the internal variable. 53 54@item ld(var) 55Allow to load the value of the internal variable with number 56@var{var}, which was previously stored with st(@var{var}, @var{expr}). 57The function returns the loaded value. 58 59@item while(cond, expr) 60Evaluate expression @var{expr} while the expression @var{cond} is 61non-zero, and returns the value of the last @var{expr} evaluation, or 62NAN if @var{cond} was always false. 63 64@item ceil(expr) 65Round the value of expression @var{expr} upwards to the nearest 66integer. For example, "ceil(1.5)" is "2.0". 67 68@item floor(expr) 69Round the value of expression @var{expr} downwards to the nearest 70integer. For example, "floor(-1.5)" is "-2.0". 71 72@item trunc(expr) 73Round the value of expression @var{expr} towards zero to the nearest 74integer. For example, "trunc(-1.5)" is "-1.0". 75 76@item sqrt(expr) 77Compute the square root of @var{expr}. This is equivalent to 78"(@var{expr})^.5". 79 80@item not(expr) 81Return 1.0 if @var{expr} is zero, 0.0 otherwise. 82@end table 83 84Note that: 85 86@code{*} works like AND 87 88@code{+} works like OR 89 90thus 91@example 92if A then B else C 93@end example 94is equivalent to 95@example 96A*B + not(A)*C 97@end example 98 99In your C code, you can extend the list of unary and binary functions, 100and define recognized constants, so that they are available for your 101expressions. 102 103The evaluator also recognizes the International System number 104postfixes. If 'i' is appended after the postfix, powers of 2 are used 105instead of powers of 10. The 'B' postfix multiplies the value for 8, 106and can be appended after another postfix or used alone. This allows 107using for example 'KB', 'MiB', 'G' and 'B' as postfix. 108 109Follows the list of available International System postfixes, with 110indication of the corresponding powers of 10 and of 2. 111@table @option 112@item y 113-24 / -80 114@item z 115-21 / -70 116@item a 117-18 / -60 118@item f 119-15 / -50 120@item p 121-12 / -40 122@item n 123-9 / -30 124@item u 125-6 / -20 126@item m 127-3 / -10 128@item c 129-2 130@item d 131-1 132@item h 1332 134@item k 1353 / 10 136@item K 1373 / 10 138@item M 1396 / 20 140@item G 1419 / 30 142@item T 14312 / 40 144@item P 14515 / 40 146@item E 14718 / 50 148@item Z 14921 / 60 150@item Y 15124 / 70 152@end table 153 154@c man end 155