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