Skip to content

Commit

Permalink
complete math.* coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroscope committed Jun 1, 2018
1 parent 3088337 commit abc6b34
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
61 changes: 51 additions & 10 deletions docs/include-cmd-scripting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,24 @@ Math Functions
These commands are only available in rTorrent-PS 1.1+, in rTorrent-PS-CH,
and maybe 2032 or so in rTorrent.

Values can either be of type *value* or *string* –
strings are automatically converted,
with an error thrown when the string contains something other than digits.

The handled values are restricted to integer arithmetic (as in `bash`),
because `rTorrent` has no floating point type.
Division, average, and median always round down.

All commands support multiple arguments, including lists.
List arguments are handled recursively,
as-if there were a nested `math.*` call of the same type,
with the list as its arguments.

When using multiple list arguments, or mixing them with plain numbers,
this can lead to unexpected results with non-commutative operators,
see the ``math.sub`` examples below.


.. glossary::

math.add
Expand All @@ -737,14 +755,10 @@ and maybe 2032 or so in rTorrent.
math.div
math.mod

**TODO**
Basic arithmetic operators (+, -, *, /, %).
These share the same code, so the errors shown in the following examples
usually apply to all commands, and are not repeated.

Also take note that list arguments are handled recursively,
as-if there were a nested `math.*` call of the same type,
with the list as its arguments.
usually apply to all commands, and are not repeated for each operator.

Examples:

Expand All @@ -768,17 +782,44 @@ and maybe 2032 or so in rTorrent.
:start-at: # math.div
:end-before: # END

.. literalinclude:: rtorrent-ps/tests/commands/math.txt
:language: console
:start-at: # math.mod
:end-before: # END


math.min
math.max
math.med
math.cnt
math.avg
math.med

**TODO**
Functions to calculate the minimum, maximum, element count, average, or median over the input values.

math.cnt
.. literalinclude:: rtorrent-ps/tests/commands/math.txt
:language: console
:start-at: # math.min
:end-before: # END

**TODO**
.. literalinclude:: rtorrent-ps/tests/commands/math.txt
:language: console
:start-at: # math.max
:end-before: # END

.. literalinclude:: rtorrent-ps/tests/commands/math.txt
:language: console
:start-at: # math.cnt
:end-before: # END

.. literalinclude:: rtorrent-ps/tests/commands/math.txt
:language: console
:start-at: # math.avg
:end-before: # END

.. literalinclude:: rtorrent-ps/tests/commands/math.txt
:language: console
:start-at: # math.med
:end-before: # END


Value Conversion & Formatting
Expand Down
2 changes: 1 addition & 1 deletion docs/rtorrent-ps

0 comments on commit abc6b34

Please sign in to comment.