--- a/Infinity.st Wed Aug 13 12:47:17 2003 +0200
+++ b/Infinity.st Wed Aug 13 13:15:10 2003 +0200
@@ -21,7 +21,7 @@
"{ Package: 'stx:libbasic' }"
MetaNumber subclass:#Infinity
- instanceVariableNames:'positive'
+ instanceVariableNames:''
classVariableNames:'InfNeg InfPos'
poolDictionaries:''
category:'Magnitude-Numbers'
@@ -89,7 +89,7 @@
examples
"
- 1 + Infinity positive
+ 1 + Infinity positive
Infinity positive + 1
Infinity positive + Infinity positive
@@ -97,31 +97,35 @@
Infinity negative + Infinity negative
Infinity negative + Infinity negative
- Infinity negative negated
- Infinity positive negated
+ Infinity negative negated
+ Infinity positive negated
- Infinity positive > Infinity negative
- Infinity negative > Infinity positive
+ Infinity positive > Infinity negative
+ Infinity negative > Infinity positive
+
+ Infinity negative + Infinity positive -> raises an error
+ Infinity negative - Infinity negative -> raises an error
+
"
!
info
"
- NAME infinity
- AUTHOR manchester
- FUNCTION Provides a class of infinities
- ST-VERSION 2.2
- PREREQUISITES
- CONFLICTS
- DISTRIBUTION world
- VERSION 1
- DATE 22 Jan 1989
-SUMMARY
-This is a set of changes that implements infinity in the Number hierarchy.
-I obtained the original changes from the author of an article in comp.lang.smalltalk.
-I have just installed it in my image and I have found two small omissions
-which are corrected in what is below; there might be others. Arithmetic
-between infinities is not defined but magnitude comparisons are implemented.
+ NAME infinity
+ AUTHOR manchester
+ FUNCTION Provides a class of infinities
+ ST-VERSION 2.2
+ PREREQUISITES
+ CONFLICTS
+ DISTRIBUTION world
+ VERSION 1
+ DATE 22 Jan 1989
+ SUMMARY
+ This is a set of changes that implements infinity in the Number hierarchy.
+ I obtained the original changes from the author of an article in comp.lang.smalltalk.
+ I have just installed it in my image and I have found two small omissions
+ which are corrected in what is below; there might be others. Arithmetic
+ between infinities is not defined but magnitude comparisons are implemented.
"
! !
@@ -130,7 +134,7 @@
negative
"Return the unique instance of negative infinity"
- ^NegativeInfinity
+ ^InfNeg
!
new
@@ -140,16 +144,18 @@
positive
"Return the unique instance of positive infinity"
- ^PositiveInfinity
+ ^InfPos
! !
!Infinity class methodsFor:'class initialization'!
initialize
- "Infinity initialize"
+ InfPos := PositiveInfinity basicNew.
+ InfNeg := NegativeInfinity basicNew.
- PositiveInfinity := self basicNew.
- NegativeInfinity := NegativeInfinity basicNew.
+ "
+ Infinity initialize
+ "
! !
!Infinity methodsFor:'arithmetic'!
@@ -219,19 +225,83 @@
!Infinity methodsFor:'comparing'!
< aNumber
- "Positive infinity is greater than any number than positive infinity.
+ "Positive infinity is greater than any number other than positive infinity.
Analogously, negative infinity is less than any other number other
than negative infinity"
- aNumber = self ifTrue: [^false].
+ aNumber == self ifTrue: [^false].
^ self positive not
+
+ "
+ Infinity positive < 0
+ Infinity positive < 1000
+ Infinity positive < -1000
+
+ Infinity positive < Infinity positive
+ Infinity positive < Infinity negative
+
+ 0 < Infinity positive
+ 1000 < Infinity positive
+ -1000 < Infinity positive
+ Infinity negative < Infinity positive
+
+ Infinity negative < 0
+ Infinity negative < 1000
+ Infinity negative < -1000
+
+ Infinity negative < Infinity negative
+ Infinity negative < Infinity positive
+
+ 0 < Infinity negative
+ 1000 < Infinity negative
+ -1000 < Infinity negative
+ Infinity negative < Infinity positive
+ "
!
= aNumber
"return true, if the argument represents the same numeric value
as the receiver, false otherwise."
- ^ aNumber = self
+ aNumber == self ifTrue:[^ true].
+ "could be another infinity..."
+ aNumber isFinite ifTrue:[^ false].
+ ^ aNumber sign == self sign
+!
+
+> aNumber
+ "Positive infinity is greater than any number other than positive infinity.
+ Analogously, negative infinity is less than any other number other
+ than negative infinity"
+
+ aNumber == self ifTrue: [^false].
+ ^ self positive
+
+ "
+ Infinity positive > 0
+ Infinity positive > 1000
+ Infinity positive > -1000
+
+ Infinity positive > Infinity positive
+ Infinity positive > Infinity negative
+
+ 0 > Infinity positive
+ 1000 > Infinity positive
+ -1000 > Infinity positive
+ Infinity negative > Infinity positive
+
+ Infinity negative > 0
+ Infinity negative > 1000
+ Infinity negative > -1000
+
+ Infinity negative > Infinity negative
+ Infinity negative > Infinity positive
+
+ 0 > Infinity negative
+ 1000 > Infinity negative
+ -1000 > Infinity negative
+ Infinity negative > Infinity positive
+ "
! !
!Infinity methodsFor:'double dispatching'!
@@ -244,7 +314,11 @@
lessFromSomeNumber:aNumber
"Sent from aNumber < self, if aNumber does not know how to handle this"
-self halt.
+
+ aNumber isFinite ifTrue:[
+ ^ self positive.
+ ].
+
^ Number
raise: #undefinedResultSignal
receiver: self
@@ -351,7 +425,7 @@
!Infinity class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Infinity.st,v 1.11 2003-07-02 09:52:46 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Infinity.st,v 1.12 2003-08-13 11:15:10 cg Exp $'
! !
Infinity initialize!