Fraction.st
changeset 4593 1023fa0c779e
parent 3984 45a76e2f4236
child 4594 eb09f567a3bc
--- a/Fraction.st	Thu Aug 12 10:53:26 1999 +0200
+++ b/Fraction.st	Thu Aug 12 10:56:06 1999 +0200
@@ -10,8 +10,6 @@
  hereby transferred.
 "
 
-'From Smalltalk/X, Version:3.4.1 on 13-feb-1998 at 15:52:22'                    !
-
 Number subclass:#Fraction
 	instanceVariableNames:'numerator denominator'
 	classVariableNames:'FractionOne FractionZero'
@@ -476,6 +474,30 @@
     ^ self retry:#> coercing:aNumber
 
     "Modified: 5.11.1996 / 10:31:28 / cg"
+!
+
+hash
+    "return a number for hashing; redefined, since fractions compare
+     by numeric value (i.e. (9/3) = 3), therefore (9/3) hash must be the same
+     as 3 hash.
+     Ideally, I should return the same hash value as a corresponding float,
+     i.e. (1/2) hash = 0.5 hash - but that seems to be too complicated
+     (any idea ?)"
+
+    (denominator = 1) ifTrue:[^ numerator hash].
+
+    ^ denominator hash bitXor: numerator hash
+
+    "
+     3 hash           
+     (9/3) hash       
+     3.0 hash         
+     (1/2) hash       
+     0.0 hash         
+     0.5 hash         
+     0.25 hash         
+     0.4 hash         
+    "
 ! !
 
 !Fraction methodsFor:'double dispatching'!
@@ -702,6 +724,6 @@
 !Fraction class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.44 1999-02-14 11:15:07 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.45 1999-08-12 08:56:06 cg Exp $'
 ! !
 Fraction initialize!