|
Class: Infinity
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--Number
|
+--MetaNumber
|
+--Infinity
|
+--Infinity::NegativeInfinity
|
+--Infinity::PositiveInfinity
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.33
date: 2023/09/16 09:16:51
- user: cg
- file: Infinity.st directory: libbasic
- module: stx stc-classLibrary: libbasic
I have two instances representing positive and negative infinity.
These are singletons used by non-floats (which have individual Inf representations).
Claus: fixed some minor bugs (args to errorUndefinedResult:) and some wrong comments.
Changed retry:coercing: to match ST/X's way of doing this
Instance Variables :-
copyrightThis is a Manchester Goodie. It is distributed freely on condition
that you observe these conditions in respect of the whole Goodie, and on
any significant part of it which is separately transmitted or stored:
* You must ensure that every copy includes this notice, and that
source and author(s) of the material are acknowledged.
* These conditions must be imposed on anyone who receives a copy.
* The material shall not be used for commercial gain without the prior
written consent of the author(s).
For more information about the Manchester Goodies Library (from which
this file was distributed) send e-mail:
To: goodies-lib@cs.man.ac.uk
Subject: help
This is an additional goody-class, which is NOT covered by the
ST/X license. It has been packaged with the ST/X distribution to
make your live easier instead. NO WARRANTY.
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.
class initialization
-
initialize
-
initialize my two singleton instances
Usage example(s):
errors
-
errorUndefinedResult: messageSelector from: aReceiver
-
instance creation
-
negative
-
Return the unique instance of negative infinity
Usage example(s):
Infinity negative negated
Infinity negative abs
Infinity positive = Float infinity
Infinity negative = Float negativeInfinity
Infinity negative = Float infinity
|
-
negative: aBoolean
-
Return either instance of negative infinity
-
new
-
only my two singleton instances are allowed;
get either via Infinity positive or Infinity negative
-
positive
-
Return the unique instance of positive infinity
queries
-
isAbstract
-
Return if this class is an abstract class.
True is returned here for myself only; false for subclasses.
Abstract subclasses must redefine this again.
arithmetic
-
* aNumber
-
Multiply the receiver by the argument and answer with the result.
-
+ aNumber
-
Add the receiver and the argument and answer with the result.
-
- aNumber
-
Subtract aNumber from the receiver and answer the result.
-
/ aNumber
-
Divide the receiver by the argument and answer the result.
coercing & converting
-
generality
-
Infinities are more general than scalars, but not more general than
vectors (e.g. Points)
comparing
-
< 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
Usage example(s):
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
-
Positive infinity is greater than any number other than positive infinity.
Analogously, negative infinity is less than any other number other
than negative infinity
Usage example(s):
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
|
double dispatching
-
differenceFromSomeNumber: aNumber
-
Sent from aNumber-self, if aNumber does not know how to handle this
-
equalFromSomeNumber: aNumber
-
Sent from aNumber = self, if aNumber does not know how to handle this.
Return true if aNumber = self.
-
lessFromSomeNumber: aNumber
-
Sent from aNumber < self, if aNumber does not know how to handle this.
Return true if aNumber < self.
-
productFromSomeNumber: aNumber
-
Sent from aNumber*self, if aNumber does not know how to handle this
-
quotientFromSomeNumber: aNumber
-
Return the quotient of the argument, aNumber and the receiver.
Sent when aNumber does not know how to divide by the receiver.
-
sumFromSomeNumber: aNumber
-
Sent from aNumber+self, if aNumber does not know how to handle this
errors
-
errorUndefinedResult: messageSelector
-
testing
-
isFinite
-
return true, if the receiver is a finite float (not NaN and not +/-INF)
-
isInfinite
-
return true, if the receiver is an infinite number (+Inf or -Inf)
NegativeInfinity
PositiveInfinity
1 + Infinity positive
Infinity positive + 1
Infinity positive + Infinity positive
Infinity negative - 1
Infinity negative + Infinity negative
Infinity negative + Infinity negative
Infinity negative negated
Infinity positive negated
Infinity positive > Infinity negative
Infinity negative > Infinity positive
Infinity negative + Infinity positive -> raises an error
Infinity negative - Infinity negative -> raises an error
|