2 Copyright (c) 2008 Vincent Geddes
3 Copyright (c) 2008 Luca Bruno
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the 'Software'), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 DEALINGS IN THE SOFTWARE.
28 self shouldNotImplement!
75 self < self zero ifTrue: [^ -1].
76 self > self zero ifTrue: [^ 1].
83 "Create an Interval between the receiver and stop"
84 ^ Interval from: self to: stop!
88 "Create an Interval between the receiver and stop by step"
89 ^ Interval from: self to: stop by: step!
93 "Do aBlock from self to stop. Pass the counter to aBlock"
94 self to: stop by: self unity do: aBlock!
97 to: stop reverseDo: aBlock
98 "Do aBlock decreasing self to stop. Pass the counter to aBlock"
99 self to: stop by: self unity reverseDo: aBlock!
102 to: stop by: step do: aBlock
103 "Do aBlock increasing self to stop stepping by step. Pass the counter to aBlock"
109 whileTrue: [ aBlock value: i.
113 whileTrue: [ aBlock value: i.
117 to: stop by: step reverseDo: aBlock
118 "Do aBlock decreasing self to stop stepping by step. Pass the counter to aBlock"
124 whileTrue: [ aBlock value: i.
128 whileTrue: [ aBlock value: i.
136 ^ Fraction numerator: self denominator: 1!
144 self subclassResponsibility!
148 self subclassResponsibility!
152 ^ self subclassResponsibility!
156 self subclassResponsibility!
160 self subclassResponsibility!
172 ifTrue: [ ^ self zero - self ]!
177 ifTrue: [ ^ self negated ]
182 "Answer the reciprocal number of self"
187 "Coerce aNumber and do the sum"
188 ^ self generality > aNumber generality
189 ifTrue: [ self + (self coerce: aNumber) ]
190 ifFalse: [ (aNumber coerce: self) + aNumber ]!
194 "Coerce aNumber and do the difference"
195 ^ self generality > aNumber generality
196 ifTrue: [ self - (self coerce: aNumber) ]
197 ifFalse: [ (aNumber coerce: self) - aNumber ]!
201 "Coerce aNumber and do multiplication"
202 ^ self generality > aNumber generality
203 ifTrue: [ self * (self coerce: aNumber) ]
204 ifFalse: [ (aNumber coerce: self) * aNumber ]!
208 "Coerce aNumber and do division"
210 ifTrue: [ self zeroDivide ].
212 ^ self generality > aNumber generality
213 ifTrue: [ self / (self coerce: aNumber) ]
214 ifFalse: [ (aNumber coerce: self) / aNumber ]!
218 "Do division then answer the quotient floor"
219 ^ (self / aNumber) floor!
223 "Coerce aNumber and do modulo"
224 ^ self generality > aNumber generality
225 ifTrue: [ self \\ (self coerce: aNumber) ]
226 ifFalse: [ (aNumber coerce: self) \\ aNumber ]!
230 "Do division then answer the truncated quotient towards zero"
231 ^ (self / aNumber) truncated!
235 "Do division then answer the truncated remainder towards zero"
236 self notYetImplemented!
243 "Return 1 if self > aNumber, 0 if = aNumber, -1 if < aNumber"
244 self > aNumber ifTrue: [ ^ 1 ].
245 self = aNumber ifTrue: [ ^ 0 ].
246 self < aNumber ifTrue: [ ^ -1 ]!
250 "Coerce aNumber and compare"
251 ^ self generality > aNumber generality
252 ifTrue: [ self < (self coerce: aNumber) ]
253 ifFalse: [ (aNumber coerce: self) < aNumber ]!
257 "Coerce aNumber and compare"
258 ^ self generality > aNumber generality
259 ifTrue: [ self > (self coerce: aNumber) ]
260 ifFalse: [ (aNumber coerce: self) > aNumber ]!
264 "Coerce aNumber and compare"
265 ^ self generality > aNumber generality
266 ifTrue: [ self <= (self coerce: aNumber) ]
267 ifFalse: [ (aNumber coerce: self) <= aNumber ]!
271 "Coerce aNumber and compare"
272 ^ self generality > aNumber generality
273 ifTrue: [ self >= (self coerce: aNumber) ]
274 ifFalse: [ (aNumber coerce: self) >= aNumber ]!
278 "Coerce aNumber and compare equality"
280 ifFalse: [ ^ false ].
281 ^ self generality > aNumber generality
282 ifTrue: [ self = (self coerce: aNumber) ]
283 ifFalse: [ (aNumber coerce: self) = aNumber ]!
287 "Coerce aNumber and compare inequality"
288 ^ self generality > aNumber generality
289 ifTrue: [ self ~= (self coerce: aNumber) ]
290 ifFalse: [ (aNumber coerce: self) ~= aNumber ]!
298 self error: 'division by zero'!
304 "Answer the integer nearest the receiver toward negative infinity."
308 truncation := self truncated.
309 self >= 0 ifTrue: [^truncation].
311 ifTrue: [^truncation]
312 ifFalse: [^truncation - 1]!
324 ^ self ln / aNumber ln!
328 self notYetImplemented!
332 self notYetImplemented!
335 raisedToInteger: anInteger
336 self notYetImplemented!
356 ^ self asFloat arcSin!
360 ^ self asFloat arcCos!
364 ^ self asFloat arcTan!
368 "Answer the square of the receiver"
372 raisedToInteger: anInteger
376 ifTrue: [ ^ self zero ].
377 (self = 1) | (anInteger = 0)
378 ifTrue: [ ^ self unity ].
381 ifTrue: [ ^ (self raisedToInteger: anInteger abs) reciprocal ].
385 [ (count := count + 1) <= anInteger ]
386 whileTrue: [ result := result * self ].
394 ifTrue: [ ^ self zero ].
395 (self = 1) | (aNumber = 0)
396 ifTrue: [ ^ self unity ].
398 (aNumber isFloat) & (self isNegative)
399 ifTrue: [ self error: 'raising a negative number to non-integral exponent'].
402 ifTrue: [ ^ (aNumber * self ln) exp ].
404 ^ self raisedToInteger: aNumber!
409 printStringBase: anInteger
410 "Answer a String representation of the receiver"
412 stream := WriteStream on: (String new: 20).
413 self printOn: stream base: anInteger.
417 printOn: aStream base: anInteger
418 self subclassResponsibility!
422 self printOn: aStream base: 10!