Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

behaviour of the modulo operator #129297

Closed
SerpentByte opened this issue Jan 25, 2025 · 3 comments
Closed

behaviour of the modulo operator #129297

SerpentByte opened this issue Jan 25, 2025 · 3 comments

Comments

@SerpentByte
Copy link

SerpentByte commented Jan 25, 2025

Feature or enhancement

Proposal:

The behaviour of the modulo operator should be made consistent across Python and C/C++.

3%2 # this is 1
-3%2 # this can be represented as -1 or 1 depending of the divisor.
# -3%2 is -1 in C/C++.

Has this already been discussed elsewhere?

I don't think so.

@SerpentByte SerpentByte added the type-feature A feature request or enhancement label Jan 25, 2025
@sobolevn
Copy link
Member

Looks like a duplicate of #75204

@ronaldoussoren
Copy link
Contributor

The behaviour of the operator is intentional, see the answers in this stack overflow question for a good explanation of the rationale for this choice.

@ronaldoussoren ronaldoussoren closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2025
@Eclips4 Eclips4 removed the type-feature A feature request or enhancement label Jan 25, 2025
@terryjreedy
Copy link
Member

Issue #75204 is not really a duplicate; it is an open proposal to revise the int division programming FAQ, which involves the choice of modulus sign determination. I just opened PR #129313 for it. It needs coredev review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants