Skip to content

inconsistent integer hashing on 64bit systems with python 2.7 #11986

@kiwifb

Description

@kiwifb

With python 2.7 integer hashing is broken on 64bit systems in a similar way than [
#4957 comment:3] in #4957 which was fixed 3 years ago. The following tests

sage -t -long -force_lib "devel/sage-main/sage/rings/padics/padic_capped_relative_element.pyx"
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/padics/padic_capped_relative_element.pyx", line 2339:
    sage: hash(R(-1)) 
Expected:
    95367431640624
Got:
    1977800240
**********************************************************************

and (which is reminiscent of #4957):

sage -t -long -force_lib "devel/sage-main/sage/rings/integer.pyx"
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/integer.pyx", line 3046:
    sage: n = -920390823904823094890238490238484; n.__hash__()
Expected:
    6874330978542788722   
Got:
    -2623069716
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/integer.pyx", line 3061:
    sage: hash(n)
Expected:
    -9223372036854767616      
Got:
    8192
**********************************************************************
File "/usr/share/sage/devel/sage-main/sage/rings/integer.pyx", line 3064:
    sage: hash(n) == hash(int(n))
Expected:
    True
Got:
    False
**********************************************************************

On my 64bit system with python-2.7:

sage: n=2^63+2^13
sage: n
9223372036854784000
sage: hash(n)
8192
sage: int(n)
9223372036854784000L
sage: hash(int(n))
-9223372036854767616

Depends on #9958

Component: c_lib

Author: Jeroen Demeyer

Reviewer: François Bissey

Merged: sage-5.0.beta0

Issue created by migration from https://trac.sagemath.org/ticket/11986

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions