On Sat, Mar 19, 2022 at 03:49:28PM -0500, Tim Peters wrote: > [Steven D'Aprano <st...@pearwood.info>] > > Sure, for floats. I certainly wouldn't want to change the behaviour for > > floats. We could change the behaviour for ints (or at least we could if > > not constrained by backwards compatibility) or add a new function. > > We could - but why would we?
You answer your own question: > > I was thinking more of Julia's rem(), which uses the sign of the dividend > > rather than the divisor. > > Which is what most languages do (like also the current standards for > C, C++, and Fortran; also what math.fmod() does). It's the natural > result when using truncating division, and the latter is what _really_ > drives it in most languages. They want integer division to truncate. Exactly. The fact is, that about half the time I use Python's mod with negative values, I get the result I don't want. That tells me that sometimes I want `%` and sometimes I want something else. Truth be told, I'm not absolutely sure that what I want is Julia's rem(), if this discussion got serious enough to write a PEP I would investigate more closely. But I doubt it will get that far. More likely I will just mine this discussion thread for good ideas, and write my own remainder function(s) once I decide precisely what I need. [...] > However, not even mpz supports what the OP here appeared to want > (non-negative mod regardless of inputs' signs). The OP hasn't told us what he actually wants, he's just dropped hints and left us to infer what he wants and hope that we got it right. -- 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/YLDBV7MISEOP37PZZVZ4WSBCO4MZ4U3C/ Code of Conduct: http://python.org/psf/codeofconduct/