Quotient and Modulo Mathematical Operations Request
raykholo last edited by
Would it be possible to have the mathematical operations of "Quotient" (divide without remainder) and Modulo (just the remainder)? I did not see any reference to these in the Meta Commands documentation.
I want to build a filament changer (MMU2 style to feed different filament types/ colors) on top of a tool changer (grab different nozzle sizes) so that any combination of filament/ color and nozzle size is possible.
In an example of 3 tools (say a 0.25, 0.4, and 0.8 volcano nozzle sizes) and 5 filament colors, we have 15 combinations to resolve. I would use the existing T# functionality to handle tool changing, and would write a similar construct in Macros to handle the filament color changer.
I would use a Macro to resolve the 15 possible combinations into the existing T# commands to select tool, and Macros would handle the filament switching commands.
As you can see in the spreadsheet image here, we would need a Quotient and Modulo operation to do this. Quotient is Tool #, Modulo is Filament Color #.
This could be provided, but I think it would be simpler to provide a round-to-integer operator. Then you could get the quotient by using round(a/b) and the remainder from a-b*round(a/b).
A Former User last edited by A Former User
Maybe i missunderstood that, but
a b div mod round(a/b) a-b*round(a/b) 1 5 0 1 0 1 0 5 0 0 0 0 2 5 0 2 0 2 3 5 0 3 1 -2 4 5 0 4 1 -1 5 5 1 0 1 0 6 5 1 1 1 1 7 5 1 2 1 2 8 5 1 3 2 -2 9 5 1 4 2 -1 10 5 2 0 2 0 11 5 2 1 2 1 12 5 2 2 2 2 13 5 2 3 3 -2 14 5 2 4 3 -1
division without remainder would be equivalent of floor(a/b) discarding, round(a/b) would round up?
(public, don't mess it up too badly https://docs.google.com/spreadsheets/d/1jaGuxY3Faa-QBwInEJwWeWvN_0XcVKpzSUmcAWgXuP8/edit#gid=0)
I was assuming that round would behave like floor. In fact I should call it floor, not round.
A Former User last edited by
to me mod() would be much better readability than a-b*floor(a/b), but I guess not everyone will be familiar with div() and mod() either. floor gets the job done at least
I could introduce the % operator to mean mod (often the same as remainder), but integer divide would need another symbol. I deliberately made the / operator mean floating point division, so that users needn't worry about whether the operands are floats or ints.
raykholo last edited by raykholo
I agree that having to use
a-b*floor(a/b)for remainder hurts readability, especially when inside complex expressions. Please please please have a dedicated mod operation. Either syntax of
a%bis completely fine.
For the quotient, rounding is surely another option and
floor(a,b)would be fine for our purposes.
Also, please note that I used syntax of
function (a,b)and not
function (a/b)above. I have usually seen it as comma separated parameters and I am concerned that using
/would confuse the system into thinking it is division inside the function.
Thank you very much for the consideration.
I have implemented floor(x) and mod(x, y) in the latest internal builds of RRF3 at https://www.dropbox.com/sh/3azy1njy3ayjsbp/AACquxr2m00eV568RZg5QG5wa?dl=0.