7d8106b89e242cf99c5a24972c52e2107199e721
1 @chapter Expression Evaluation
2 @c man begin EXPRESSION EVALUATION
4 When evaluating an arithemetic expression, Libav uses an internal
5 formula evaluator, implemented through the @file{libavutil/eval.h}
6 interface.
8 An expression may contain unary, binary operators, constants, and
9 functions.
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:
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)
38 Return 1.0 if @var{x} is NAN, 0.0 otherwise.
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)
49 Allow to store the value of the expression @var{expr} in an internal
50 variable. @var{var} specifies the number of the variable where to
51 store the value, and it is a value ranging from 0 to 9. The function
52 returns the value stored in the internal variable.
54 @item ld(var)
55 Allow to load the value of the internal variable with number
56 @var{var}, which was previosly stored with st(@var{var}, @var{expr}).
57 The function returns the loaded value.
59 @item while(cond, expr)
60 Evaluate expression @var{expr} while the expression @var{cond} is
61 non-zero, and returns the value of the last @var{expr} evaluation, or
62 NAN if @var{cond} was always false.
64 @item ceil(expr)
65 Round the value of expression @var{expr} upwards to the nearest
66 integer. For example, "ceil(1.5)" is "2.0".
68 @item floor(expr)
69 Round the value of expression @var{expr} downwards to the nearest
70 integer. For example, "floor(-1.5)" is "-2.0".
72 @item trunc(expr)
73 Round the value of expression @var{expr} towards zero to the nearest
74 integer. For example, "trunc(-1.5)" is "-1.0".
76 @item sqrt(expr)
77 Compute the square root of @var{expr}. This is equivalent to
78 "(@var{expr})^.5".
80 @item not(expr)
81 Return 1.0 if @var{expr} is zero, 0.0 otherwise.
82 @end table
84 Note that:
86 @code{*} works like AND
88 @code{+} works like OR
90 thus
91 @example
92 if A then B else C
93 @end example
94 is equivalent to
95 @example
96 A*B + not(A)*C
97 @end example
99 In your C code, you can extend the list of unary and binary functions,
100 and define recognized constants, so that they are available for your
101 expressions.
103 The evaluator also recognizes the International System number
104 postfixes. If 'i' is appended after the postfix, powers of 2 are used
105 instead of powers of 10. The 'B' postfix multiplies the value for 8,
106 and can be appended after another postfix or used alone. This allows
107 using for example 'KB', 'MiB', 'G' and 'B' as postfix.
109 Follows the list of available International System postfixes, with
110 indication 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
133 2
134 @item k
135 3 / 10
136 @item K
137 3 / 10
138 @item M
139 6 / 20
140 @item G
141 9 / 30
142 @item T
143 12 / 40
144 @item P
145 15 / 40
146 @item E
147 18 / 50
148 @item Z
149 21 / 60
150 @item Y
151 24 / 70
152 @end table
154 @c man end