eval.texi 3.5 KB

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