On 30/09/2021 08:57, Serhiy Storchaka wrote:
Decimals use a different rule than integers and floats: the modulus has
the same sign as the dividend. It was discussed using this rule for
floats (perhaps there is even FAQ or HOWTO for this), there are
advantages of using it for floats (the result is more accurate). But the
current rule (the modulus has the same sign as the divisor) is much much
more convenient for integers, and having different rules for integers
and floats is a source of bugs.

Thanks Serhiy and Victor. I hadn't realised decimal was so different from float. So decimal is not useful as a comparator. It's not an idealisation of intended float behaviour.

The question is about floor-division of two Python built-in floats, involving non-finite operands, and whether this is standardised in Python the language. I couldn't find a FAQ/HOW-TO and nothing in the IEEE standard bears directly on floor division. I found an interesting discussion (https://mail.python.org/pipermail/python-dev/2007-January/070707.html) but it is having so much trouble with finite arguments that it barely mentions extended values a float might take. Tim makes good sense as always.

Observing behaviour (Windows and Linux), it is consistent now but was divergent in the past. In Python 2.7.16 (Windows):

>>> -3.14 // inf
nan

In 3.8 (Windows and Linux) and 2.7 (Linux):

>>> -3.14 // inf
-1.0

I would put the change down to improving fmod conformance in MSC, rather than a Python language change. But the cause doesn't matter. The fact that both were acceptable suggests that floor division is not standardised for non-finite operands.

Pragmatically, however, it is seldom a good idea to differ from CPython. A bit of extra work at run-time, to check the divsor, is not a big penalty.

--

Jeff Allen

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/S62T3SHVDEVW4ZWDDKSE76KFYWK5TAQT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to