Posted 14 July 2016 - 11:30 AM
I'm writing an API that revolves around mathematics. Within this API, I have basic arithmetic operations that receive multiple arguments and apply the operation with each argument, where the first argument is the value on which to apply the operation.
So for example, I would have divide(n, a, B)/> and it would do n / a followed by n / b (it's actually simplified to n / (a * B)/> if a * b is found to not exceed the bit32 limit).
I'd like to write a similar function for modulo but I can't think of a proper way of simplifying multiple operands to optimize the algorithm.
Here are the ideas I currently have, given that the additional arguments are numbered alphabetically.
So for example, I would have divide(n, a, B)/> and it would do n / a followed by n / b (it's actually simplified to n / (a * B)/> if a * b is found to not exceed the bit32 limit).
I'd like to write a similar function for modulo but I can't think of a proper way of simplifying multiple operands to optimize the algorithm.
Here are the ideas I currently have, given that the additional arguments are numbered alphabetically.
- If b > a then skip b because n mod a mod b = n mod a
- If b | a then skip a because n mod a mod b = n mod b
- If n mod a is 0 then skip all following moduli