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

Syntax error dependent on size of number #306

Open
jneb opened this issue Feb 3, 2023 · 2 comments
Open

Syntax error dependent on size of number #306

jneb opened this issue Feb 3, 2023 · 2 comments

Comments

@jneb
Copy link

jneb commented Feb 3, 2023

How about this one:

>>> 4 ** 300 == 8 ** 200
True
>>> 4 ** 300 is 8 ** 200
False

>>> 4 ** 30 is 8 ** 20
SyntaxWarning: "is" with a literal. Did you mean "=="?
  4 ** 30 is 8 ** 20
True
@nifadyev
Copy link
Contributor

Hey @jneb , could you please write the explanation and make a PR? If it is possible, of course

@jneb
Copy link
Author

jneb commented Oct 16, 2024

To be honest, I have no idea. I thought it had to do with the size of the left operand, but I'm flabbergasted by this:
Just checking:

>>> (1<<128)-(1<<124) == 15<<124
True

Difference between two expressions with same value:

>>> 15<<124 is 8**300
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False
>>> (1<<128)-(1<<124) is 8**300
False

But it's also not the form of the expression, because making it a bit smaller raises the warning again:

>>> (1<<127)-(1<<124) is 8**300
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False

All I know is that there's something about the left operand. Smaller send to produce the warning, but there's more behind it.
I'll have to check the source...

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

2 participants