Squeak Class Documentation category index | class index  
 
SmallInteger
  category: Kernel-Numbers
  superclass: Integer
  subclasses:

My instances are 31-bit numbers, stored in twos complement form. The allowable range is approximately +- 1 billion (see SmallInteger minVal, maxVal).

instance methods
  arithmetic
  *
+
-
/
//
\\
gcd:
quo:

  bit manipulation
  bitAnd:
bitOr:
bitShift:
bitXor:
hashMultiply
highBit
highBitOfMagnitude
lowBit

  comparing
  <
<=
=
>
>=
hash
identityHash
identityHashMappedBy:
~=

  converting
  asFloat

  copying
  clone
deepCopy
shallowCopy
veryDeepCopyWith:

  printing
  destinationBuffer:
printOn:base:
threeDigitName
uniqueNameForReference

  private
  fromString:radix:
highBitOfPositiveReceiver

  system primitives
  asOop
digitAt:
digitAt:put:
digitLength
instVarAt:
nextInstance

  testing
  even
odd

class methods
  constants
  maxVal
minVal

  documentation
  guideToDivision

  examples
  exampleFor:

  instance creation
  basicNew
new

  plugin generation
  ccg:generateCoerceToOopFrom:on:
ccg:generateCoerceToValueFrom:on:
ccg:prolog:expr:index:
ccgCanConvertFrom:

instance methods
  arithmetic top  
 

*

Primitive. Multiply the receiver by the argument and answer with the
result if it is a SmallInteger. Fail if the argument or the result is not a
SmallInteger. Essential. No Lookup. See Object documentation whatIsAPrimitive.


 

+

Primitive. Add the receiver to the argument and answer with the result
if it is a SmallInteger. Fail if the argument or the result is not a
SmallInteger Essential No Lookup. See Object documentation whatIsAPrimitive.


 

-

Primitive. Subtract the argument from the receiver and answer with the
result if it is a SmallInteger. Fail if the argument or the result is not a
SmallInteger. Essential. No Lookup. See Object documentation
whatIsAPrimitive.


 

/

Primitive. This primitive (for /) divides the receiver by the argument
and returns the result if the division is exact. Fail if the result is not a
whole integer. Fail if the argument is 0 or is not a SmallInteger. Optional.
No Lookup. See Object documentation whatIsAPrimitive.


 

//

Primitive. Divide the receiver by the argument and answer with the
result. Round the result down towards negative infinity to make it a
whole integer. Fail if the argument is 0 or is not a SmallInteger.
Essential. No Lookup. See Object documentation whatIsAPrimitive.


 

\\

Primitive. Take the receiver modulo the argument. The result is the
remainder rounded towards negative infinity, of the receiver divided by
the argument Fail if the argument is 0 or is not a SmallInteger. Optional.
No Lookup. See Object documentation whatIsAPrimitive.


 

gcd:

See SmallInteger (Integer) | gcd:


 

quo:

Primitive. Divide the receiver by the argument and answer with the
result. Round the result down towards zero to make it a whole integer.
Fail if the argument is 0 or is not a SmallInteger. Optional. See Object
documentation whatIsAPrimitive.


  bit manipulation top  
 

bitAnd:

Primitive. Answer an Integer whose bits are the logical OR of the
receiver's bits and those of the argument, arg.
Numbers are interpreted as having 2's-complement representation.
Essential. See Object documentation whatIsAPrimitive.


 

bitOr:

Primitive. Answer an Integer whose bits are the logical OR of the
receiver's bits and those of the argument, arg.
Numbers are interpreted as having 2's-complement representation.
Essential. See Object documentation whatIsAPrimitive.


 

bitShift:

Primitive. Answer an Integer whose value is the receiver's value shifted
left by the number of bits indicated by the argument. Negative arguments
shift right. The receiver is interpreted as having 2's-complement representation.
Essential. See Object documentation whatIsAPrimitive.


 

bitXor:

Primitive. Answer an Integer whose bits are the logical XOR of the
receiver's bits and those of the argument, arg.
Numbers are interpreted as having 2's-complement representation.
Essential. See Object documentation whatIsAPrimitive.


 

hashMultiply


 

highBit

Answer the index of the high order bit of the receiver, or zero if the
receiver is zero. Raise an error if the receiver is negative, since
negative integers are defined to have an infinite number of leading 1's
in 2's-complement arithmetic. Use >>highBitOfMagnitude if you want to
get the highest bit of the magnitude.


 

highBitOfMagnitude

Answer the index of the high order bit of the receiver, or zero if the
receiver is zero. This method is used for negative SmallIntegers as well,
since Squeak's LargeIntegers are sign/magnitude.


 

lowBit

Answer the index of the low order one bit.
2r00101000 lowBit (Answers: 4)
2r-00101000 lowBit (Answers: 4)
First we skip bits in groups of 4, then single bits.
While not optimal, this is a good tradeoff; long
integer #lowBit always invokes us with bytes.


  comparing top  
 

<

Primitive. Compare the receiver with the argument and answer with
true if the receiver is less than the argument. Otherwise answer false.
Fail if the argument is not a SmallInteger. Essential. No Lookup. See
Object documentation whatIsAPrimitive.


 

<=

Primitive. Compare the receiver with the argument and answer true if
the receiver is less than or equal to the argument. Otherwise answer
false. Fail if the argument is not a SmallInteger. Optional. No Lookup.
See Object documentation whatIsAPrimitive.


 

=

Primitive. Compare the receiver with the argument and answer true if
the receiver is equal to the argument. Otherwise answer false. Fail if the
argument is not a SmallInteger. Essential. No Lookup. See Object
documentation whatIsAPrimitive.


 

>

Primitive. Compare the receiver with the argument and answer true if
the receiver is greater than the argument. Otherwise answer false. Fail if
the argument is not a SmallInteger. Essential. No Lookup. See Object
documentation whatIsAPrimitive.


 

>=

Primitive. Compare the receiver with the argument and answer true if
the receiver is greater than or equal to the argument. Otherwise answer
false. Fail if the argument is not a SmallInteger. Optional. No Lookup.
See Object documentation whatIsAPrimitive.


 

hash

Hash is reimplemented because = is implemented.


 

identityHash

Answer a SmallInteger whose value is related to the receiver's identity.
This method must not be overridden, except by SmallInteger.
Primitive. Fails if the receiver is a SmallInteger. Essential.
See Object documentation whatIsAPrimitive.

Do not override.


 

identityHashMappedBy:

Answer what my hash would be if oops changed according to map.


 

~=

Primitive. Compare the receiver with the argument and answer true if
the receiver is not equal to the argument. Otherwise answer false. Fail if
the argument is not a SmallInteger. Essential. No Lookup. See Object
documentation whatIsAPrimitive.


  converting top  
 

asFloat

Primitive. Answer a Float that represents the value of the receiver.
Essential. See Object documentation whatIsAPrimitive.


  copying top  
 

clone


 

deepCopy

Answer a copy of the receiver with its own copy of each instance
variable.


 

shallowCopy

Answer a copy of the receiver which shares the receiver's instance variables.


 

veryDeepCopyWith:

Return self. I can't be copied. Do not record me.


  printing top  
 

destinationBuffer:


 

printOn:base:

Refer to the comment in Integer|printOn:base:.


 

threeDigitName


 

uniqueNameForReference

Answer a nice name by which the receiver can be referred to by other objects. For SmallIntegers, we can actually just use the receiver's own printString, though this is pretty strange in some ways.


  private top  
 

fromString:radix:


 

highBitOfPositiveReceiver

Answer the index of the high order bit of the receiver, or zero if the
receiver is zero. Receiver has to be positive!


  system primitives top  
 

asOop

Answer an object pointer as an integer, return negative number for SmallInteger


 

digitAt:

Answer the value of an indexable field in the receiver. LargePositiveInteger uses bytes of base two number, and each is a 'digit' base 256. Fail if the argument (the index) is not an Integer or is out of bounds.


 

digitAt:put:

Fails. The digits of a small integer can not be modified.


 

digitLength

Answer the number of indexable fields in the receiver. This value is the
same as the largest legal subscript. Included so that a SmallInteger can
behave like a LargePositiveInteger or LargeNegativeInteger.


 

instVarAt:

Small integer has to be specially handled.


 

nextInstance

SmallIntegers can't be enumerated this way. There are a finite number of them from from (SmallInteger minVal) to (SmallInteger maxVal), but you'll have to enumerate them yourself with:
(SmallInteger minVal) to: (SmallInteger maxVal) do: [:integer | <your code here>].


  testing top  
 

even

Refer to the comment in Number|even.


 

odd

Answer whether the receiver is an odd number.


class methods
  constants top  
 

maxVal

Answer the maximum value for a SmallInteger.


 

minVal

Answer the minimum value for a SmallInteger.


  documentation top  
 

guideToDivision

Handy guide to the kinds of Integer division:
/ exact division, returns a fraction if result is not a whole integer.
// returns an Integer, rounded towards negative infinity.
\\ is modulo rounded towards negative infinity.
quo: truncated division, rounded towards zero.


  examples top  
 

exampleFor:

Provide a MethodCall with a valid example of aSelector, ready to run. If 'all', provide all tests we know about for SUnit tests. When 'all', each will be a Verifier, with an expected answer. Returns a list of MethodCalls, Verifiers, or VerifierOfPropertys.


  instance creation top  
 

basicNew

Primitive. Answer an instance of the receiver (which is a class) with no
indexable variables. Fail if the class is indexable. Essential. See Object
documentation whatIsAPrimitive.


 

new

Answer a new instance of the receiver (which is a class) with no indexable variables. Fail if the class is indexable.


  plugin generation top  
 

ccg:generateCoerceToOopFrom:on:


 

ccg:generateCoerceToValueFrom:on:


 

ccg:prolog:expr:index:


 

ccgCanConvertFrom: