In this two commits, I did some minor revisions on pypar.balance() function.
The 1st one guards the argument p against out-of-bound values, and returns (N, N). This return value is natural because N:N is a valid slice of zero-length, which is expected, and also because this is a natural continuation of the return values from valid input values, and finally, such is already the case when balance(N, P, p) is called when P > N.
In the 2nd commit, from math import floor is no longer used, as with conversions to float. They're not necessary, and are much slower than integer arithmetics. To get the quotient and remainder, Python's built-in operators // and % are enough. This is even faster than divmod().
In this two commits, I did some minor revisions on
pypar.balance()
function.The 1st one guards the argument
p
against out-of-bound values, and returns(N, N)
. This return value is natural becauseN:N
is a valid slice of zero-length, which is expected, and also because this is a natural continuation of the return values from valid input values, and finally, such is already the case whenbalance(N, P, p)
is called whenP > N
.In the 2nd commit,
from math import floor
is no longer used, as with conversions tofloat
. They're not necessary, and are much slower than integer arithmetics. To get the quotient and remainder, Python's built-in operators//
and%
are enough. This is even faster thandivmod()
.