Jupyter Notebooks incorrectly calculating numpy conjugation to a power

Question:

I happened upon some error in my Jupyter Notebook that I can’t explain. I have the following code.

import numpy as np
c = 100
c_conj = np.conjugate(c)
print(c == c_conj)
print(c**5 == c_conj**5)

Resulting in the output

True
False

I get the same result for JupyterLite (the online Jupyter Notebook software). Alternatively, if I run the same code on any other platform (e.g. Google Collab), I get the output

True
True

Is this user error? Is there a way to explain this?

Answers:

numpy.conjugate(100) returns a numpy.int_ instance, not a plain Python int. numpy.int_ corresponds to C long. On the platforms where the comparison evaluated to False, C long is 32 bits, and the c_conj**5 computation overflowed.

Answered By: user2357112