You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
3.4KB

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