ArithmeticValue.st
changeset 16657 a87789caf59d
parent 16121 7b441c381015
child 17038 e5e3568f805e
--- a/ArithmeticValue.st	Mon Jun 30 16:15:03 2014 +0200
+++ b/ArithmeticValue.st	Mon Jun 30 16:15:35 2014 +0200
@@ -470,6 +470,37 @@
     self error:'retry:coercing: oops - same generality; retry should not happen'
 
     "Modified: 5.11.1996 / 15:03:38 / cg"
+!
+
+retry:aSymbol coercing:aNumber with:anArgument
+    "arithmetic represented by the binary operator, aSymbol,
+     could not be performed with the receiver and the argument, aNumber,
+     because of the differences in representation.
+     Coerce either the receiver or the argument, depending on which has higher
+     generality, and try again.
+     If the operation is compare for same value (=), return false if
+     the argument is not a Number.
+     If the generalities are the same, create an error message, since this
+     means that a subclass has not been fully implemented."
+
+    |hasGenerality myGenerality otherGenerality|
+
+    hasGenerality := aNumber respondsTo:#generality.
+    hasGenerality ifFalse:[
+        ^ self error:'retry:coercing: argument is not a number'.
+    ].
+
+    myGenerality := self generality.
+    otherGenerality := aNumber generality.
+    (myGenerality > otherGenerality) ifTrue:[
+        ^ self perform:aSymbol with:(self coerce:aNumber) with:anArgument
+    ].
+    (myGenerality < otherGenerality) ifTrue:[
+        ^ (aNumber coerce:self) perform:aSymbol with:aNumber with:anArgument
+    ].
+    self error:'retry:coercing: oops - same generality; retry should not happen'
+
+    "Modified: 5.11.1996 / 15:03:38 / cg"
 ! !
 
 !ArithmeticValue methodsFor:'converting'!
@@ -785,6 +816,20 @@
     "Created: / 09-08-2010 / 19:49:26 / cg"
 !
 
+isAlmostEqualToFromFloat:aFloat nEpsilon:nE
+    "the receiver does not know how to compare to a short float -
+     retry the operation by coercing to higher generality"
+
+    ^ aFloat retry:#isAlmostEqualTo:nEpsilon: coercing:self with:nE
+!
+
+isAlmostEqualToFromShortFloat:aShortFloat nEpsilon:nE
+    "the receiver does not know how to compare to a short float -
+     retry the operation by coercing to higher generality"
+
+    ^ aShortFloat retry:#isAlmostEqualTo:nEpsilon: coercing:self with:nE
+!
+
 lessFromFixedPoint:aFixedPoint
     "the receiver does not know how to compare to a fixedPoint number -
      retry the operation by coercing to higher generality"
@@ -1362,11 +1407,11 @@
 !ArithmeticValue class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.93 2014-02-23 18:18:50 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.94 2014-06-30 14:15:35 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.93 2014-02-23 18:18:50 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.94 2014-06-30 14:15:35 stefan Exp $'
 ! !