You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromdecimalimportDecimalprint(-0.9//0.123)
# prints -8.0print(Decimal('-0.9')//Decimal('0.123'))
# prints -7print(-10//4.2)
# prints -3.0print(Decimal('-10')//Decimal('4.2'))
# prints -2
There are some small differences between arithmetic on Decimal objects
and arithmetic on integers and floats. When the remainder operator % is
applied to Decimal objects
The issue is that the decimal spec specifies "divide-integer" and "remainder" operations. We've chosen to map those operations to "%" and "//" for convenience, even though there's a difference between float and Decimal here.
Thanks for the report. I'm going to close here, since this isn't a bug.
If you want to advocate for a behaviour change, by all means go ahead, but be aware that it would likely be a hard sell. The main challenge would be finding a way to change the behaviour that doesn't abruptly break existing code that depends on the current semantics.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: