-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix complex parsing signs #10297
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
base: main
Are you sure you want to change the base?
Fix complex parsing signs #10297
Conversation
Before: print(complex('-9e-17+1j')) # prints (-9e-17-1j) After: print(complex('-9e-17+1j')) # prints (-9e-17+1j)
Thanks for this! Submitting on This code comes from MicroPython, so it would be appropriate to submit this upstream, to https://github.com/micropython/micropython. It's worth looking to see if the code there has already been fixed or is different in some way. |
Yeah I was looking at MP and I see the same in the code, and same results when trying on 1.25. >>> complex("1+j")
(1+1j)
>>> complex("-1+j")
(-1-1j) |
Should I submit a PR over there too then? |
Yes, submit there first. If they accept it (and they might change it a bit), then we'll take their change as it is merged there, so the sources match. If they don't do it promptly, we can merge it here and then catch up with what they do. |
Ok, thanks! |
Another thing to do is to add a test: add it to |
There are already tests there that should've caught this mistake, not sure why they weren't noticed... There are missing tests for exponential notation and complex numbers, should I add those to to the complex1.py tests or somewhere else? |
There is no test like It would be fine to add more tests, and that's the right file to add them in. Won't hurt. |
Whoops, I thought I saw something like that, anyways I'll go ahead and add those. Thanks! |
Changes
I tried to fix a parsing error in the py/parsenum.c file.
Tests:
Before: print(complex('-9e-17+1j')) # prints (-9e-17-1j) wrong
After: print(complex('-9e-17+1j')) # prints (-9e-17+1j) correct
It's pretty simple, I just made it so it resets
dec_neg
upon restarting the parse for complex numbers so it doesn't carry through to the imaginary part.dec_neg
gets applied to the real part before moving on to the imaginary, so resetting it doesn't change the sign of the real part.Other stuff
Note: The contributions listed here on my fork are at the main branch, the other (doubles-cmath) branch on my fork is for my project, not contributing.
This is my first time contributing to anything! I'm not sure whether to submit this to main or the latest branch.