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 ^ 3.1415926535897932384626433832795028841971693993751!
32 ^ 2.7182818284590452353602874713526624977572470937000!
38 self shouldNotImplement!
85 self < self zero ifTrue: [^ -1].
86 self > self zero ifTrue: [^ 1].
93 "Create an Interval between the receiver and stop"
94 ^ Interval from: self to: stop!
98 "Create an Interval between the receiver and stop by step"
99 ^ Interval from: self to: stop by: step!
103 "Do aBlock from self to stop. Pass the counter to aBlock"
104 self to: stop by: self unity do: aBlock!
107 to: stop reverseDo: aBlock
108 "Do aBlock decreasing self to stop. Pass the counter to aBlock"
109 self to: stop by: self unity reverseDo: aBlock!
112 to: stop by: step do: aBlock
113 "Do aBlock increasing self to stop stepping by step. Pass the counter to aBlock"
119 whileTrue: [ aBlock value: i.
123 whileTrue: [ aBlock value: i.
127 to: stop by: step reverseDo: aBlock
128 "Do aBlock decreasing self to stop stepping by step. Pass the counter to aBlock"
134 whileTrue: [ aBlock value: i.
138 whileTrue: [ aBlock value: i.
146 ^ Fraction numerator: self denominator: 1!
154 self subclassResponsibility!
158 self subclassResponsibility!
162 ^ self subclassResponsibility!
166 self subclassResponsibility!
170 self subclassResponsibility!
182 ifTrue: [ ^ self zero - self ]!
187 ifTrue: [ ^ self negated ]
192 "Answer the reciprocal number of self"
197 "Coerce aNumber and do the sum"
198 ^ self generality > aNumber generality
199 ifTrue: [ self + (self coerce: aNumber) ]
200 ifFalse: [ (aNumber coerce: self) + aNumber ]!
204 "Coerce aNumber and do the difference"
205 ^ self generality > aNumber generality
206 ifTrue: [ self - (self coerce: aNumber) ]
207 ifFalse: [ (aNumber coerce: self) - aNumber ]!
211 "Coerce aNumber and do multiplication"
212 ^ self generality > aNumber generality
213 ifTrue: [ self * (self coerce: aNumber) ]
214 ifFalse: [ (aNumber coerce: self) * aNumber ]!
218 "Coerce aNumber and do division"
220 ifTrue: [ self zeroDivide ].
222 ^ self generality > aNumber generality
223 ifTrue: [ self / (self coerce: aNumber) ]
224 ifFalse: [ (aNumber coerce: self) / aNumber ]!
228 "Do division then answer the quotient floor"
229 ^ (self / aNumber) floor!
233 "Coerce aNumber and do modulo"
234 ^ self generality > aNumber generality
235 ifTrue: [ self \\ (self coerce: aNumber) ]
236 ifFalse: [ (aNumber coerce: self) \\ aNumber ]!
240 "Do division then answer the truncated quotient towards zero"
241 ^ (self / aNumber) truncated!
245 "Do division then answer the truncated remainder towards zero"
246 self notYetImplemented!
253 "Return 1 if self > aNumber, 0 if = aNumber, -1 if < aNumber"
254 self > aNumber ifTrue: [ ^ 1 ].
255 self = aNumber ifTrue: [ ^ 0 ].
256 self < aNumber ifTrue: [ ^ -1 ]!
260 "Coerce aNumber and compare"
261 ^ self generality > aNumber generality
262 ifTrue: [ self < (self coerce: aNumber) ]
263 ifFalse: [ (aNumber coerce: self) < aNumber ]!
267 "Coerce aNumber and compare"
268 ^ self generality > aNumber generality
269 ifTrue: [ self > (self coerce: aNumber) ]
270 ifFalse: [ (aNumber coerce: self) > aNumber ]!
274 "Coerce aNumber and compare"
275 ^ self generality > aNumber generality
276 ifTrue: [ self <= (self coerce: aNumber) ]
277 ifFalse: [ (aNumber coerce: self) <= aNumber ]!
281 "Coerce aNumber and compare"
282 ^ self generality > aNumber generality
283 ifTrue: [ self >= (self coerce: aNumber) ]
284 ifFalse: [ (aNumber coerce: self) >= aNumber ]!
288 "Coerce aNumber and compare equality"
290 ifFalse: [ ^ false ].
291 ^ self generality > aNumber generality
292 ifTrue: [ self = (self coerce: aNumber) ]
293 ifFalse: [ (aNumber coerce: self) = aNumber ]!
297 "Coerce aNumber and compare inequality"
298 ^ self generality > aNumber generality
299 ifTrue: [ self ~= (self coerce: aNumber) ]
300 ifFalse: [ (aNumber coerce: self) ~= aNumber ]!
308 self error: 'division by zero'!
314 "Answer the integer nearest the receiver toward negative infinity."
318 truncation := self truncated.
319 self >= 0 ifTrue: [^truncation].
321 ifTrue: [^truncation]
322 ifFalse: [^truncation - 1]!
334 ^ self ln / aNumber ln!
338 self notYetImplemented!
342 self notYetImplemented!
345 raisedToInteger: anInteger
346 self notYetImplemented!
366 ^ self asFloat arcSin!
370 ^ self asFloat arcCos!
374 ^ self asFloat arcTan!
378 "Answer the square of the receiver"
382 raisedToInteger: anInteger
386 ifTrue: [ ^ self zero ].
387 (self = 1) | (anInteger = 0)
388 ifTrue: [ ^ self unity ].
391 ifTrue: [ ^ (self raisedToInteger: anInteger abs) reciprocal ].
395 [ (count := count + 1) <= anInteger ]
396 whileTrue: [ result := result * self ].
404 ifTrue: [ ^ self zero ].
405 (self = 1) | (aNumber = 0)
406 ifTrue: [ ^ self unity ].
408 (aNumber isFloat) & (self isNegative)
409 ifTrue: [ self error: 'raising a negative number to non-integral exponent'].
412 ifTrue: [ ^ (aNumber * self ln) exp ].
414 ^ self raisedToInteger: aNumber!
419 printStringBase: anInteger
420 "Answer a String representation of the receiver"
422 stream := WriteStream on: (String new: 20).
423 self printOn: stream base: anInteger.
427 printOn: aStream base: anInteger
428 self subclassResponsibility!
432 self printOn: aStream base: 10!