equal
deleted
inserted
replaced
13 " |
13 " |
14 |
14 |
15 "{ Package: 'stx:libbasic' }" |
15 "{ Package: 'stx:libbasic' }" |
16 |
16 |
17 Fraction subclass:#FixedPoint |
17 Fraction subclass:#FixedPoint |
18 instanceVariableNames:'scale' |
18 instanceVariableNames:'scale' |
19 classVariableNames:'PI_1000' |
19 classVariableNames:'PI_1000' |
20 poolDictionaries:'' |
20 poolDictionaries:'' |
21 category:'Magnitude-Numbers' |
21 category:'Magnitude-Numbers' |
22 ! |
22 ! |
23 |
23 |
24 FixedPoint comment:' |
24 FixedPoint comment:' |
25 Description: This class implements infinite precision fixed-point numbers. |
25 Description: This class implements infinite precision fixed-point numbers. |
26 It doesn''t really do anything too interesting except creating instances, converting, and printing, |
26 It doesn''t really do anything too interesting except creating instances, converting, and printing, |
280 "return the product of the receiver and the argument, aNumber. |
280 "return the product of the receiver and the argument, aNumber. |
281 Redefined to care for the scale if the argument is another fixPoint number. |
281 Redefined to care for the scale if the argument is another fixPoint number. |
282 The results scale is the maximum of the receivers scale and the arguments |
282 The results scale is the maximum of the receivers scale and the arguments |
283 scale." |
283 scale." |
284 |
284 |
285 |n d| |
|
286 |
|
287 aNumber isInteger ifTrue:[ |
285 aNumber isInteger ifTrue:[ |
288 ^ self class |
286 ^ self class |
289 numerator:(numerator * aNumber) |
287 numerator:(numerator * aNumber) |
290 denominator:denominator |
288 denominator:denominator |
291 scale:scale |
289 scale:scale |
292 ]. |
290 ]. |
293 (aNumber isFraction) ifTrue:[ |
291 aNumber isFraction ifTrue:[ |
294 n := numerator * aNumber numerator. |
|
295 d := denominator * aNumber denominator. |
|
296 |
|
297 ^ self class |
292 ^ self class |
298 numerator:n |
293 numerator:(numerator * aNumber numerator) |
299 denominator:d |
294 denominator:(denominator * aNumber denominator) |
300 scale:(scale max:aNumber scale) |
295 scale:(scale max:aNumber scale) |
301 ]. |
296 ]. |
302 ^ aNumber productFromFixedPoint:self |
297 ^ aNumber productFromFixedPoint:self |
303 |
298 |
304 " |
299 " |
571 "return the quotient of the receiver and the argument, aNumber. |
566 "return the quotient of the receiver and the argument, aNumber. |
572 Redefined to care for the scale if the argument is another fixPoint number. |
567 Redefined to care for the scale if the argument is another fixPoint number. |
573 The results scale is the maximum of the receivers scale and the arguments |
568 The results scale is the maximum of the receivers scale and the arguments |
574 scale." |
569 scale." |
575 |
570 |
576 |n d| |
|
577 |
|
578 aNumber isInteger ifTrue:[ |
571 aNumber isInteger ifTrue:[ |
579 ^ (self class |
|
580 numerator:numerator |
|
581 denominator:(denominator * aNumber) |
|
582 scale:scale) |
|
583 ]. |
|
584 |
|
585 (aNumber isFraction) ifTrue:[ |
|
586 n := numerator * aNumber denominator. |
|
587 d := denominator * aNumber numerator. |
|
588 |
|
589 ^ self class |
572 ^ self class |
590 numerator:n |
573 numerator:numerator |
591 denominator:d |
574 denominator:(denominator * aNumber) |
|
575 scale:scale |
|
576 ]. |
|
577 |
|
578 aNumber isFraction ifTrue:[ |
|
579 ^ self class |
|
580 numerator:(numerator * aNumber denominator) |
|
581 denominator:(denominator * aNumber numerator) |
592 scale:(scale max:aNumber scale) |
582 scale:(scale max:aNumber scale) |
593 ]. |
583 ]. |
594 ^ aNumber quotientFromFixedPoint:self |
584 ^ aNumber quotientFromFixedPoint:self |
595 |
585 |
596 " |
586 " |
965 ! ! |
955 ! ! |
966 |
956 |
967 !FixedPoint class methodsFor:'documentation'! |
957 !FixedPoint class methodsFor:'documentation'! |
968 |
958 |
969 version |
959 version |
970 ^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.20 2002-08-02 13:54:37 penk Exp $' |
960 ^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.21 2002-11-25 09:19:48 stefan Exp $' |
971 ! ! |
961 ! ! |