SYSTEM WARNING: Creating default object from empty value

SYSTEM WARNING: Creating default object from empty value

Mantis - Squeak
Viewing Issue Advanced Details
6601 Kernel minor always 08-10-07 15:18 04-18-10 21:58
tween  
nicolas cellier  
normal  
closed 3.10  
fixed  
none    
none trunk  
0006601: Float hash incorrect ( 2=2.0 , but 2 hash~=2.0 hash)
Since 2 = 2.0 ,
(2 hash) should equal (2.0 hash).

2 hash -> 2
2.0 hash -> 0

Should the fix be something like this? (in Float>>#hash)..

   self fractionPart = 0.0 ifTrue:[^self truncated hash].
   ^ (((self basicAt: 1) bitAnd: 16r00FFFF00) +
      ((self basicAt: 2) bitAnd: 16r00FFFF00)) bitShift: -8
related to 0003360closed nicolas cellier hash and equal problem 
related to 0003374closed nicolas cellier Arithmetic equality should be transitive 

Notes
(0010971)
tween   
08-10-07 15:38   
This seems to have automatically assigned itself to Ken.
I don't know why.
(0010972)
tween   
08-10-07 17:48   
here are some other Number examples...

    (1/2) = 0.5 -> true
    (1/2) hash = 0.5 hash -> false

    10s0 = 10 -> true
    10s0 hash = 10 hash -> false
(0010973)
KenCausey   
08-10-07 19:40   
It was assigned to me because you failed to choose a category.
(0010974)
KenCausey   
08-10-07 19:41   
Also, if you have any hope of getting this into 3.10 you will want to add this to

http://wiki.squeak.org/squeak/5934 [^]

and probably also package it as a .cs.gz with a test.
(0010975)
tween   
08-10-07 20:15   
It seems that Float hash issues were discussed back in 1997. Also the question of whether 'equal' Objects should _always_ have equal hash values. See the thread started by...

http://www.create.ucsb.edu/squeak/9705.html#Letter33 [^]
(0011120)
nicolas cellier   
09-12-07 20:46   
See also http://bugs.squeak.org/view.php?id=3360 [^]

and http://bugs.squeak.org/view.php?id=3374 [^] where you can see nice properties of Smalltalk number equality and draw some conclusions on hash...

(0012891)
nicolas cellier   
01-04-09 22:06   
I like the proposed fix:
    self fractionPart = 0.0 ifTrue:[^self truncated hash].

It does not work because Float infinity will raise an Error, but with help of 0006983 :
    (self isFinite and: [self fractionPart = 0.0]) ifTrue:[^self truncated hash].

That does not spoil efficiency to much, except for large Floats, because they all have fractionPart = 0.0 and will trigger slow LargeInteger algorithms...
Is this a problem ?
I bet no because huge numbers are very rare...

Float allInstances size. "5107"
Float allInstances count: [:f | f isFinite and: [f truncated class ~= SmallInteger]]. "33"


Then, for fraction we'd better change hash to fit Float like this:

| tmp |
tmp := self asFloat.
tmp isFinite ifTrue: [^tmp hash].
^numerator hash bitXor: denominator hash

And if equality is based on exactness - see 0003374

| tmp |
denominator isPowerOfTwo ifTrue: [
    "If denominator is not a power of two, I cannot be exactly equal to a Float"
    tmp := self asFloat.
    tmp isFinite ifTrue: [^tmp hash]].
^numerator hash bitXor: denominator hash

See 0003374 for changeSet
(0012896)
nicolas cellier   
01-04-09 22:43   
"fix begin"
Installer mantis ensureFix: 3374.
"fix test"
"fix end"
(0013511)
nicolas cellier   
02-13-10 04:21   
See 0003374