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

[python] mod operator is modulus in python, not remainder #2886

Open
jwunderl opened this issue Apr 23, 2020 · 0 comments
Open

[python] mod operator is modulus in python, not remainder #2886

jwunderl opened this issue Apr 23, 2020 · 0 comments

Comments

@jwunderl
Copy link
Member

Describe the bug

mod operator in python is modulus, not remainder; this means it handles negatives differently from javascript.

-1 % 4

in python is 3, in javascript / c++ is -1

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://makecode.microbit.org/_LhfXu3iHigXL
  2. see console output
  3. go to console / terminal window, start python repl (python)
  4. print(-1 % 4) in window; see output is different

Expected behavior

Maybe need a helper function for mod to convert to in python or something? It's a bit of an edge case.

Remembered they were different in python when responding to https://forum.makecode.com/t/remainder-modulus-operator-returning-negative-values-when-it-shouldnt/1789

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

No branches or pull requests

2 participants