[Numpy-discussion] float64 / int comparison different from float / int comparison

Stéfan van der Walt stefan at sun.ac.za
Mon Oct 31 20:59:26 EDT 2011


On Mon, Oct 31, 2011 at 11:23 AM, Matthew Brett <matthew.brett at gmail.com> wrote:
> In [8]: np.float(2**63) == 2**63
> Out[8]: True
>
> In [9]: np.float(2**63) > 2**63-1
> Out[9]: True
>
> In [10]: np.float64(2**63) == 2**63
> Out[10]: True
>
> In [11]: np.float64(2**63) > 2**63-1
> Out[11]: False
>
> In [16]: np.float64(2**63-1) == np.float(2**63-1)
> Out[16]: True

Interesting.  Turns out that np.float(x) returns a Python float
object.  If you change the experiment to only use numpy array scalars,
things are more consistent:

In [36]: np.array(2**63, dtype=np.float) > 2**63 - 1
Out[36]: False

In [37]: np.array(2**63, dtype=np.float32) > 2**63 - 1
Out[37]: False

In [38]: np.array(2**63, dtype=np.float64) > 2**63 - 1

Regards
Stéfan



More information about the NumPy-Discussion mailing list