On Fri, Mar 18, 2022 at 04:26:54PM -0500, Tim Peters wrote:

> Another choice is made by math.remainder:
> 
> >>> import math
> >>> math.remainder(7, 10)
> -3.0


Alas, math.remainder goes through float:

>>> math.remainder(3**500, 3)  # Should be 0.
1.0
>>> math.remainder(3**500 + 2, 3)  # Should be 2.
1.0

It would be nice if remainder() worked properly for exact values, 
without overflow or rounding errors.



> What I'm _guessing_ you mean by "Euclidean division" is that
> 
>     0 <= divmod(a,b) < abs(b)
> 
> That is, the modulus is always non-negative, regardless of the inputs' signs.
> 
> I expect no languages implement that because: (a) there's no
> particularly compelling use for it ;-) ;

I don't know whether this counts as compelling or not, but I have a 
divmod variant which returns an always positive modulus for use in base 
conversion. It is only used in one place in a module I haven't touched 
in a decade, so it is quite possible that if I were writing that code 
again today, I wouldn't do it that way.


-- 
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/PZHZ4WMH6XGMNSNI3ZZD3EY3X37TEHDV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to