|
|
Class: Integer
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--Number
|
+--Integer
|
+--LargeInteger
|
+--SmallInteger
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.246
date: 2010/04/13 16:11:42
- user: cg
- file: Integer.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
abstract superclass for all integer numbers.
See details in concrete subclasses LargeInteger and SmallInteger.
Mixed mode arithmetic:
int op int -> int
int op fix -> fix; scale is fix's scale
int op fraction -> fraction
int op float -> float
[Class variables:]
DefaultDisplayRadix the radix in which integers present their
displayString (which is used in inspectors)
If you are to look at many hex numbers, bitmasks
etc. you may set this to 2 or 16.
(avoids typing printStringRadix:.. all the time
- I know - I am lazy ;-). Default is 10.
Number
LargeInteger
SmallInteger
Float
ShortFloat
Fraction
FixedPoint
Compatibility-Squeak
-
readFrom: aStringOrStream base: aBase
-
for squeak compatibility
Signal constants
-
bcdConversionErrorSignal
-
return the signal which is raised when bcd conversion fails
(i.e. when trying to decode an invalid BCD number)
class initialization
-
initialize
-
constants
-
epsilon
-
return the maximum relative spacing
-
unity
-
return the neutral element for multiplication (1)
-
zero
-
return the neutral element for addition (0)
instance creation
-
byte1: b1 byte2: b2 byte3: b3 byte4: b4
-
Squeak compatibility:
Return an Integer given four value bytes.
The returned integer is either a Small- or a LargeInteger
-
fastFromString: aString at: startIndex
-
return the next unsigned Integer from the string
as a decimal number, starting at startIndex.
The number must be in the native machines int range
(i.e. 63bit on alpha / 31 on all others);
However, for portability, only use it for 31bit numbers.
No spaces are skipped.
This is a specially tuned entry (using a low-level C-call), which
returns garbage if the argument string is not a small integer number.
It has been added to allow high speed string decomposition into numbers,
especially for mass-data.
-
fromBCDBytes: aByteArray
-
given a byteArray in BCD format, return an appropriate integer.
The byteArray must contain the BCD encoded decimal string,
starting with the most significant digits.
This conversion is useful for some communication protocols,
or control systems, which represent big numbers this way...
-
fromSwappedBCDBytes: aByteArray
-
given a byteArray in BCD format, return an appropriate integer.
The byteArray must contain the BCD encoded decimal string,
starting with the LEAST significant digits.
This conversion is useful for some communication protocols,
or control systems (e.g. SMC), which represent big numbers this way...
-
new: numberOfBytes neg: negative
-
for ST-80 compatibility:
Return an empty Integer (uninitialized value) with space for
numberOfBytes bytes (= digitLength). The additional argument
negative specifies if the result should be a negative number.
The digits can be stored byte-wise into the result, using digitAt:put:
-
readFrom: aStringOrStream
-
return the next unsigned Integer from the (character-)stream aStream
as decimal number.
NOTICE:
This behaves different from the default readFrom:, in returning
0 (instead of raising an error) in case no number can be read.
It is unclear, if this is the correct behavior (ST-80 does this)
- depending on the upcoming ANSI standard, this may change.
-
readFrom: aStringOrStream onError: exceptionBlock
-
return the next Integer from the (character-)stream aStream,
handling initial XXr for arbitrary radix numbers and initial sign.
Also, all initial whitespace is skipped.
If the string does not represent a valid integer number,
return the value of exceptionBlock.
-
readFrom: aStringOrStream radix: radix
-
return the next unsigned Integer from the (character-)stream aStream
in radix; (assumes that the initial XXr has already been read).
No whitespace-skipping is done.
Returns 0 if no number available.
NOTICE:
This behaves different from the default readFrom:, in returning
0 (instead of raising an error) in case no number can be read.
It is unclear, if this is the correct behavior (ST-80 does this)
- depending on the upcoming ANSI standard, this may change.
-
readFrom: aStringOrStream radix: radix onError: exceptionBlock
-
return the next unsigned Integer from the (character-)stream aStream
in radix; (assumes that the initial XXr has already been read).
No whitespace-skipping is done.
Returns the value of exceptionBlock, if no number is available.
-
readFromRomanString: aStringOrStream
-
convert a string or stream containing a roman representation into an integer.
Raises a RomanNumberFormatError, if the inputs format is completely wrong.
Raises BadRomanNumberFormatError if its wrong, but could be parsed.
Notifies via NaiveRomanNumberFormatNotification, if its a bit wrong (naive format).
Will read both real and naive roman numbers (see printRomanOn: vs. printRomanOn:naive:),
however, a notification is raised for for naive numbers (catch it if you are interested in it).
-
readFromRomanString: aStringOrStream onError: exceptionalValue
-
convert a string or stream containing a roman representation into an integer.
Raises an exception, if the inputs format is wrong.
Does allow reading of naive (more than 3 in a row) and
bad (not using L and D) roman numbers.
(Such numbers can be seen on some medevial buildings.
-
readFromString: aString radix: base onError: exceptionBlock
-
misc
-
displayRadix: aNumber
-
being tired of always sending #printStringRadix: in the inspectors,
this allows you to change the default print radix for the displayString
method.
prime numbers
-
flushPrimeCache
-
cleanup after using a primeCache
-
initializePrimeCacheUpTo: limit
-
if many operations are to be done using primes, we can keep them around...
You will need n/8/2 bytes to keep fast info about primes up to n
(i.e. 100Mb is good for primes up to 1.6*10^9)
-
largePrimesUpTo: max do: aBlock
-
Evaluate aBlock with all primes up and including maxValue.
The Algorithm is adapted from http://www.rsok.com/~jrm/printprimes.html
It encodes prime numbers much more compactly than #primesUpTo:
38.5 integer per byte (2310 numbers per 60 byte) allow for some fun large primes.
(all primes up to SmallInteger maxVal can be computed within ~27MB of memory;
the regular #primesUpTo: would require 4 *GIGA*bytes).
Note: The algorithm could be re-written to produce the first primes (which require
the longest time to sieve) faster but only at the cost of clarity.
-
primeCacheSize
-
-
primesUpTo2000
-
primes up to 1000
-
primesUpTo: max
-
Return a list of prime integers up to abd including the given integer.
-
primesUpTo: max do: aBlock
-
Compute aBlock with all prime integers up to and including the given integer.
queries
-
hasSharedInstances
-
return true if this class has shared instances, that is, instances
with the same value are identical.
Although not always shared (LargeIntegers), these should be treated
so, to be independent of the number of bits in a SmallInt
-
isAbstract
-
Return if this class is an abstract class.
True is returned for Integer here; false for subclasses.
Abstract subclasses must redefine again.
Compatibility-Dolphin
-
& aNumber
-
return the bitwise-and of the receiver and the argument, anInteger.
Same as bitAnd: - added for compatibility with Dolphin Smalltalk
-
highWord
-
return the high 16 bits of a 32 bit value
-
lowWord
-
return the low 16 bits of a 32 bit value
-
mask: integerMask set: aBoolean
-
Answer the result of setting/resetting the specified mask in the receiver.
-
printStringRadix: aRadix padTo: sz
-
return a printed representation of the receiver in a given radix,
padded with spaces (at the right) up to size.
If the printString is longer than size,
it is returned unchanged (i.e. not truncated).
See also printStringRadix:size:fill:
-
| aNumber
-
return the bitwise-or of the receiver and the argument, anInteger.
Same as bitOr: - added for compatibility with Dolphin Smalltalk
Compatibility-Squeak
-
asByteArray
-
return my hexBytes in MSB
-
asByteArrayOfSize: size
-
return my hexBytes in MSB, optionally padded at the left with zeros
-
atRandom
-
return a random number between 1 amd myself
-
atRandom: aRandomGenerator
-
return a random number between 1 amd myself
-
printPaddedWith: padChar to: size base: base
-
-
printStringBase: base
-
return my printString in a base;
same as printStringRadix:
-
printStringHex
-
return my printString in base 16;
same as printStringRadix:
-
printStringRoman
-
return my roman printString;
almost the same as romanPrintString:
-
raisedTo: exp modulo: mod
-
Compatibility-V'Age
-
<< aNumber
-
V'Age compatibility: left shift
-
>> aNumber
-
V'Age compatibility: right shift
bcd conversion
-
decodeFromBCD
-
return a number representing the value of the BCD encoded receiver.
-
encodeAsBCD
-
return a BCD encoded number representing the same value as the
receiver.
bit operators
-
allMask: anInteger
-
return true if all 1-bits in anInteger are also 1 in the receiver
-
anyMask: anInteger
-
return true if any 1-bits in anInteger is also 1 in the receiver.
(somewhat incorrect, if the mask is zero)
-
bitAnd: anInteger
-
return the bitwise-and of the receiver and the argument, anInteger.
This is a general and slow implementation, walking over the bytes of
the receiver and the argument.
-
bitAt: index
-
return the value of the index's bit (index starts at 1) as 0 or 1.
Notice: the result of bitAt: on negative receivers is not
defined in the language standard (since the implementation
is free to choose any internal representation for integers)
-
bitClear: anInteger
-
return the bitwise-and of the receiver and the complement of argument, anInteger.
This is a general and slow implementation, walking over the bytes of
the receiver and the argument.
-
bitCount
-
return the number of 1-bits in the receiver
-
bitIndicesOfOneBitsDo: aBlock
-
evaluate aBlock for all indices of a 1-bit, starting with the index of the lowest bit.
The index for the least significant bit is 1.
-
bitIndicesOfOneBitsReverseDo: aBlock
-
evaluate aBlock for all inices of a 1-bit, starting with the index of the highest
and ending with the lowest bit.
The index for the least significant bit is 1.
-
bitInvert
-
return a new integer, where all bits are complemented.
This does not really make sense for negative largeIntegers,
since the digits are stored as absolute value.
Q: is this specified in a language standard ?
-
bitOr: anInteger
-
return the bitwise-or of the receiver and the argument, anInteger.
This is a general and slow implementation, walking over the bytes of
the receiver and the argument.
-
bitShift: shiftCount
-
return the value of the receiver shifted by shiftCount bits;
leftShift if shiftCount > 0; rightShift otherwise.
Notice: the result of bitShift: on negative receivers is not
defined in the language standard (since the implementation
is free to choose any internal representation for integers)
However, ST/X preserves the sign.
-
bitTest: anInteger
-
return true, if any bit from aMask is set in the receiver.
I.e. true, if the bitwise-AND of the receiver and the argument, anInteger
is non-0, false otherwise.
This is a general and slow implementation, walking over the bytes of
the receiver and the argument.
-
bitXor: anInteger
-
return the bitwise-or of the receiver and the argument, anInteger.
This is a general and slow implementation, walking over the bytes of
the receiver and the argument.
-
changeBit: index to: aBooleanOrNumber
-
return a new number where the specified bit is on or off,
depending on aBooleanOrNumber.
Bits are counted from 1 starting with the least significant.
The methods name may be missleading: the receiver is not changed,
but a new number is returned. Should be named #withBit:changedTo:
-
changeMask: mask to: aBooleanOrNumber
-
return a new number where the specified mask-bit is on or off,
depending on aBooleanOrNumber.
The methods name may be missleading: the receiver is not changed,
but a new number is returned. Should be named #withMask:changedTo:
-
clearBit: index
-
return a new integer where the specified bit is off.
Bits are counted from 1 starting with the least significant.
The methods name may be missleading: the receiver is not changed,
but a new number is returned. Should be named #withBitCleared:
-
even
-
return true if the receiver is even
-
highBit
-
return the bitIndex of the highest bit set. The returned bitIndex
starts at 1 for the least significant bit.
Returns 0 if no bit is set.
-
invertBit: index
-
return a new number where the specified bit is inverted.
Bits are counted from 1 starting with the least significant.
The methods name may be missleading: the receiver is not changed,
but a new number is returned. Should be named #withBitInverted:
-
isBitSet: index
-
return true if the index' bit is set; false otherwise.
Bits are counted from 1 starting with the least significant.
-
lowBit
-
return the bitIndex of the lowest bit set. The returned bitIndex
starts at 1 for the least significant bit.
Returns 0 if no bit is set.
-
maskClear: aMask
-
-
maskSet: aMask
-
-
noMask: anInteger
-
return true if no 1-bit in anInteger is 1 in the receiver
-
odd
-
return true if the receiver is odd
-
rightShift: shiftCount
-
return the value of the receiver shifted right by shiftCount bits;
rightShift if shiftCount > 0; leftShift otherwise.
Notice: the result of bitShift: on negative receivers is not
defined in the language standard (since the implementation
is free to choose any internal representation for integers)
However, ST/X preserves the sign.
-
setBit: index
-
return a new integer, where the specified bit is on.
Bits are counted from 1 starting with the least significant.
The methods name may be missleading: the receiver is not changed,
but a new number is returned. Should be named #withBitSet:
byte access
-
byteAt: anIndex
-
compatibility with ByteArrays etc.
-
digitByteLength
-
return the number bytes required for a 2's complement
binary representation of this Integer.
For positive receivers, thats the same as the digitLength.
-
digitBytes
-
return a byteArray filled with the receivers bits
(8 bits of the absolute value per element),
least significant byte is first
** This method raises an error - it must be redefined in concrete classes **
-
digitBytesMSB: msbFlag
-
return a byteArray filled with the receivers bits
(8 bits of the absolute value per element),
if msbflag = true, most significant byte is first,
otherwise least significant byte is first
coercing & converting
-
asFixedPoint
-
return the receiver as a fixedPoint number
-
asFixedPoint: scale
-
return the receiver as fixedPoint number, with the given number
of post-decimal-point digits.
-
asFloat
-
return a Float with same value as myself.
Since floats have a limited precision, you usually loose bits when doing this.
-
asFraction
-
return a Fraction with same value as receiver
-
asInteger
-
return the receiver truncated towards zero -
for integers this is self
-
asLargeFloat
-
return a LargeFloat with same value as myself.
Since largeFloats have a limited precision, you usually loose bits when
doing this.
-
asLongFloat
-
return a LongFloat with same value as myself.
Since longFloats have a limited precision, you usually loose bits when
doing this.
-
asModuloNumber
-
return a precomputed modulo number
-
asShortFloat
-
return a ShortFloat with same value as receiver
-
signExtendedByteValue
-
return a smallInteger from sign-extending the 8'th bit.
May be useful for communication interfaces
-
signExtendedShortValue
-
return a smallInteger from sign-extending the 16'th bit.
May be useful for communication interfaces
comparing
-
hash
-
redefined to return smallInteger hashValues
double dispatching
-
differenceFromFraction: aFraction
-
sent when a fraction does not know how to subtract the receiver, an integer
-
differenceFromTimestamp: aTimestamp
-
I am to be interpreted as seconds, return the timestamp this number of seconds
before aTimestamp
-
equalFromFraction: aFraction
-
that should never be invoked, as fractions are always normalized to integers
if resulting from an arithmetic operation.
However, this implementation is for subclasses (i.e. fixed point) and also
allows comparing unnormalized fractions as might appear within the fraction class
-
productFromFraction: aFraction
-
sent when a fraction does not know how to multiply the receiver, an integer
-
quotientFromFraction: aFraction
-
Return the quotient of the argument, aFraction and the receiver.
Sent when aFraction does not know how to divide by the receiver.
-
sumFromFraction: aFraction
-
sent when a fraction does not know how to add the receiver, an integer
-
sumFromTimestamp: aTimestamp
-
I am to be interpreted as seconds, return the timestamp this number of seconds
after aTimestamp
helpers
-
gcd_helper: anInteger
-
a helper for the greatest common divisor of the receiver and anInteger.
Knuth's algorithm for large positive integers, with receiver being
larger than the arg.
inspecting
-
inspectorExtraAttributes
-
extra (pseudo instvar) entries to be shown in an inspector.
iteration
-
to: stop collect: aBlock
-
syntactic sugar;
same as (self to:stop) collect:aBlock
misc math
-
acker: n
-
return the value of acker(self, n).
;-) Do not try with receivers > 3
-
binco: kIn
-
-
binomialCoefficient: kIn
-
The binomial coefficient
/ n \ with self being n, and 0 <= k <= n.
\ k /
is the number of ways of picking k unordered outcomes from n possibilities,
also known as a combination or combinatorial number.
Sometimes also called C(n,k) (for choose k from n)
binCo is defined as:
n!
----------
k! (n-k)!
but there is a faster, recursive formula:
/ n \ = / n - 1 \ + / n - 1 \
\ k / \ k - 1 / \ k /
with:
/ n \ = / n \ = 1
\ 0 / \ n /
-
divMod: aNumber
-
return an array filled with self // aNumber and
self \\ aNumber.
The result is only defined for positive receiver and argument.
This may be redefined in some integer classes for
more performance (where the remainder is generated as a side effect of division)
-
extendedEuclid: tb
-
return the solution of 'ax + by = gcd(a,b)'.
An array containing x, y and gcd(a,b) is returned.
-
factorial
-
return fac(self) (i.e. 1*2*3...*self) using an iterative algorithm.
This is slightly faster than the recursive algorithm, and does not
suffer from stack overflow problems (with big receivers)
-
factorialR
-
return fac(self) (i.e. 1*2*3...*self) using a recursive algorithm.
This is included to demonstration purposes - if you really need
factorial numbers, use the iterative #factorial, which is slightly
faster and does not suffer from stack overflow problems (with big receivers).
-
fib
-
compute the fibionacci number for the receiver.
fib(0) := 0
fib(1) := 1
fib(n) := fib(n-1) + fib(n-2)
-
fib_helper
-
compute the fibionacci number for the receiver.
Fib(n) = Fib(n-1) + Fib(n-2)
Knuth:
Fib(n+m) = Fib(m) * Fib(n+1) + Fib(m-1) * Fib(n)
This is about 3 times faster than fib_iterative.
-
gcd: anInteger
-
return the greatest common divisor of the receiver and anInteger.
Euclids & Knuths algorithm.
-
integerReciprocal
-
return an integer representing 1/self * 2**n.
Where an integer is one bit longer than self.
This is a helper for modulu numbers
-
integerSqrt
-
newton's method to get the largest integer which is less or equal to the
receiver's square root.
This might be needed for some number theoretic problems with large numbers
(ans also in cryptography)
-
inverseMod: n
-
find the modular inverse for myself to n.
This is defined as the solution of: '1 = (self * x) mod n.
This is a helper for modulu numbers
-
lcm: anInteger
-
return the least common multiple (using gcd:)
-
primeFactors
-
return a collection of prime factors of the receiver.
For prime numbers, an empty collection is returned.
Can take a long time for big numbers
(win a nobel price, if you find something quick)
-
primeFactorsUpTo: limitArgOrNil
-
return a collection of prime factors of the receiver.
For prime numbers, an empty collection is returned.
Can take a long time for big numbers
(win a nobel price, if you find something quick)
-
raisedTo: exp mod: mod
-
return the modulo (remainder) of
the receiver raised to exp (an Integer) and mod (another Integer)
-
raisedToCrtModP: p q: q ep: ep eq: eq u: u
-
Application of the Chinese Remainder Theorem (CRT).
This is a faster modexp for moduli with a known factorisation into two
relatively prime factors p and q, and an input relatively prime to the
modulus, the Chinese Remainder Theorem to do the computation mod p and
mod q, and then combine the results. This relies on a number of
precomputed values, but does not actually require the modulus n or the
exponent e.
expout = expin ^ e mod (p*q).
We form this by evaluating
p2 = (expin ^ e) mod p and
q2 = (expin ^ e) mod q
and then combining the two by the CRT.
Two optimisations of this are possible. First, we can reduce expin
modulo p and q before starting.
Second, since we know the factorisation of p and q (trivially derived
from the factorisation of n = p*q), and expin is relatively prime to
both p and q, we can use Euler's theorem, expin^phi(m) = 1 (mod m),
to throw away multiples of phi(p) or phi(q) in e.
Letting ep = e mod phi(p) and
eq = e mod phi(q)
then combining these two speedups, we only need to evaluate
p2 = ((expin mod p) ^ ep) mod p and
q2 = ((expin mod q) ^ eq) mod q.
Now we need to apply the CRT. Starting with
expout = p2 (mod p) and
expout = q2 (mod q)
we can say that expout = p2 + p * k, and if we assume that 0 <= p2 < p,
then 0 <= expout < p*q for some 0 <= k < q. Since we want expout = q2
(mod q), then p*k = q2-p2 (mod q). Since p and q are relatively prime,
p has a multiplicative inverse u mod q. In other words, u = 1/p (mod q).
Multiplying by u on both sides gives k = u*(q2-p2) (mod q).
Since we want 0 <= k < q, we can thus find k as
k = (u * (q2-p2)) mod q.
Once we have k, evaluating p2 + p * k is easy, and
that gives us the result
printing & storing
-
asBCDBytes
-
return a byteArray containing the receiver in BCD encoding.
The byteArray will contain the BCD encoded decimal string,
starting with the most significant digits first.
This conversion is useful for some communication protocols,
or control systems, which represent big numbers this way...
-
displayString
-
return a string for displaying in a view (as in inspector).
The output radix is usually 10, but can be changed by setting
DefaultDisplayRadix (see Integer>>displayRadix:)
-
errorPrintHex
-
print the receiver as a hex number on the standard error stream
-
hexPrintString
-
return a hex string representation of the receiver
-
hexPrintString: size
-
return a hex string representation of the receiver,
padded to size characters
-
printHex
-
print the receiver as a hex number on the standard output stream
-
printOn: aStream
-
append a printed description of the receiver to aStream
-
printOn: aStream base: b
-
return a string representation of the receiver in the specified
radix (without the initial XXr)
-
printOn: aStream base: b showRadix: showRadix
-
append a string representation of the receiver in the specified numberBase to aStream
(if showRadix is true, with initial XXr)
The radix argument should be between 2 and 36.
-
printOn: aStream base: baseInteger size: sz fill: fillCharacter
-
print a string representation of the receiver in the specified
base. The string is padded on the left with fillCharacter to make
its size as specified in sz.
-
printOn: aStream radix: base
-
append a printed description of the receiver to aStream.
The receiver is printed in radix base (instead of the default, 10).
This method is obsoleted by #printOn:base:, which is ST-80 & ANSI compatible.
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
printRomanOn: aStream
-
print the receiver as roman number to the receiver, aStream.
This converts correct (i.e. prefix notation for 4,9,40,90, etc.).
-
printRomanOn: aStream naive: naive
-
print the receiver as roman number to the receiver, aStream.
The naive argument controls if the conversion is
correct (i.e. subtracting prefix notation for 4,9,40,90, etc.),
or naive (i.e. print 4 as IIII and 9 as VIIII); also called simple.
The naive version is often used for page numbers in documents.
-
printStringRadix: base
-
return a string representation of the receiver in the specified
base; does NOT prepend XXr to the string.
See also: radixPrintStringRadix:
printOn:base:showRadix:
-
printStringRadix: aRadix size: sz fill: fillCharacter
-
return a string representation of the receiver in the specified
radix. The string is padded on the left with fillCharacter to make
its size as specified in sz.
-
radixPrintStringRadix: radix
-
return a string representation of the receiver in the specified
base; prepend XXr to the string
-
romanPrintString
-
return a roman number representation of the receiver as a string
queries
-
digitAt: n
-
return the n-th byte of the binary representation.
** This method raises an error - it must be redefined in concrete classes **
-
digitByteAt: n
-
return 8 bits of my signed value, starting at byte index.
For positive receivers, this is the same as #digitAt:;
for negative ones, the actual bit representation is returned.
** This method raises an error - it must be redefined in concrete classes **
-
digitLength
-
return the number of bytes needed for the binary representation
of the receiver.
This method is redefined in concrete classes - the fallback here is
never really used.
-
isInteger
-
return true, if the receiver is some kind of integer number
-
isPowerOf: p
-
return true, if the receiver is a power of p
-
isPowerOfTwo
-
return true, if the receiver is a power of 2
special access
-
exponent
-
return what would be the normalized float's exponent if I were a float.
This is not for general use - it has been added for dolphin (soap) compatibility.
This assumes that the mantissa is normalized to
0.5 .. 1.0 and the number's value is: mantissa * 2^exp
special bit operators
-
add_32: anInteger
-
return a C-semantic 32bit sum of the receiver and the argument.
Both must be either Small- or LargeIntegers.
Returns a signed 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
modulu operations with C semantics.
-
add_32u: anInteger
-
return a C-semantic 32bit unsigned sum of the receiver and the argument.
Both must be either Small- or LargeIntegers.
Returns an unsigned 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
modulu operations with C semantics.
-
bitAnd_32: anInteger
-
return a C-semantic 32bit locical-and of the receiver and
the argument. Both must be either Small- or LargeIntegers.
Returns a signed 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
bitAnd_32u: anInteger
-
return a C-semantic 32bit locical-and of the receiver and
the argument. Both must be either Small- or LargeIntegers.
Returns an unsigned 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
bitInvert_32
-
return a C-semantic 32bit complement of the receiver,
which must be either Small- or LargeIntegers.
Returns a signed 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
bitInvert_32u
-
return a C-semantic 32bit complement of the receiver,
which must be either Small- or LargeIntegers.
Returns an unsigned 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
bitOr_32: anInteger
-
return a C-semantic 32bit locical-or of the receiver and
the argument. Both must be either Small- or LargeIntegers.
Returns a signed 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
bitOr_32u: anInteger
-
return a C-semantic 32bit locical-or of the receiver and
the argument. Both must be either Small- or LargeIntegers.
Returns an unsigned 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
bitXor_32: anInteger
-
return a C-semantic 32bit locical-xor of the receiver and
the argument. Both must be either Small- or LargeIntegers.
Returns a signed 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
bitXor_32u: anInteger
-
return a C-semantic 32bit locical-xor of the receiver and
the argument. Both must be either Small- or LargeIntegers.
Returns an unsigned 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
bit operations with C semantics.
-
mul_32: anInteger
-
return a C-semantic 32bit product of the receiver and the argument.
Both must be either Small- or LargeIntegers.
Returns a signed 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
modulu operations with C semantics.
-
mul_32u: anInteger
-
return a C-semantic 32bit unsigned product of the receiver and the argument.
Both must be either Small- or LargeIntegers.
Returns an unsigned 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
modulu operations with C semantics.
-
sub_32: anInteger
-
return a C-semantic 32bit difference of the receiver and the argument.
Both must be either Small- or LargeIntegers.
Returns a signed 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
modulu operations with C semantics.
-
sub_32u: anInteger
-
return a C-semantic 32bit unsigned difference of the receiver and the argument.
Both must be either Small- or LargeIntegers.
Returns an unsigned 32bit number.
This (nonstandard) specialized method is provided to allow simulation of
modulu operations with C semantics.
testing
-
isLiteral
-
return true, if the receiver can be used as a literal constant in ST syntax
(i.e. can be used in constant arrays)
-
isPrime
-
return true if I am a prime Number.
This is a q&d hack, which may need optimization if heavily used.
-
nextPrime
-
return the next prime after the receiver
tracing
-
traceInto: aRequestor level: level from: referrer
-
double dispatch into tracer, passing my type implicitely in the selector
truncation & rounding
-
ceiling
-
return the smallest integer which is larger or equal to the receiver.
For integers, this is the receiver itself.
-
compressed
-
if the receiver can be represented as a SmallInteger, return
a SmallInteger with my value; otherwise return self with leading
zeros removed. This method is redefined in LargeInteger.
-
floor
-
return the largest integer which is smaller or equal to the receiver.
For integers, this is the receiver itself.
-
fractionPart
-
return a number with value from digits after the decimal point.
(i.e. the receiver minus its truncated value)
Since integers have no fraction, return 0 here.
-
integerPart
-
return a number with value from digits before the decimal point.
(i.e. the receivers truncated value)
Since integers have no fraction, return the receiver here.
-
normalize
-
if the receiver can be represented as a SmallInteger, return
a SmallInteger with my value; otherwise return self with leading
zeros removed.
This method is left for backward compatibility - it has been
renamed to #compressed for ST-80 compatibility.
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
rounded
-
return the receiver rounded toward the next Integer -
for integers this is the receiver itself.
-
truncated
-
return the receiver truncated towards zero as Integer
for integers this is the receiver itself.
visiting
-
acceptVisitor: aVisitor with: aParameter
-
ModuloNumber
|