- live browsing of Self object memory -

lobby traitssmallInt

CopyDowns: vector

CreatorPath: traits smallInt

Modules: smallInt, int32and64, smallIntTests

parent* = traits integer

Klein

int32and64

storeAsBigEndianByteVectorInto:At:IfFail: =
( 
    [endianDependentServer].
    aByteVector bigEndianIntSize: 32 Signed: true At: index Put: self IfFail: fb)
storeAsLittleEndianByteVectorInto:At:IfFail: = ( aByteVector littleEndianIntSize: 32 Signed: true At: index Put: self IfFail: fb)

arithmetic

% =
( 
     asSmallInteger _IntMod: a IfFail: [| :error. :name. |
    "Return receiver a receiver. Obeys identity: a%b = a - (b * a/b)."
       ('badTypeError' == error) ifTrue: [
           " use double dispatching "
           a moduloSmallInteger: asSmallInteger ] False: [
       ('overflowError' == error) ifTrue: [
           " retry after coercing to bigInts "
           asBigInteger % a asBigInteger ] False: [
       primitiveFailedError: error Name: name ]]])
* =
( 
     asSmallInteger _IntMul: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a multiplySmallInteger: asSmallInteger ] False: [
    ('overflowError' == error) ifTrue: [
        " retry after coercing to bigInts "
        asBigInteger * a asBigInteger ] False: [
    primitiveFailedError: error Name: name ]]])
+ =
( 
     asSmallInteger _IntAdd: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a addSmallInteger: asSmallInteger ] False: [
    ('overflowError' == error) ifTrue: [
        " retry after coercing to bigInts "
        asBigInteger + a asBigInteger ] False: [
    primitiveFailedError: error Name: name ]]])
- =
( 
     asSmallInteger _IntSub: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a subtractSmallInteger: asSmallInteger ] False: [
    ('overflowError' == error) ifTrue: [
        " retry after coercing to bigInts "
        asBigInteger - a asBigInteger ] False: [
    primitiveFailedError: error Name: name ]]])
/ =
( 
     asSmallInteger _IntDiv: a IfFail: [| :error. :name. |
    ('badTypeError' == error) ifTrue: [
        " use double dispatching "
        a divideSmallInteger: asSmallInteger ] False: [
    ('overflowError' == error) ifTrue: [
        " retry after coercing to bigInts "
        asBigInteger / a asBigInteger ] False: [
    primitiveFailedError: error Name: name ]]])
Integer division according to: | a/b | = |a| / |b| and |a| <= | a/b | * |b| < |a| + |b|
addBigInteger: = ( a + asBigInteger)_
addFloat: = ( a + asFloat)_
divideBigInteger: = ( a / asBigInteger)_
divideFloat: = ( a / asFloat)_
moduloBigInteger: = ( a % asBigInteger)_
moduloFloat: = ( a % asFloat)_
multiplyBigInteger: = ( a * asBigInteger)_
multiplyFloat: = ( a * asFloat)_
subtractBigInteger: = ( a - asBigInteger)_
subtractFloat: = ( a - asFloat)_
addSmallInteger: = ( a + asSmallInteger)
divideSmallInteger: = ( a / asSmallInteger)
moduloSmallInteger: = ( a % asSmallInteger)
multiplySmallInteger: = ( a * asSmallInteger)
subtractSmallInteger: = ( a - asSmallInteger)

bitfield operations

getBitFieldOffset:Mask: = ( (>> offset) && mask)Return the contents of the bitfield at the given offset. The mask argument is a right-justified mask for the bitfield (i.e., for a bitfield of size N, the mask is an integer whose N least significant bits are one and whose remaining bits are zero).
getFlagOffset: = ( ((>> offset) && 1) = 1)Return true if the bit at the given offset in the receiver is one, false if it is zero.
setBitFieldOffset:Mask:Value: =
( | maskedValue |

    maskedValue: mask && value asInteger.
    (value = maskedValue) ifFalse: [
        error: 'attempting to assign a value too large for given bit field'.
    ].
    (&& (mask << offset) complement) || (maskedValue << offset))
Return the result of setting the specified bitfield of the receiver to the given value. The low-order bit of the bitfield is offset bits from the LSB of the receiver. The mask argument is a right-justified mask for the bitfield as described in getBitField:Mask:.
setFlagOffset:To: =
( 
    aBoolean
        ifTrue: [ || (1 << offset) ]
         False: [ && (1 << offset) complement ])
Return the result of setting the bit at the given offset in the receiver to 1 if the given boolean is true or 0 if the given boolean is false.

bits

&& = ( asSmallInteger _IntAnd: a asSmallInteger)bitwise and
+> = ( asSmallInteger _IntArithmeticShiftRight: a asSmallInteger)
<+ = ( asSmallInteger _IntArithmeticShiftLeft: a asSmallInteger)
<< = ( asSmallInteger _IntLogicalShiftLeft: a asSmallInteger)
>> = ( asSmallInteger _IntLogicalShiftRight: a asSmallInteger)
^^ = ( asSmallInteger _IntXor: a asSmallInteger)bitwise xor
complement = ( -1 - self)bitwise complement
numberOfOnes =
( 
    = 0 ifTrue: [^ 0].
    < 0 ifTrue: [^ bitSize - complement numberOfOnes].
      (&& 1)  + (+> 1) numberOfOnes)
|| = ( asSmallInteger _IntOr: a asSmallInteger)bitwise or

coercions

asBigInteger = ( bigInt fromInt: asSmallInteger)
asByte = ( self)
asFloat = ( asSmallInteger _IntAsFloat)
asInt16 = ( int32 int16FromInt32: self)
asInt32 = ( self)A smallInt is also an int32, so this coercion is easy!
asInt64 = ( self)A smallInt is also an int64, so this coercion is easy.
asInt8 = ( int32 int8FromInt32: self)
asSmallIntegerIfFail: = ( self)

comparing

!= = ( asSmallInteger _IntNE: a IfFail: [(= a) not])
< =
( 
     asSmallInteger _IntLT: a IfFail: [
    a reverseLessThanSmallInteger: asSmallInteger])
<= =
( 
     asSmallInteger _IntLE: a IfFail: [
    a reverseLessThanOrEqualSmallInteger: asSmallInteger])
= =
( 
     asSmallInteger _IntEQ: a IfFail: [
    a equalsSmallInteger: asSmallInteger])
> =
( 
     asSmallInteger _IntGT: a IfFail: [
    a reverseGreaterThanSmallInteger: asSmallInteger])
>= =
( 
     asSmallInteger _IntGE: a IfFail: [
    a reverseGreaterThanOrEqualSmallInteger: asSmallInteger])
hash = ( self)
compareBigInteger:IfLess:Equal:Greater: =
( 
    asBigInteger compare: a asBigInteger 
        IfLess: lb Equal: eb Greater: gb)
_
equalsBigInteger: = ( asBigInteger = a asBigInteger)_
equalsFloat: = ( a = asFloat)_
reverseGreaterThanFloat: = ( a > asFloat)_
reverseGreaterThanOrEqualFloat: = ( a >= asFloat)_
reverseLessThanFloat: = ( a < asFloat)_
reverseLessThanOrEqualFloat: = ( a <= asFloat)_
equalsSmallInteger: = ( a = asSmallInteger)
reverseGreaterThanOrEqualSmallInteger: = ( a >= asSmallInteger)
reverseGreaterThanSmallInteger: = ( a > asSmallInteger)
reverseLessThanOrEqualSmallInteger: = ( a <= asSmallInteger)
reverseLessThanSmallInteger: = ( a < asSmallInteger)

miscellaneous

bitSize = ( typeSizes bitSize: 'self_int')
byteSize = ( typeSizes byteSize: 'self_int')

unit tests