Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0006601 [Squeak] Kernel minor always 08-10-07 15:18 04-18-10 21:58
Reporter tween View Status public  
Assigned To nicolas cellier
Priority normal Resolution fixed  
Status closed   Product Version 3.10
Summary 0006601: Float hash incorrect ( 2=2.0 , but 2 hash~=2.0 hash)
Description 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
Additional Information
Attached Files

- Relationships

SYSTEM WARNING: Creating default object from empty value

SYSTEM WARNING: Creating default object from empty value

related to 0003360closed nicolas cellier hash and equal problem 
related to 0003374closed nicolas cellier Arithmetic equality should be transitive 

- Notes
(0010971 - 75 - 81 - 81 - 81 - 81 - 81)
tween
08-10-07 15:38

This seems to have automatically assigned itself to Ken.
I don't know why.
 
(0010972 - 149 - 289 - 289 - 289 - 289 - 289)
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 - 62 - 62 - 62 - 62 - 62 - 62)
KenCausey
08-10-07 19:40

It was assigned to me because you failed to choose a category.
 
(0010974 - 176 - 200 - 318 - 318 - 318 - 318)
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 - 230 - 242 - 396 - 396 - 396 - 396)
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 - 197 - 221 - 477 - 477 - 477 - 477)
nicolas cellier
09-12-07 20:46
edited on: 09-12-07 20:48

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 - 1110 - 1420 - 1420 - 1688 - 1688 - 1688)
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 - 69 - 117 - 117 - 117 - 117 - 117)
nicolas cellier
01-04-09 22:43

"fix begin"
Installer mantis ensureFix: 3374.
"fix test"
"fix end"
 
(0013511 - 9 - 9 - 9 - 100 - 100 - 100)
nicolas cellier
02-13-10 04:21

See 0003374
 

- Issue History
Date Modified Username Field Change
08-10-07 15:18 tween New Issue
08-10-07 15:18 tween Status new => assigned
08-10-07 15:18 tween Assigned To  => KenCausey
08-10-07 15:38 tween Note Added: 0010971
08-10-07 17:48 tween Note Added: 0010972
08-10-07 19:40 KenCausey Note Added: 0010973
08-10-07 19:40 KenCausey Assigned To KenCausey =>
08-10-07 19:40 KenCausey Category Any => Kernel
08-10-07 19:41 KenCausey Note Added: 0010974
08-10-07 20:15 tween Note Added: 0010975
09-12-07 20:46 nicolas cellier Note Added: 0011120
09-12-07 20:48 nicolas cellier Note Edited: 0011120
09-25-07 01:13 matthewf Relationship added related to 0003360
09-25-07 01:13 matthewf Relationship added related to 0003374
09-25-07 01:15 matthewf Status assigned => new
01-04-09 22:06 nicolas cellier Note Added: 0012891
01-04-09 22:43 nicolas cellier Note Added: 0012896
01-10-09 02:00 Keith_Hodges Status new => pending
02-13-10 04:21 nicolas cellier Status pending => resolved
02-13-10 04:21 nicolas cellier Fixed in Version  => trunk
02-13-10 04:21 nicolas cellier Resolution open => fixed
02-13-10 04:21 nicolas cellier Assigned To  => nicolas cellier
02-13-10 04:21 nicolas cellier Note Added: 0013511
04-18-10 21:58 andreas Status resolved => closed


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
92 total queries executed.
57 unique queries executed.
Powered by Mantis Bugtracker