Float.st
changeset 92 0c73b48551ac
parent 88 81dacba7a63a
child 131 39599c151f30
--- a/Float.st	Sun Jul 10 00:59:39 1994 +0200
+++ b/Float.st	Fri Aug 05 02:55:07 1994 +0200
@@ -20,6 +20,8 @@
 Float comment:'
 COPYRIGHT (c) 1988 by Claus Gittinger
               All Rights Reserved
+
+$Header: /cvs/stx/stx/libbasic/Float.st,v 1.16 1994-08-05 00:54:50 claus Exp $
 '!
 
 !Float class methodsFor:'documentation'!
@@ -40,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/Float.st,v 1.15 1994-06-02 16:20:22 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Float.st,v 1.16 1994-08-05 00:54:50 claus Exp $
 "
 !
 
@@ -69,7 +71,7 @@
 
     Class Variables:
 
-	LastErrorNumber	<Integer>	value of errno (after a trig- or other math err)
+        LastErrorNumber <Integer>       value of errno (after a trig- or other math err)
 "
 ! !
 
@@ -360,6 +362,42 @@
 %}
 .
     ^ self retry:#~= coercing:aNumber
+!
+
+hash
+    "return a number for hashing; redefined, since floats compare
+     by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same
+     as 3 hash."
+
+    |i idx|
+
+    (self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[
+        i := self asInteger.
+        self = i ifTrue:[
+            ^ i hash
+        ].
+    ].
+
+    "
+     mhmh take my value-bits to hash on
+    "
+    idx := self basicSize.
+    ^ (((self basicAt:idx) bitAnd:16r3F) bitShift:24) +
+      ((self basicAt:idx-1) bitShift:16) +
+      ((self basicAt:idx-2) bitShift:8) +
+      (self basicAt:idx-3)
+
+    "
+     3 hash       
+     3.0 hash
+     3.1 hash  
+     3.14159 hash  
+     31.4159 hash 
+     3.141591 hash 
+     1.234567890123456 hash  
+     1.234567890123457 hash   
+     Set withAll:#(3 3.0 99 99.0 3.1415)
+    "
 ! !
 
 !Float methodsFor:'coercion and converting'!
@@ -772,7 +810,7 @@
     Float storeBinaryIEEEDouble:self on:stream.
 ! !
 
-!Float methodsFor:'printing and storing'!
+!Float methodsFor:'printing & storing'!
 
 printString
     "return a printed representation of the receiver"