changeset 10326 | b1103ad3581f |
parent 10324 | 25973c64a974 |
child 10911 | 38e7677d10a7 |
10325:8a5bcf88a3f0 | 10326:b1103ad3581f |
---|---|
44 |
44 |
45 Notice, that what used to be signals are now exception classes - the class |
45 Notice, that what used to be signals are now exception classes - the class |
46 variables and signal accessors remain here for backward compatibility. |
46 variables and signal accessors remain here for backward compatibility. |
47 |
47 |
48 [class variables:] |
48 [class variables:] |
49 ArithmeticSignal <Error> parent of all arithmetic signals |
49 ArithmeticSignal <Error> parent of all arithmetic signals |
50 (never raised itself) |
50 (never raised itself) |
51 New: now a reference to ArithmeticError |
51 New: now a reference to ArithmeticError |
52 |
52 |
53 DomainErrorSignal <Error> raised upon float errors |
53 DomainErrorSignal <Error> raised upon float errors |
54 (for example range in trigonometric) |
54 (for example range in trigonometric) |
55 New: now a reference to DomainError |
55 New: now a reference to DomainError |
56 |
56 |
57 DivisionByZeroSignal <Error> raised when division by 0 is attempted |
57 DivisionByZeroSignal <Error> raised when division by 0 is attempted |
58 New: now a reference to ZeroDivide |
58 New: now a reference to ZeroDivide |
59 |
59 |
60 OverflowSignal <Error> raised on overflow/underflow conditions |
60 OverflowSignal <Error> raised on overflow/underflow conditions |
61 UnderflowSignal in float arithmetic. |
61 UnderflowSignal in float arithmetic. |
62 Notice: some OperatingSystems do not |
62 Notice: some OperatingSystems do not |
63 provide enough information for ST/X to |
63 provide enough information for ST/X to |
64 extract the real reason for the floatException |
64 extract the real reason for the floatException |
65 thus raising DomainErrorSignal in these cases. |
65 thus raising DomainErrorSignal in these cases. |
66 |
66 |
67 [author:] |
67 [author:] |
68 Claus Gittinger |
68 Claus Gittinger |
69 |
69 |
70 [See also:] |
70 [See also:] |
71 Number |
71 Number |
72 " |
72 " |
73 ! ! |
73 ! ! |
74 |
74 |
75 !ArithmeticValue class methodsFor:'Signal constants'! |
75 !ArithmeticValue class methodsFor:'Signal constants'! |
76 |
76 |
86 |
86 |
87 ^ ConversionError |
87 ^ ConversionError |
88 |
88 |
89 " |
89 " |
90 ConversionError handle:[:ex | |
90 ConversionError handle:[:ex | |
91 Transcript flash |
91 Transcript flash |
92 ] |
92 ] |
93 do:[ |
93 do:[ |
94 (0.0 uncheckedDivide:0.0) asFraction |
94 (0.0 uncheckedDivide:0.0) asFraction |
95 ] |
95 ] |
96 " |
96 " |
97 ! |
97 ! |
98 |
98 |
99 divisionByZeroSignal |
99 divisionByZeroSignal |
141 |
141 |
142 ^ UnderflowError |
142 ^ UnderflowError |
143 ! |
143 ! |
144 |
144 |
145 unorderedSignal |
145 unorderedSignal |
146 "return the signal which is raised when numbers are compared, |
146 "return the signal which is raised when numbers are compared, |
147 for which no ordering is defined (for example: complex numbers)" |
147 for which no ordering is defined (for example: complex numbers)" |
148 |
148 |
149 ^ UnorderedNumbersError |
149 ^ UnorderedNumbersError |
150 ! ! |
150 ! ! |
151 |
151 |
253 |
253 |
254 \\ something |
254 \\ something |
255 "return the receiver modulo something. |
255 "return the receiver modulo something. |
256 The remainder has the same sign as something. |
256 The remainder has the same sign as something. |
257 The following is always true: |
257 The following is always true: |
258 (receiver // something) * something + (receiver \\ something) = receiver |
258 (receiver // something) * something + (receiver \\ something) = receiver |
259 " |
259 " |
260 |
260 |
261 ^ self - ((self // something) * something) |
261 ^ self - ((self // something) * something) |
262 |
262 |
263 " |
263 " |
275 |
275 |
276 (self negative) ifTrue:[^ self negated]. |
276 (self negative) ifTrue:[^ self negated]. |
277 ^ self |
277 ^ self |
278 ! |
278 ! |
279 |
279 |
280 dist:arg |
280 dist:arg |
281 "return the distance between arg and the receiver." |
281 "return the distance between arg and the receiver." |
282 |
282 |
283 ^ (arg - self) abs |
283 ^ (arg - self) abs |
284 |
284 |
285 " |
285 " |
286 (1%1) dist:(0%0) |
286 (1%1) dist:(0%0) |
287 (1@1) dist:(0@0) |
287 (1@1) dist:(0@0) |
288 (1) dist:(0) |
288 (1) dist:(0) |
289 " |
289 " |
290 ! |
290 ! |
291 |
291 |
292 negated |
292 negated |
293 "return the receiver negated" |
293 "return the receiver negated" |
297 |
297 |
298 quo:something |
298 quo:something |
299 "Return the integer quotient of dividing the receiver by the argument |
299 "Return the integer quotient of dividing the receiver by the argument |
300 with truncation towards zero. |
300 with truncation towards zero. |
301 The following is always true: |
301 The following is always true: |
302 (receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver |
302 (receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver |
303 " |
303 " |
304 |
304 |
305 ^ (self / something) truncated |
305 ^ (self / something) truncated |
306 ! |
306 ! |
307 |
307 |
314 rem:something |
314 rem:something |
315 "Return the integer remainder of dividing the receiver by the argument |
315 "Return the integer remainder of dividing the receiver by the argument |
316 with truncation towards zero. |
316 with truncation towards zero. |
317 The remainder has the same sign as the receiver. |
317 The remainder has the same sign as the receiver. |
318 The following is always true: |
318 The following is always true: |
319 (receiver quo: something) * something + (receiver rem: something) = receiver |
319 (receiver quo: something) * something + (receiver rem: something) = receiver |
320 " |
320 " |
321 |
321 |
322 ^ self - ((self quo:something) * something) |
322 ^ self - ((self quo:something) * something) |
323 ! |
323 ! |
324 |
324 |
328 This operation is provided for emulators of other languages/semantics, |
328 This operation is provided for emulators of other languages/semantics, |
329 where no exception is raised for these results (i.e. Java). |
329 where no exception is raised for these results (i.e. Java). |
330 Its only defined if the arguments type is the same as the receivers." |
330 Its only defined if the arguments type is the same as the receivers." |
331 |
331 |
332 aNumber isZero ifTrue:[ |
332 aNumber isZero ifTrue:[ |
333 self isZero ifTrue:[^ self class NaN]. |
333 self isZero ifTrue:[^ self class NaN]. |
334 self negative ifTrue:[^ self class negativeInfinity]. |
334 self negative ifTrue:[^ self class negativeInfinity]. |
335 ^ self class infinity. |
335 ^ self class infinity. |
336 ]. |
336 ]. |
337 ^ self / aNumber |
337 ^ self / aNumber |
338 ! ! |
338 ! ! |
339 |
339 |
340 !ArithmeticValue methodsFor:'coercing & converting'! |
340 !ArithmeticValue methodsFor:'coercing & converting'! |
345 ^ self subclassResponsibility |
345 ^ self subclassResponsibility |
346 ! |
346 ! |
347 |
347 |
348 generality |
348 generality |
349 "return a number giving the receivers generality, that number is |
349 "return a number giving the receivers generality, that number is |
350 used to convert one of the arguments in a mixed expression. |
350 used to convert one of the arguments in a mixed expression. |
351 The generality has to be defined in subclasses, |
351 The generality has to be defined in subclasses, |
352 such that gen(a) > gen(b) iff, conversion of b into a's class |
352 such that gen(a) > gen(b) iff, conversion of b into a's class |
353 does not cut precision. For example, Integer has 40, Float has 80, |
353 does not cut precision. For example, Integer has 40, Float has 80, |
354 meaning that if we convert a Float to an Integer, some precision may |
354 meaning that if we convert a Float to an Integer, some precision may |
355 be lost. The generality is used by ArithmeticValue>>retry:coercing:, |
355 be lost. The generality is used by ArithmeticValue>>retry:coercing:, |
356 which converts the lower-precision number to the higher precision |
356 which converts the lower-precision number to the higher precision |
357 numbers class, when mixed-type arithmetic is performed." |
357 numbers class, when mixed-type arithmetic is performed." |
358 |
358 |
359 ^ self subclassResponsibility |
359 ^ self subclassResponsibility |
360 |
360 |
361 "Modified: / 5.11.1996 / 15:05:30 / cg" |
361 "Modified: / 5.11.1996 / 15:05:30 / cg" |
362 "Modified: / 13.2.1998 / 15:36:01 / stefan" |
362 "Modified: / 13.2.1998 / 15:36:01 / stefan" |
363 ! |
363 ! |
364 |
364 |
365 retry:aSymbol coercing:aNumber |
365 retry:aSymbol coercing:aNumber |
366 "arithmetic represented by the binary operator, aSymbol, |
366 "arithmetic represented by the binary operator, aSymbol, |
367 could not be performed with the receiver and the argument, aNumber, |
367 could not be performed with the receiver and the argument, aNumber, |
368 because of the differences in representation. |
368 because of the differences in representation. |
369 Coerce either the receiver or the argument, depending on which has higher |
369 Coerce either the receiver or the argument, depending on which has higher |
370 generality, and try again. |
370 generality, and try again. |
371 If the operation is compare for same value (=), return false if |
371 If the operation is compare for same value (=), return false if |
372 the argument is not a Number. |
372 the argument is not a Number. |
373 If the generalities are the same, create an error message, since this |
373 If the generalities are the same, create an error message, since this |
374 means that a subclass has not been fully implemented." |
374 means that a subclass has not been fully implemented." |
375 |
375 |
376 |hasGenerality myGenerality otherGenerality| |
376 |hasGenerality myGenerality otherGenerality| |
377 |
377 |
378 hasGenerality := aNumber respondsTo:#generality. |
378 hasGenerality := aNumber respondsTo:#generality. |
379 hasGenerality ifFalse:[ |
379 hasGenerality ifFalse:[ |
380 (aSymbol == #=) ifTrue:[ |
380 (aSymbol == #=) ifTrue:[ |
381 ^ false |
381 ^ false |
382 ]. |
382 ]. |
383 (aSymbol == #~=) ifTrue:[ |
383 (aSymbol == #~=) ifTrue:[ |
384 ^ true |
384 ^ true |
385 ]. |
385 ]. |
386 ^ self error:'retry:coercing: argument is not a number'. |
386 ^ self error:'retry:coercing: argument is not a number'. |
387 ]. |
387 ]. |
388 |
388 |
389 myGenerality := self generality. |
389 myGenerality := self generality. |
390 otherGenerality := aNumber generality. |
390 otherGenerality := aNumber generality. |
391 (myGenerality > otherGenerality) ifTrue:[ |
391 (myGenerality > otherGenerality) ifTrue:[ |
392 ^ self perform:aSymbol with:(self coerce:aNumber) |
392 ^ self perform:aSymbol with:(self coerce:aNumber) |
393 ]. |
393 ]. |
394 (myGenerality < otherGenerality) ifTrue:[ |
394 (myGenerality < otherGenerality) ifTrue:[ |
395 ^ (aNumber coerce:self) perform:aSymbol with:aNumber |
395 ^ (aNumber coerce:self) perform:aSymbol with:aNumber |
396 ]. |
396 ]. |
397 ObjectMemory printStackBacktrace. |
|
398 self error:'retry:coercing: oops - same generality; retry should not happen' |
397 self error:'retry:coercing: oops - same generality; retry should not happen' |
399 |
398 |
400 "Modified: 5.11.1996 / 15:03:38 / cg" |
399 "Modified: 5.11.1996 / 15:03:38 / cg" |
401 ! ! |
400 ! ! |
402 |
401 |
418 ^ self asFraction asFixedPoint |
417 ^ self asFraction asFixedPoint |
419 |
418 |
420 " |
419 " |
421 0.3 asFixedPoint |
420 0.3 asFixedPoint |
422 0.5 asFixedPoint |
421 0.5 asFixedPoint |
423 (1/5) asFloat asFixedPoint |
422 (1/5) asFloat asFixedPoint |
424 (1/3) asFloat asFixedPoint |
423 (1/3) asFloat asFixedPoint |
425 (2/3) asFloat asFixedPoint |
424 (2/3) asFloat asFixedPoint |
426 (1/8) asFloat asFixedPoint |
425 (1/8) asFloat asFixedPoint |
427 3.14159 asFixedPoint |
426 3.14159 asFixedPoint |
428 0.0000001 asFraction |
427 0.0000001 asFraction |
429 0.0000001 asFixedPoint |
428 0.0000001 asFixedPoint |
430 " |
429 " |
437 number of post-decimal-digits." |
436 number of post-decimal-digits." |
438 |
437 |
439 ^ self asFraction asFixedPoint:scale |
438 ^ self asFraction asFixedPoint:scale |
440 |
439 |
441 " |
440 " |
442 0.3 asFixedPoint:4 |
441 0.3 asFixedPoint:4 |
443 0.3 asFixedPoint:3 |
442 0.3 asFixedPoint:3 |
444 0.3 asFixedPoint:2 |
443 0.3 asFixedPoint:2 |
445 0.3 asFixedPoint:1 |
444 0.3 asFixedPoint:1 |
446 0.3 asFixedPoint:0 |
445 0.3 asFixedPoint:0 |
447 |
446 |
448 0.5 asFixedPoint:3 |
447 0.5 asFixedPoint:3 |
449 (1/5) asFloat asFixedPoint:1 |
448 (1/5) asFloat asFixedPoint:1 |
450 (1/8) asFloat asFixedPoint:1 |
449 (1/8) asFloat asFixedPoint:1 |
451 1.0 asFixedPoint:2 |
450 1.0 asFixedPoint:2 |
452 3.14159 asFixedPoint:2 |
451 3.14159 asFixedPoint:2 |
453 3.14159 asFixedPoint:3 |
452 3.14159 asFixedPoint:3 |
454 (3.14159 asFixedPoint:2) asFixedPoint:5 |
453 (3.14159 asFixedPoint:2) asFixedPoint:5 |
455 " |
454 " |
456 ! |
455 ! |
457 |
456 |
458 asFloat |
457 asFloat |
459 "return a float with same value" |
458 "return a float with same value" |
554 ! ! |
553 ! ! |
555 |
554 |
556 !ArithmeticValue methodsFor:'destructive arithmethic'! |
555 !ArithmeticValue methodsFor:'destructive arithmethic'! |
557 |
556 |
558 *= aNumber |
557 *= aNumber |
559 "Return the product of self multiplied by aNumber. |
558 "Return the product of self multiplied by aNumber. |
560 The receiver MAY, but NEED NOT be changed to contain the product. |
559 The receiver MAY, but NEED NOT be changed to contain the product. |
561 So this method must be used as: 'a := a *= 5'. |
560 So this method must be used as: 'a := a *= 5'. |
562 This method can be redefined for constructed datatypes to do optimisations" |
561 This method can be redefined for constructed datatypes to do optimisations" |
563 |
562 |
564 ^ self * aNumber |
563 ^ self * aNumber |
566 "Created: / 28.4.1999 / 11:46:11 / stefan" |
565 "Created: / 28.4.1999 / 11:46:11 / stefan" |
567 "Modified: / 28.4.1999 / 11:53:28 / stefan" |
566 "Modified: / 28.4.1999 / 11:53:28 / stefan" |
568 ! |
567 ! |
569 |
568 |
570 += aNumber |
569 += aNumber |
571 "Return the sum of self and aNumber. |
570 "Return the sum of self and aNumber. |
572 The receiver MAY, but NEED NOT be changed to contain the sum. |
571 The receiver MAY, but NEED NOT be changed to contain the sum. |
573 So this method must be used as: 'a := a += 5'. |
572 So this method must be used as: 'a := a += 5'. |
574 This method can be redefined for constructed datatypes to do optimisations" |
573 This method can be redefined for constructed datatypes to do optimisations" |
575 |
574 |
576 ^ self + aNumber |
575 ^ self + aNumber |
578 "Created: / 28.4.1999 / 10:13:41 / stefan" |
577 "Created: / 28.4.1999 / 10:13:41 / stefan" |
579 "Modified: / 28.4.1999 / 11:54:11 / stefan" |
578 "Modified: / 28.4.1999 / 11:54:11 / stefan" |
580 ! |
579 ! |
581 |
580 |
582 -= aNumber |
581 -= aNumber |
583 "Return the difference of self and aNumber. |
582 "Return the difference of self and aNumber. |
584 The receiver MAY, but NEED NOT be changed to contain the difference. |
583 The receiver MAY, but NEED NOT be changed to contain the difference. |
585 So this method must be used as: 'a := a -= 5'. |
584 So this method must be used as: 'a := a -= 5'. |
586 This method can be redefined for constructed datatypes to do optimisations" |
585 This method can be redefined for constructed datatypes to do optimisations" |
587 |
586 |
588 ^ self - aNumber |
587 ^ self - aNumber |
590 "Created: / 28.4.1999 / 10:13:58 / stefan" |
589 "Created: / 28.4.1999 / 10:13:58 / stefan" |
591 "Modified: / 28.4.1999 / 11:54:37 / stefan" |
590 "Modified: / 28.4.1999 / 11:54:37 / stefan" |
592 ! |
591 ! |
593 |
592 |
594 /= aNumber |
593 /= aNumber |
595 "Return the quotient of self and aNumber. |
594 "Return the quotient of self and aNumber. |
596 The receiver MAY, but NEED NOT be changed to contain the quotient. |
595 The receiver MAY, but NEED NOT be changed to contain the quotient. |
597 So this method must be used as: 'a := a /= 5'. |
596 So this method must be used as: 'a := a /= 5'. |
598 This method can be redefined for constructed datatypes to do optimisations" |
597 This method can be redefined for constructed datatypes to do optimisations" |
599 |
598 |
600 ^ self / aNumber |
599 ^ self / aNumber |
602 "Created: / 28.4.1999 / 11:46:22 / stefan" |
601 "Created: / 28.4.1999 / 11:46:22 / stefan" |
603 "Modified: / 28.4.1999 / 11:55:06 / stefan" |
602 "Modified: / 28.4.1999 / 11:55:06 / stefan" |
604 ! |
603 ! |
605 |
604 |
606 div2 |
605 div2 |
607 "Return the quotient of self divided by 2. |
606 "Return the quotient of self divided by 2. |
608 The receiver MAY, but NEED NOT be changed to contain the result. |
607 The receiver MAY, but NEED NOT be changed to contain the result. |
609 So this method must be used as: 'a := a div2. |
608 So this method must be used as: 'a := a div2. |
610 This method can be redefined for constructed datatypes to do optimisations" |
609 This method can be redefined for constructed datatypes to do optimisations" |
611 |
610 |
612 ^ self // 2 |
611 ^ self // 2 |
614 "Created: / 28.4.1999 / 10:12:44 / stefan" |
613 "Created: / 28.4.1999 / 10:12:44 / stefan" |
615 "Modified: / 28.4.1999 / 11:56:09 / stefan" |
614 "Modified: / 28.4.1999 / 11:56:09 / stefan" |
616 ! |
615 ! |
617 |
616 |
618 mul2 |
617 mul2 |
619 "Return the product of self multiplied by 2. |
618 "Return the product of self multiplied by 2. |
620 The receiver MAY, but NEED NOT be changed to contain the result. |
619 The receiver MAY, but NEED NOT be changed to contain the result. |
621 So this method must be used as: 'a := a mul2. |
620 So this method must be used as: 'a := a mul2. |
622 This method can be redefined for constructed datatypes to do optimisations" |
621 This method can be redefined for constructed datatypes to do optimisations" |
623 |
622 |
624 ^ self * 2 |
623 ^ self * 2 |
994 "Created: 17.4.1996 / 12:34:10 / cg" |
993 "Created: 17.4.1996 / 12:34:10 / cg" |
995 ! ! |
994 ! ! |
996 |
995 |
997 !ArithmeticValue methodsFor:'mathematical functions'! |
996 !ArithmeticValue methodsFor:'mathematical functions'! |
998 |
997 |
999 ** aNumber |
998 ** aNumber |
1000 "Answer the receiver raised to the power of the argument, aNumber." |
999 "Answer the receiver raised to the power of the argument, aNumber." |
1001 "same as Number>>raisedTo:" |
1000 "same as Number>>raisedTo:" |
1002 |
1001 |
1003 ^self raisedTo: aNumber |
1002 ^self raisedTo: aNumber |
1004 |
1003 |
1006 "Modified: / 17-07-2006 / 12:51:33 / cg" |
1005 "Modified: / 17-07-2006 / 12:51:33 / cg" |
1007 ! |
1006 ! |
1008 |
1007 |
1009 raisedTo: aNumber |
1008 raisedTo: aNumber |
1010 aNumber isInteger ifTrue:[ |
1009 aNumber isInteger ifTrue:[ |
1011 ^ self raisedToInteger:aNumber |
1010 ^ self raisedToInteger:aNumber |
1012 ]. |
1011 ]. |
1013 ^ self subclassResponsibility |
1012 ^ self subclassResponsibility |
1014 ! |
1013 ! |
1015 |
1014 |
1016 raisedToInteger:exp |
1015 raisedToInteger:exp |
1017 "return the receiver raised to exp" |
1016 "return the receiver raised to exp" |
1018 |
1017 |
1019 |result e t| |
1018 |result e t| |
1020 |
1019 |
1021 "use the addition chaining algorithm, |
1020 "use the addition chaining algorithm, |
1022 which is much faster for big exp-arguments" |
1021 which is much faster for big exp-arguments" |
1023 |
1022 |
1024 result := 1. |
1023 result := 1. |
1025 t := self. |
1024 t := self. |
1026 exp < 0 ifTrue:[ |
1025 exp < 0 ifTrue:[ |
1027 e := exp negated. |
1026 e := exp negated. |
1028 ] ifFalse:[ |
1027 ] ifFalse:[ |
1029 e := exp. |
1028 e := exp. |
1030 ]. |
1029 ]. |
1031 |
1030 |
1032 [e ~~ 0] whileTrue:[ |
1031 [e ~~ 0] whileTrue:[ |
1033 [(e bitAnd:1) == 0] whileTrue:[ |
1032 [(e bitAnd:1) == 0] whileTrue:[ |
1034 e := e bitShift:-1. |
1033 e := e bitShift:-1. |
1035 t := t * t. |
1034 t := t * t. |
1036 ]. |
1035 ]. |
1037 e := e - 1. |
1036 e := e - 1. |
1038 result := result * t. |
1037 result := result * t. |
1039 ]. |
1038 ]. |
1040 |
1039 |
1041 (exp < 0) ifTrue:[ |
1040 (exp < 0) ifTrue:[ |
1042 ^ 1 / result |
1041 ^ 1 / result |
1043 ]. |
1042 ]. |
1044 |
1043 |
1045 ^ result |
1044 ^ result |
1046 |
1045 |
1047 |
1046 |
1048 " |
1047 " |
1049 (2 raisedToInteger:216) |
1048 (2 raisedToInteger:216) |
1050 (2 raisedTo:216) |
1049 (2 raisedTo:216) |
1051 -> 105312291668557186697918027683670432318895095400549111254310977536 |
1050 -> 105312291668557186697918027683670432318895095400549111254310977536 |
1052 |
1051 |
1053 (2 raisedToInteger:216) asFloat |
1052 (2 raisedToInteger:216) asFloat |
1054 (2 raisedTo:216) asFloat |
1053 (2 raisedTo:216) asFloat |
1055 -> 1.05312E+65 |
1054 -> 1.05312E+65 |
1056 |
1055 |
1057 (2 raisedToInteger:500) |
1056 (2 raisedToInteger:500) |
1058 (2 raisedTo:500) |
1057 (2 raisedTo:500) |
1059 -> 3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376 |
1058 -> 3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376 |
1060 2 raisedToInteger:10 |
1059 2 raisedToInteger:10 |
1061 -> 1024 |
1060 -> 1024 |
1062 -2 raisedToInteger:10 |
1061 -2 raisedToInteger:10 |
1063 -> 1024 |
1062 -> 1024 |
1064 -2 raisedToInteger:9 |
1063 -2 raisedToInteger:9 |
1065 -> -512 |
1064 -> -512 |
1066 10 raisedToInteger:-10 |
1065 10 raisedToInteger:-10 |
1067 -> (1/10000000000) |
1066 -> (1/10000000000) |
1068 2 raisedToInteger:0 |
1067 2 raisedToInteger:0 |
1069 -> 1 |
1068 -> 1 |
1070 2 raisedToInteger:-1 |
1069 2 raisedToInteger:-1 |
1071 -> (1/2) |
1070 -> (1/2) |
1072 |
1071 |
1073 Time millisecondsToRun:[ |
1072 Time millisecondsToRun:[ |
1074 10000 timesRepeat:[ |
1073 10000 timesRepeat:[ |
1075 (2 raisedToInteger:500) |
1074 (2 raisedToInteger:500) |
1076 ] |
1075 ] |
1077 ] |
1076 ] |
1078 |
1077 |
1079 Time millisecondsToRun:[ |
1078 Time millisecondsToRun:[ |
1080 |bigNum| |
1079 |bigNum| |
1081 bigNum := 2 raisedToInteger:500. |
1080 bigNum := 2 raisedToInteger:500. |
1082 10 timesRepeat:[ |
1081 10 timesRepeat:[ |
1083 (bigNum raisedToInteger:500) |
1082 (bigNum raisedToInteger:500) |
1084 ] |
1083 ] |
1085 ] |
1084 ] |
1086 " |
1085 " |
1087 |
1086 |
1088 "Created: / 27.4.1999 / 15:19:22 / stefan" |
1087 "Created: / 27.4.1999 / 15:19:22 / stefan" |
1089 "Modified: / 27.4.1999 / 16:16:11 / stefan" |
1088 "Modified: / 27.4.1999 / 16:16:11 / stefan" |
1125 |
1124 |
1126 "Modified: / 9.7.1998 / 10:19:27 / cg" |
1125 "Modified: / 9.7.1998 / 10:19:27 / cg" |
1127 ! |
1126 ! |
1128 |
1127 |
1129 isFinite |
1128 isFinite |
1130 "return true, if the receiver is finite |
1129 "return true, if the receiver is finite |
1131 i.e. it can be represented as a rational number." |
1130 i.e. it can be represented as a rational number." |
1132 |
1131 |
1133 ^ true |
1132 ^ true |
1134 ! |
1133 ! |
1135 |
1134 |
1232 "return the receiver rounded to multiples of aNumber" |
1231 "return the receiver rounded to multiples of aNumber" |
1233 |
1232 |
1234 ^ (self / aNumber) rounded * aNumber |
1233 ^ (self / aNumber) rounded * aNumber |
1235 |
1234 |
1236 " |
1235 " |
1237 0 roundTo:4 |
1236 0 roundTo:4 |
1238 1 roundTo:4 |
1237 1 roundTo:4 |
1239 2 roundTo:4 |
1238 2 roundTo:4 |
1240 3 roundTo:4 |
1239 3 roundTo:4 |
1241 4 roundTo:4 |
1240 4 roundTo:4 |
1242 5 roundTo:4 |
1241 5 roundTo:4 |
1249 "return the receiver rounded up to the next multiple of aNumber" |
1248 "return the receiver rounded up to the next multiple of aNumber" |
1250 |
1249 |
1251 ^ (self / aNumber) ceiling * aNumber |
1250 ^ (self / aNumber) ceiling * aNumber |
1252 |
1251 |
1253 " |
1252 " |
1254 0 roundUpTo:4 |
1253 0 roundUpTo:4 |
1255 1 roundUpTo:4 |
1254 1 roundUpTo:4 |
1256 2 roundUpTo:4 |
1255 2 roundUpTo:4 |
1257 3 roundUpTo:4 |
1256 3 roundUpTo:4 |
1258 4 roundUpTo:4 |
1257 4 roundUpTo:4 |
1259 5 roundUpTo:4 |
1258 5 roundUpTo:4 |
1260 6 roundUpTo:4 |
1259 6 roundUpTo:4 |
1261 7 roundUpTo:4 |
1260 7 roundUpTo:4 |
1262 8 roundUpTo:4 |
1261 8 roundUpTo:4 |
1263 " |
1262 " |
1264 ! |
1263 ! |
1265 |
1264 |
1266 rounded |
1265 rounded |
1267 "return the integer nearest the receiver" |
1266 "return the integer nearest the receiver" |
1268 |
1267 |
1269 self negative ifTrue:[ |
1268 self negative ifTrue:[ |
1270 ^ (self - 0.5) ceiling |
1269 ^ (self - 0.5) ceiling |
1271 ]. |
1270 ]. |
1272 ^ (self + 0.5) floor |
1271 ^ (self + 0.5) floor |
1273 |
1272 |
1274 "Modified: 5.11.1996 / 11:31:59 / cg" |
1273 "Modified: 5.11.1996 / 11:31:59 / cg" |
1275 ! |
1274 ! |
1290 ! ! |
1289 ! ! |
1291 |
1290 |
1292 !ArithmeticValue class methodsFor:'documentation'! |
1291 !ArithmeticValue class methodsFor:'documentation'! |
1293 |
1292 |
1294 version |
1293 version |
1295 ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.75 2007-01-12 21:11:28 cg Exp $' |
1294 ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.76 2007-01-12 23:18:42 cg Exp $' |
1296 ! ! |
1295 ! ! |
1297 |
1296 |
1298 ArithmeticValue initialize! |
1297 ArithmeticValue initialize! |