Hi Nathan, and welcome!
On Fri, Mar 18, 2022 at 05:13:16AM -0000, Nathan Levett wrote: > First time posting here ~ I've recently encountered that python does > not have an OOTB operator for modulo that is consistent with Euclidean > division. Although it should be easy for anyone who wants this to > create it themselves, it struck me as odd that it was not an already > included feature. I was even more shocked to see a list indicating > that most languages don't include one consister with Euclidean > division (disheartening to realise that the number theory way of doing > things is not the default). Your post would be more persuasive if you: * explained how Python's modulo is not consistent with Euclidean division; * defined what definition of modulo is "the number theory way of doing things"; * told us what languages you have found that do include this version of modulo. I'm not sure what part of number theory you are referring to. You should explain, since its not obvious. I've just grabbed one of my text books, and it doesn't even define a modulo operator. It only defines modulo arithmetic, as in: a is congruent to b mod m if m∣(a-b) with a, b, m ∈ ℤ and m non-negative. where ∣ is "divides". Although both a and b may be negative, not one of the examples or exercises include examples where they are negative. Wolfram language (Mathematica) define their Mod[a, b] function: a mod b = a - b*floor(a/b) which for real-valued a, b gives the result with the same sign as b. https://functions.wolfram.com/IntegerFunctions/Mod/ That, I believe, makes it the same as Python's % operator. Ada has two functions, mod() and rem(). I believe that mod(a, b) is the same as Python's a%b, while rem(a, b) takes the sign of a rather than the sign of b. http://archive.adaic.com/standards/83lrm/html/lrm-04-05.html#4.5.5 Julia has the same: https://docs.julialang.org/en/v1/manual/mathematical-operations/#Division-functions -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NPGD7WW2MA7XTSHJF6A34VIFPBL7ZHMM/ Code of Conduct: http://python.org/psf/codeofconduct/