Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for basic arithmetic operators to git version #71

Closed
chros73 opened this issue Mar 5, 2017 · 3 comments
Closed

Add support for basic arithmetic operators to git version #71

chros73 opened this issue Mar 5, 2017 · 3 comments

Comments

@chros73
Copy link
Owner

chros73 commented Mar 5, 2017

I. Summary
Add support for basic arithmetic operators (+, -, *, /, %) and min, max, count, avg, median functions.
All commands:

  • support multiple arguments
  • support list type as well
  • restricted to integer arithmetic (as in bash), even /
    • rtorrent (and libtorrent) currently handles only integer variables
    • /, avg, median always round down

II. New commands in rtorrent

  • math.add
  • math.sub
  • math.mul
  • math.div
  • math.mod
  • math.min
  • math.max
  • math.cnt
  • math.avg
  • math.med

III. Arithmetic operators in action

# Subtract 3 numbers: -4
print=(math.sub,5,2,7)
# Divide 3 numbers: 2 !
print=(math.div,80,9,4)

# Calculate size of a download using its size of files (example using list type)
print=(math.add,(f.multicall,,f.size_bytes=))

# Get average size in Bytes of downloads in main view
print=(math.div,(math.add,(d.multicall2,main,d.size_bytes=)),(view.size,main))

math.min and math.max can be used as variable assignment based on intervals as well:

# Assign 0 if value smaller than 0, or assign value otherwise ( x >= 0 ? x : 0 )
print=(math.max,0,(math.sub,2,7))
# Assign 0 if value smaller than 0, 100 if value is bigger than 100, or assign value otherwise ( x < 0 ? 0 : (x > 100 ? 100 : x) )
print=(math.max,0,(math.min,100,(math.div,500,2)))
@chros73
Copy link
Owner Author

chros73 commented Mar 6, 2017

Rename commands as @rakshasa suggested:

  • math.add
  • math.sub
  • math.mul
  • math.div
  • math.mod
  • math.min
  • math.max

Note: Original post has been edited.

@chros73 chros73 reopened this Mar 6, 2017
@chros73 chros73 closed this as completed in 0898c2e Mar 6, 2017
@chros73
Copy link
Owner Author

chros73 commented Mar 7, 2017

Add 2 new commands:

  • math.cnt (count)
  • math.avg

Note: Original post has been edited.

chros73 pushed a commit that referenced this issue Mar 7, 2017
@chros73
Copy link
Owner Author

chros73 commented Mar 11, 2017

Add 1 new command for median:

  • math.med

Note: Original post has been edited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant