home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 232_01 / integer.st < prev    next >
Text File  |  1987-06-17  |  3KB  |  129 lines

  1. Class Integer :Number
  2. [
  3.     = aNumber
  4.         ^ <SameTypeOfObject self aNumber>
  5.             ifTrue:  [ <IntegerEquality self aNumber> ]
  6.             ifFalse: [ super = aNumber ]
  7. |
  8.     > aNumber
  9.         ^ <SameTypeOfObject self aNumber>
  10.             ifTrue:  [ <IntegerGreaterThan self aNumber> ]
  11.             ifFalse: [ super > aNumber ]
  12. |
  13.     < aNumber
  14.         ^ <SameTypeOfObject self aNumber>
  15.             ifTrue:  [ <IntegerLessThan self aNumber> ]
  16.             ifFalse: [ super < aNumber ]
  17. |
  18.     + aNumber
  19.         ^ <SameTypeOfObject self aNumber>
  20.             ifTrue:  [ <IntegerAddition self aNumber> ]
  21.             ifFalse: [ super + aNumber ]
  22. |
  23.     - aNumber
  24.         ^ <SameTypeOfObject self aNumber>
  25.             ifTrue:  [<IntegerSubtraction self aNumber>]
  26.             ifFalse: [ super - aNumber ]
  27. |
  28.     * aNumber
  29.         ^ <SameTypeOfObject self aNumber>
  30.             ifTrue:  [<IntegerMultiplication self aNumber>]
  31.             ifFalse: [ super * aNumber ]
  32. |
  33.     / aNumber
  34.         ^ self asFloat / aNumber
  35. |
  36.     // aNumber
  37.         ^ <SameTypeOfObject self aNumber>
  38.             ifTrue:  [<IntegerSlash self aNumber>]
  39.             ifFalse: [self opError]
  40. |
  41.     \\ aNumber            | i |
  42.         ^ <SameTypeOfObject self aNumber>
  43.             ifTrue:  [i <- self * ( (self < 0)
  44.                         ifTrue:  [ -1 ]
  45.                         ifFalse: [ 1 ] ).
  46.                   i rem: aNumber]
  47.             ifFalse:  [self opError]
  48. |
  49.     allMask: anInteger
  50.         ^ anInteger = <BitAND self anInteger>
  51. |
  52.     anyMask: anInteger
  53.         ^ 0 ~= <BitAND self anInteger>
  54. |
  55.     asCharacter
  56.         ^ <IntegerToCharacter self>
  57. |
  58.     asFloat
  59.         ^ <IntegerToFloat self >
  60. |
  61.     asInteger
  62.         ^ self
  63. |
  64.     asString
  65.         ^ <IntegerToString self>
  66. |
  67.     bitAnd: anInteger
  68.         ^ <BitAND self anInteger>
  69. |
  70.     bitAt: anInteger
  71.         ^ <BitAt self anInteger>
  72. |
  73.     bitInvert
  74.         ^ <BitInverse self>
  75. |
  76.     bitOr: anInteger
  77.         ^ <BitOR self anInteger>
  78. |
  79.     bitShift: anInteger
  80.         ^ <BitShift self anInteger>
  81. |
  82.     bitXor: anInteger
  83.         ^ <BitXOR self anInteger>
  84. |
  85.     even
  86.         ^ (self rem: 2) = 0
  87. |
  88.     factorial
  89.         ^ <Factorial self>
  90. |
  91.     gcd: anInteger
  92.         ^ <SameTypeOfObject self anInteger>
  93.             ifTrue:  [<GCD self anInteger>]
  94.             ifFalse: [self opError]
  95. |
  96.     highBit
  97.         ^ <HighBit self>
  98. |
  99.     lcm: anInteger
  100.         ^ <SameTypeOfObject self anInteger>
  101.             ifTrue:  [self * anInteger quo:
  102.                     (self gcd: anInteger)]
  103.             ifFalse: [self opError]
  104. |
  105.     noMask: anInteger
  106.         ^ 0 = (self bitAnd: anInteger)
  107. |
  108.     odd
  109.         ^ (self rem: 2) ~= 0
  110. |
  111.     quo: anInteger
  112.         ^ <SameTypeOfObject self anInteger>
  113.             ifTrue:  [<IntegerDivision self anInteger>]
  114.             ifFalse: [self opError]
  115. |
  116.     radix: aNumber
  117.         ^ <RadixPrint self aNumber>
  118. |
  119.     rem: anInteger
  120.         ^ <SameTypeOfObject self anInteger>
  121.             ifTrue:  [<IntegerMod self anInteger>]
  122.             ifFalse: [self opError]
  123. |
  124.     timesRepeat: aBlock        | i |
  125.         i <- 0.
  126.         [i < self] whileTrue:
  127.             [aBlock value. i <- i + 1]
  128. ]
  129.