30.09.21 10:07, Jeff Allen пише: >>>> from decimal import Decimal >>>> Decimal('-3.14') // Decimal('Infinity') > Decimal('-0')
You do not need an infinity to see the difference. >>> Decimal('3.14') % Decimal('2') Decimal('1.14') >>> Decimal('3.14') % Decimal('-2') Decimal('1.14') >>> Decimal('-3.14') % Decimal('2') Decimal('-1.14') >>> Decimal('-3.14') % Decimal('-2') Decimal('-1.14') 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. _______________________________________________ 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/YBIDA44TP4EA3L3OP6TQUHA6UWA6EJR2/ Code of Conduct: http://python.org/psf/codeofconduct/