author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 11:46:35 +0100 | |
changeset 620 | c7353f86a302 |
parent 528 | a083413dfbe8 |
child 701 | a309e3ef7faf |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
213 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Magnitude subclass:#ArithmeticValue |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'DivisionByZeroSignal DomainErrorSignal |
|
213 | 16 |
OverflowSignal UnderflowSignal |
345 | 17 |
ArithmeticSignal AnyArithmeticSignal |
18 |
UnorderedSignal' |
|
1 | 19 |
poolDictionaries:'' |
20 |
category:'Magnitude-Numbers' |
|
21 |
! |
|
22 |
||
82 | 23 |
!ArithmeticValue class methodsFor:'documentation' ! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
213 | 28 |
All Rights Reserved |
1 | 29 |
|
82 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
1 | 38 |
|
82 | 39 |
version |
528
a083413dfbe8
converted version methods from comment-only to returning-a-string
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
40 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/ArithVal.st,v 1.16 1995-11-11 14:26:28 cg Exp $' |
82 | 41 |
! |
1 | 42 |
|
82 | 43 |
documentation |
44 |
" |
|
45 |
ArithmeticValue is an abstract superclass for all things responding to |
|
155 | 46 |
arithmetic messages. It was inserted into the hierarchy, to allow objects |
47 |
like matrices, functions etc. to share the arithmetic methods defined here. |
|
48 |
||
49 |
class variables: |
|
213 | 50 |
ArithmeticSignal <Signal> parent of all arithmetic signals |
155 | 51 |
(never raised itself) |
82 | 52 |
|
213 | 53 |
DomainErrorSignal <Signal> raised upon float errors |
54 |
(for example range in trigonometric) |
|
155 | 55 |
|
213 | 56 |
DivisionByZeroSignal <Signal> raised when division by 0 is attempted |
155 | 57 |
|
213 | 58 |
OverflowSignal <Signal> raised on overflow/underflow conditions |
59 |
UnderflowSignal in float arithmetic. |
|
60 |
Notice: some OperatingSystems do not |
|
61 |
provide enough information for ST/X to |
|
62 |
extract the real reason for the floatException |
|
63 |
thus raising DomainErrorSignal in these cases. |
|
82 | 64 |
" |
65 |
! ! |
|
1 | 66 |
|
67 |
!ArithmeticValue class methodsFor:'initialization' ! |
|
68 |
||
69 |
initialize |
|
70 |
"setup the signals" |
|
71 |
||
54 | 72 |
DomainErrorSignal isNil ifTrue:[ |
302 | 73 |
ArithmeticSignal := ErrorSignal newSignalMayProceed:false. |
213 | 74 |
ArithmeticSignal nameClass:self message:#arithmeticSignal. |
75 |
ArithmeticSignal notifierString:'arithmetic error'. |
|
155 | 76 |
|
213 | 77 |
DomainErrorSignal := ArithmeticSignal newSignalMayProceed:false. |
78 |
DomainErrorSignal nameClass:self message:#domainErrorSignal. |
|
79 |
DomainErrorSignal notifierString:'domain error'. |
|
1 | 80 |
|
213 | 81 |
DivisionByZeroSignal := ArithmeticSignal newSignalMayProceed:false. |
82 |
DivisionByZeroSignal nameClass:self message:#divisionByZeroSignal. |
|
83 |
DivisionByZeroSignal notifierString:'division by zero'. |
|
1 | 84 |
|
213 | 85 |
OverflowSignal := ArithmeticSignal newSignalMayProceed:false. |
86 |
OverflowSignal nameClass:self message:#overflowSignal. |
|
87 |
OverflowSignal notifierString:'overflow'. |
|
54 | 88 |
|
213 | 89 |
UnderflowSignal := ArithmeticSignal newSignalMayProceed:false. |
90 |
UnderflowSignal nameClass:self message:#underflowSignal. |
|
91 |
UnderflowSignal notifierString:'underflow'. |
|
1 | 92 |
|
345 | 93 |
UnorderedSignal := ArithmeticSignal newSignalMayProceed:false. |
94 |
UnorderedSignal nameClass:self message:#unorderedSignal. |
|
95 |
UnorderedSignal notifierString:'unordered'. |
|
96 |
||
213 | 97 |
AnyArithmeticSignal := SignalSet with:DomainErrorSignal |
98 |
with:DivisionByZeroSignal |
|
99 |
with:OverflowSignal |
|
345 | 100 |
with:UnderflowSignal |
101 |
with:UnorderedSignal. |
|
54 | 102 |
] |
1 | 103 |
! ! |
104 |
||
345 | 105 |
!ArithmeticValue class methodsFor:'Signal constants' ! |
1 | 106 |
|
107 |
domainErrorSignal |
|
108 |
"return the signal which is raised on math errors |
|
109 |
(such as log of 0 etc.)" |
|
110 |
||
111 |
^ DomainErrorSignal |
|
112 |
! |
|
113 |
||
114 |
divisionByZeroSignal |
|
115 |
"return the signal which is raised on division by zero" |
|
116 |
||
117 |
^ DivisionByZeroSignal |
|
118 |
! |
|
119 |
||
120 |
overflowSignal |
|
121 |
"return the signal which is raised on overflow conditions (in floats)" |
|
122 |
||
123 |
^ OverflowSignal |
|
124 |
! |
|
125 |
||
126 |
underflowSignal |
|
127 |
"return the signal which is raised on underflow conditions (in floats)" |
|
128 |
||
129 |
^ UnderflowSignal |
|
130 |
! |
|
131 |
||
345 | 132 |
unorderedSignal |
133 |
"return the signal which is raised when numbers are compared, |
|
134 |
for which no ordering is defined (for example: complex numbers)" |
|
135 |
||
136 |
^ UnderflowSignal |
|
137 |
! |
|
138 |
||
155 | 139 |
arithmeticSignal |
140 |
"return the parent of all arithmetic signals" |
|
141 |
||
142 |
^ ArithmeticSignal |
|
143 |
! |
|
144 |
||
1 | 145 |
anyArithmeticSignal |
155 | 146 |
"return a signalSet with all possible arithmetic signals. |
147 |
OBSOLETE: this will vanish, since starting with 2.10.3, signal parents |
|
213 | 148 |
have been added." |
1 | 149 |
|
150 |
^ AnyArithmeticSignal |
|
151 |
! ! |
|
152 |
||
153 |
!ArithmeticValue methodsFor:'converting' ! |
|
154 |
||
155 |
degreesToRadians |
|
156 |
"interpreting the receiver as radians, return the degrees" |
|
157 |
||
158 |
^ self asFloat degreesToRadians |
|
159 |
! |
|
160 |
||
161 |
radiansToDegrees |
|
162 |
"interpreting the receiver as degrees, return the radians" |
|
163 |
||
164 |
^ self asFloat radiansToDegrees |
|
165 |
! |
|
166 |
||
167 |
asInteger |
|
168 |
"return an integer with same value - might truncate" |
|
169 |
||
170 |
^ self truncated |
|
171 |
! |
|
172 |
||
173 |
asFloat |
|
174 |
"return a float with same value" |
|
175 |
||
176 |
^ self subclassResponsibility |
|
177 |
! |
|
178 |
||
179 |
asFraction |
|
180 |
"return a fraction with same value" |
|
181 |
||
182 |
^ self subclassResponsibility |
|
183 |
! |
|
184 |
||
185 |
coerce:aNumber |
|
186 |
"convert aNumber into an instance of the receivers class and return it." |
|
187 |
||
188 |
^ self subclassResponsibility |
|
189 |
! |
|
190 |
||
191 |
generality |
|
192 |
"return a number giving the receivers generality, that number is |
|
193 |
used to convert one of the arguments in a mixed expression. |
|
194 |
The generality has to be defined in subclasses, |
|
195 |
such that gen(a) > gen(b) iff, conversion of b into a's class |
|
196 |
does not cut precision. For example, Integer has 40, Float has 80, |
|
197 |
meaning that if we convert a Float to an Integer, some precision may |
|
198 |
be lost. The generality is used by ArithmeticValue>>retry:cuercing:" |
|
199 |
||
200 |
^ self subclassResponsibility |
|
201 |
! |
|
202 |
||
203 |
retry:aSymbol coercing:aNumber |
|
204 |
"arithmetic represented by the binary operator, aSymbol, |
|
205 |
could not be performed with the receiver and the argument, aNumber, |
|
206 |
because of the differences in representation. |
|
207 |
Coerce either the receiver or the argument, depending on which has higher |
|
208 |
generality, and try again. |
|
209 |
If the operation is compare for same value (=), return false if |
|
210 |
the argument is not a Number. |
|
211 |
If the generalities are the same, create an error message, since this |
|
212 |
means that a subclass has not been fully implemented." |
|
213 |
||
214 |
|myGenerality otherGenerality| |
|
215 |
||
216 |
(aSymbol == #=) ifTrue:[ |
|
213 | 217 |
(aNumber respondsTo:#generality) ifFalse:[^ false] |
1 | 218 |
] ifFalse:[ |
213 | 219 |
(aNumber respondsTo:#generality) ifFalse:[ |
220 |
self error:'retry:coercing: argument is not a number'. |
|
221 |
^ self |
|
222 |
] |
|
1 | 223 |
]. |
224 |
myGenerality := self generality. |
|
225 |
otherGenerality := aNumber generality. |
|
226 |
(myGenerality > otherGenerality) ifTrue:[ |
|
213 | 227 |
^ self perform:aSymbol with:(self coerce:aNumber) |
1 | 228 |
]. |
229 |
(myGenerality < otherGenerality) ifTrue:[ |
|
213 | 230 |
^ (aNumber coerce:self) perform:aSymbol with:aNumber |
1 | 231 |
]. |
232 |
self error:'retry:coercing: oops - same generality' |
|
233 |
! ! |
|
234 |
||
235 |
!ArithmeticValue methodsFor:'queries' ! |
|
236 |
||
237 |
respondsToArithmetic |
|
238 |
"return true, if the receiver responds to arithmetic messages" |
|
239 |
||
240 |
^ true |
|
241 |
! ! |
|
242 |
||
243 |
!ArithmeticValue methodsFor:'arithmetic' ! |
|
244 |
||
245 |
+ something |
|
246 |
"return the sum of the receiver and the argument" |
|
247 |
||
248 |
^ self subclassResponsibility |
|
249 |
! |
|
250 |
||
251 |
- something |
|
252 |
"return the difference of the receiver and the argument" |
|
253 |
||
254 |
^ self subclassResponsibility |
|
255 |
! |
|
256 |
||
257 |
* something |
|
258 |
"return the product of the receiver and the argument" |
|
259 |
||
260 |
^ self subclassResponsibility |
|
261 |
! |
|
262 |
||
263 |
/ something |
|
264 |
"return the quotient of the receiver and the argument" |
|
265 |
||
266 |
^ self subclassResponsibility |
|
267 |
! |
|
268 |
||
269 |
// something |
|
270 |
"return the integer quotient of the receiver and the argument" |
|
271 |
||
272 |
^ (self / something) floor |
|
273 |
! |
|
274 |
||
275 |
\\ something |
|
276 |
"return the integer modulu of the receiver and the argument" |
|
277 |
||
278 |
^ self - ((self // something) * something) |
|
279 |
! |
|
280 |
||
281 |
quo:something |
|
282 |
"Return the integer quotient of dividing the receiver by the argument |
|
283 |
with truncation towards zero." |
|
284 |
||
285 |
^ (self / something) truncated |
|
286 |
! |
|
287 |
||
288 |
rem:something |
|
289 |
"Return the integer remainder of dividing the receiver by the argument |
|
290 |
with truncation towards zero. |
|
291 |
The remainder has the same sign as the receiver." |
|
292 |
||
293 |
^ self - ((self quo:something) * something) |
|
294 |
! |
|
295 |
||
296 |
abs |
|
297 |
"return the absolute value of the receiver" |
|
298 |
||
299 |
(self negative) ifTrue:[^ self negated]. |
|
300 |
^ self |
|
301 |
! |
|
302 |
||
303 |
negated |
|
304 |
"return the receiver negated" |
|
305 |
||
306 |
^ self class zero - self |
|
307 |
! |
|
308 |
||
309 |
reciprocal |
|
310 |
"return the receivers reciprocal" |
|
311 |
||
312 |
^ self class unity / self |
|
313 |
! ! |
|
314 |
||
315 |
!ArithmeticValue methodsFor:'comparing'! |
|
316 |
||
317 |
>= something |
|
318 |
"return true, if the argument is less or equal than the receiver" |
|
319 |
||
320 |
^ (self < something) not |
|
321 |
! |
|
322 |
||
323 |
> something |
|
324 |
"return true, if the argument is less than the receiver" |
|
325 |
||
326 |
^ something < self |
|
327 |
! |
|
328 |
||
329 |
<= something |
|
330 |
"return true, if the argument is greater or equal than the receiver" |
|
331 |
||
332 |
^ (something < self) not |
|
333 |
! |
|
334 |
||
335 |
< something |
|
336 |
"return true, if the argument is greater than the receiver" |
|
337 |
||
338 |
^ self subclassResponsibility |
|
339 |
! |
|
340 |
||
341 |
compare:arg ifLess:lessBlock ifEqual:equalBlock ifGreater:greaterBlock |
|
342 |
"three-way compare - thanks to Self for this idea. |
|
343 |
Can be redefined in subclasses to do it with a single comparison if |
|
344 |
comparison is expensive." |
|
345 |
||
346 |
self < arg ifTrue:[ |
|
213 | 347 |
^ lessBlock value |
1 | 348 |
]. |
349 |
self = arg ifTrue:[ |
|
213 | 350 |
^ equalBlock value |
1 | 351 |
]. |
352 |
^ greaterBlock value |
|
353 |
! ! |
|
354 |
||
213 | 355 |
!ArithmeticValue methodsFor:'truncation & rounding'! |
1 | 356 |
|
357 |
ceiling |
|
358 |
"return the integer nearest the receiver towards positive infinity." |
|
359 |
||
360 |
|anInteger| |
|
361 |
||
362 |
anInteger := self // 1. "truncates towards negative infinity" |
|
363 |
anInteger = self ifTrue:[^ anInteger]. |
|
364 |
^ anInteger + 1 |
|
365 |
! |
|
366 |
||
367 |
floor |
|
368 |
"return the receiver truncated towards negative infinity" |
|
369 |
||
370 |
^ self // 1 |
|
371 |
! |
|
372 |
||
373 |
truncated |
|
374 |
"return the receiver truncated towards zero" |
|
375 |
||
77 | 376 |
self negative ifTrue:[ |
213 | 377 |
^ self ceiling |
77 | 378 |
]. |
379 |
^ self floor |
|
1 | 380 |
! |
381 |
||
382 |
truncateTo:aNumber |
|
383 |
"return the receiver truncated to multiples of aNumber" |
|
384 |
||
385 |
^ ((self / aNumber) floor * aNumber) asInteger |
|
386 |
! |
|
387 |
||
388 |
rounded |
|
389 |
"return the integer nearest the receiver" |
|
390 |
||
77 | 391 |
^ (self + 0.5) floor |
1 | 392 |
! |
393 |
||
394 |
roundTo:aNumber |
|
395 |
"return the receiver rounded to multiples of aNumber" |
|
396 |
||
397 |
^ (self / aNumber) rounded * aNumber |
|
398 |
! ! |
|
399 |
||
400 |
!ArithmeticValue methodsFor:'double dispatching'! |
|
401 |
||
402 |
sumFromInteger:anInteger |
|
403 |
"the receiver does not know how to add an integer - |
|
404 |
retry the operation by coercing to higher generality" |
|
405 |
||
406 |
^ anInteger retry:#+ coercing:self |
|
407 |
! |
|
408 |
||
409 |
sumFromFloat:aFloat |
|
410 |
"the receiver does not know how to add a float - |
|
411 |
retry the operation by coercing to higher generality" |
|
412 |
||
413 |
^ aFloat retry:#+ coercing:self |
|
414 |
! |
|
415 |
||
416 |
sumFromFraction:aFraction |
|
417 |
"the receiver does not know how to add a fraction - |
|
418 |
retry the operation by coercing to higher generality" |
|
419 |
||
420 |
^ aFraction retry:#+ coercing:self |
|
421 |
! |
|
422 |
||
423 |
differenceFromInteger:anInteger |
|
424 |
"the receiver does not know how to subtract from an integer - |
|
425 |
retry the operation by coercing to higher generality" |
|
426 |
||
427 |
^ anInteger retry:#- coercing:self |
|
428 |
! |
|
429 |
||
430 |
differenceFromFloat:aFloat |
|
431 |
"the receiver does not know how to subtract from a float - |
|
432 |
retry the operation by coercing to higher generality" |
|
433 |
||
434 |
^ aFloat retry:#- coercing:self |
|
435 |
! |
|
436 |
||
437 |
differenceFromFraction:aFraction |
|
438 |
"the receiver does not know how to subtract from a fraction - |
|
439 |
retry the operation by coercing to higher generality" |
|
440 |
||
441 |
^ aFraction retry:#- coercing:self |
|
442 |
! |
|
443 |
||
444 |
productFromInteger:anInteger |
|
445 |
"the receiver does not know how to multiply an integer - |
|
446 |
retry the operation by coercing to higher generality" |
|
447 |
||
448 |
^ anInteger retry:#* coercing:self |
|
449 |
! |
|
450 |
||
451 |
productFromFloat:aFloat |
|
452 |
"the receiver does not know how to multiply a float - |
|
453 |
retry the operation by coercing to higher generality" |
|
454 |
||
455 |
^ aFloat retry:#* coercing:self |
|
456 |
! |
|
457 |
||
458 |
productFromFraction:aFraction |
|
459 |
"the receiver does not know how to multiply a fraction - |
|
460 |
retry the operation by coercing to higher generality" |
|
461 |
||
462 |
^ aFraction retry:#* coercing:self |
|
463 |
! |
|
464 |
||
465 |
quotientFromInteger:anInteger |
|
466 |
"the receiver does not know how to divide an integer - |
|
467 |
retry the operation by coercing to higher generality" |
|
468 |
||
469 |
^ anInteger retry:#/ coercing:self |
|
470 |
! |
|
471 |
||
472 |
quotientFromFloat:aFloat |
|
473 |
"the receiver does not know how to divide a float - |
|
474 |
retry the operation by coercing to higher generality" |
|
475 |
||
476 |
^ aFloat retry:#/ coercing:self |
|
477 |
! |
|
478 |
||
479 |
quotientFromFraction:aFraction |
|
480 |
"the receiver does not know how to divide a fraction - |
|
481 |
retry the operation by coercing to higher generality" |
|
482 |
||
483 |
^ aFraction retry:#/ coercing:self |
|
484 |
! |
|
485 |
||
486 |
lessFromInteger:anInteger |
|
487 |
"the receiver does not know how to compare to an integer - |
|
488 |
retry the operation by coercing to higher generality" |
|
489 |
||
490 |
^ anInteger retry:#< coercing:self |
|
491 |
! |
|
492 |
||
493 |
lessFromFloat:aFloat |
|
494 |
"the receiver does not know how to compare to a float - |
|
495 |
retry the operation by coercing to higher generality" |
|
496 |
||
497 |
^ aFloat retry:#< coercing:self |
|
498 |
! |
|
499 |
||
500 |
lessFromFraction:aFraction |
|
501 |
"the receiver does not know how to compare to a fraction - |
|
502 |
retry the operation by coercing to higher generality" |
|
503 |
||
504 |
^ aFraction retry:#< coercing:self |
|
505 |
! ! |
|
506 |
||
507 |
!ArithmeticValue methodsFor:'misc math'! |
|
508 |
||
509 |
squared |
|
510 |
"return receiver * receiver" |
|
511 |
||
512 |
^ self * self |
|
513 |
! |
|
514 |
||
515 |
exp |
|
516 |
"return e ^ receiver" |
|
517 |
||
518 |
^ self asFloat exp |
|
519 |
! |
|
520 |
||
521 |
ln |
|
522 |
"return the natural logarithm of the receiver" |
|
523 |
||
524 |
^ self asFloat ln |
|
525 |
! |
|
526 |
||
527 |
log |
|
528 |
"return log base 10 of the receiver" |
|
529 |
||
530 |
^ self log:10 |
|
531 |
! |
|
532 |
||
533 |
log:aNumber |
|
534 |
"return log base aNumber of the receiver" |
|
535 |
||
536 |
^ self ln / aNumber ln |
|
537 |
! |
|
538 |
||
539 |
sqrt |
|
540 |
"return the square root of the receiver" |
|
541 |
||
542 |
^ self asFloat sqrt |
|
543 |
! |
|
544 |
||
545 |
floorLog:radix |
|
546 |
"return the logarithm truncated as an integer" |
|
547 |
||
548 |
^ (self log:radix) floor |
|
549 |
! |
|
550 |
||
551 |
raisedTo:aNumber |
|
552 |
"return the receiver raised to aNumber" |
|
553 |
||
554 |
aNumber = 0 ifTrue:[^ 1]. |
|
555 |
aNumber = 1 ifTrue:[^ self]. |
|
556 |
aNumber isInteger ifTrue:[ |
|
213 | 557 |
^ self raisedToInteger:aNumber |
1 | 558 |
]. |
559 |
^ self asFloat raisedTo:aNumber |
|
560 |
! |
|
561 |
||
562 |
raisedToInteger:anInteger |
|
563 |
"return the receiver raised to anInteger" |
|
564 |
||
565 |
|count result| |
|
566 |
||
567 |
result := self coerce:1. |
|
568 |
count := anInteger abs. |
|
569 |
count timesRepeat:[result := result * self]. |
|
570 |
(anInteger < 0) ifTrue:[ |
|
213 | 571 |
^ 1 / result |
1 | 572 |
]. |
573 |
^ result |
|
574 |
! ! |
|
575 |
||
576 |
!ArithmeticValue methodsFor:'trigonometric'! |
|
577 |
||
578 |
sin |
|
579 |
"return the sine of the receiver (interpreted as radians)" |
|
580 |
||
581 |
^ self asFloat sin |
|
582 |
! |
|
583 |
||
584 |
cos |
|
585 |
"return the cosine of the receiver (interpreted as radians)" |
|
586 |
||
587 |
^ self asFloat cos |
|
588 |
! |
|
589 |
||
590 |
tan |
|
591 |
"return the tangens of the receiver (interpreted as radians)" |
|
592 |
||
593 |
^ self asFloat tan |
|
594 |
! |
|
595 |
||
596 |
arcCos |
|
597 |
"return the arccosine of the receiver (in radians)" |
|
598 |
||
599 |
^ self asFloat arcCos |
|
600 |
! |
|
601 |
||
602 |
arcSin |
|
603 |
"return the arcsine of the receiver (in radians)" |
|
604 |
||
605 |
^ self asFloat arcSin |
|
606 |
! |
|
607 |
||
608 |
arcTan |
|
609 |
"return the arctangens of the receiver (in radians)" |
|
610 |
||
611 |
^ self asFloat arcTan |
|
612 |
! ! |
|
613 |
||
614 |
!ArithmeticValue methodsFor:'testing'! |
|
615 |
||
616 |
negative |
|
617 |
"return true, if the receiver is < 0" |
|
618 |
||
619 |
" this would lead to infinite recursion ... |
|
620 |
^ (self < 0) |
|
621 |
" |
|
622 |
^ self subclassResponsibility |
|
623 |
! |
|
624 |
||
625 |
positive |
|
626 |
"return true, if the receiver is >= 0" |
|
627 |
||
628 |
^ self negative not |
|
629 |
! |
|
630 |
||
631 |
strictlyPositive |
|
632 |
"return true, if the receiver is > 0" |
|
633 |
||
634 |
^ (self > 0) |
|
635 |
! |
|
636 |
||
637 |
sign |
|
638 |
"return the sign of the receiver" |
|
639 |
||
640 |
(self < 0) ifTrue:[^ -1]. |
|
641 |
(self > 0) ifTrue:[^ 1]. |
|
642 |
^ 0 |
|
643 |
! |
|
644 |
||
645 |
even |
|
646 |
"return true if the receiver is divisible by 2" |
|
647 |
||
648 |
^ self truncated asInteger even |
|
649 |
! |
|
650 |
||
651 |
odd |
|
652 |
"return true if the receiver is not divisible by 2" |
|
653 |
||
654 |
^ self even not |
|
655 |
! |
|
656 |
||
657 |
denominator |
|
658 |
"return the denominator of the receiver" |
|
659 |
||
660 |
^ 1 |
|
661 |
! |
|
662 |
||
663 |
numerator |
|
664 |
"return the numerator of the receiver." |
|
665 |
||
666 |
^ self |
|
667 |
! ! |