eval.texi 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. @end table
  55. Note that:
  56. @code{*} works like AND
  57. @code{+} works like OR
  58. thus
  59. @example
  60. if A then B else C
  61. @end example
  62. is equivalent to
  63. @example
  64. A*B + not(A)*C
  65. @end example
  66. When A evaluates to either 1 or 0, that is the same as
  67. @example
  68. A*B + eq(A,0)*C
  69. @end example
  70. In your C code, you can extend the list of unary and binary functions,
  71. and define recognized constants, so that they are available for your
  72. expressions.
  73. The evaluator also recognizes the International System number
  74. postfixes. If 'i' is appended after the postfix, powers of 2 are used
  75. instead of powers of 10. The 'B' postfix multiplies the value for 8,
  76. and can be appended after another postfix or used alone. This allows
  77. using for example 'KB', 'MiB', 'G' and 'B' as postfix.
  78. Follows the list of available International System postfixes, with
  79. indication of the corresponding powers of 10 and of 2.
  80. @table @option
  81. @item y
  82. -24 / -80
  83. @item z
  84. -21 / -70
  85. @item a
  86. -18 / -60
  87. @item f
  88. -15 / -50
  89. @item p
  90. -12 / -40
  91. @item n
  92. -9 / -30
  93. @item u
  94. -6 / -20
  95. @item m
  96. -3 / -10
  97. @item c
  98. -2
  99. @item d
  100. -1
  101. @item h
  102. 2
  103. @item k
  104. 3 / 10
  105. @item K
  106. 3 / 10
  107. @item M
  108. 6 / 20
  109. @item G
  110. 9 / 30
  111. @item T
  112. 12 / 40
  113. @item P
  114. 15 / 40
  115. @item E
  116. 18 / 50
  117. @item Z
  118. 21 / 60
  119. @item Y
  120. 24 / 70
  121. @end table
  122. @c man end