Calculating modulo with numpy for large integer (>63 bits) sometimes gives incorrect results.
For example:
import numpy
numpy.mod(12345678912345679000, 3)
numpy.mod(12345678912345679001, 3)
numpy.mod(12345678912345679002, 3)
all give the result of 1.0
. Note that there is no 8
between the second 7
and 9
.
This could be due to the int being larger than 63 bits.
However, sometimes the correct results are outputted.
For example,
numpy.mod(123456789123456789100, 3)
numpy.mod(123456789123456789101, 3)
numpy.mod(123456789123456789102, 3)
give the correct results of 1
, 2
, and 0
, respectively. Note these new ints are 3 bits longer than before with the addition of 8
between the second 7
and 9
.
Any idea why numpy.mod would have this behavior and how can I work with large ints (>63 bits) in a consistent manner with numpy?
Thanks in advance!
I'm running Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on 64-bit windows with numpy v1.18.1.