--- a/Number.st Wed Aug 14 15:47:47 1996 +0200
+++ b/Number.st Thu Aug 15 11:12:28 1996 +0200
@@ -39,6 +39,10 @@
[author:]
Claus Gittinger
+
+ [see also:]
+ Integer LargeInteger SmallInteger
+ LimitedPrecisionReal Float ShortFloat
"
! !
@@ -225,6 +229,38 @@
"return the generality value - see ArithmeticValue>>retry:coercing:"
^ 40
+!
+
+retry: aSymbol coercing: aNumber
+ "Arithmetic represented by the symbol, 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 symbol is the equals sign, answer false if the argument
+ is not a Number. If the generalities are the same, create an error message."
+
+ |myGenerality otherGenerality|
+
+ (aSymbol == #=) ifTrue:[
+ (aNumber respondsTo:#generality) ifFalse:[^ false]
+ ] ifFalse:[
+ (aNumber respondsTo:#generality) ifFalse:[
+ self error:'retry:coercing: argument is not a number'.
+ ^ self
+ ]
+ ].
+ myGenerality := self generality.
+ otherGenerality := aNumber generality.
+ (myGenerality > otherGenerality) ifTrue:[
+ ^ self perform:aSymbol with:(self coerce:aNumber)
+ ].
+ (myGenerality < otherGenerality) ifTrue:[
+ aNumber isInfinite ifTrue: [
+ ^ aNumber retryReverseOf:aSymbol with:self
+ ].
+ ^ (aNumber coerce:self) perform:aSymbol with:aNumber
+ ].
+ self error:'retry:coercing: oops - same generality'
! !
!Number methodsFor:'converting'!
@@ -435,6 +471,12 @@
!Number methodsFor:'testing'!
+isFinite
+ ^true!
+
+isInfinite
+ ^false!
+
isLiteral
"return true, if the receiver can be used as a literal
(i.e. can be used in constant arrays)"
@@ -459,5 +501,5 @@
!Number class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.33 1996-07-18 10:40:57 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Number.st,v 1.34 1996-08-15 09:12:28 cg Exp $'
! !