author | Claus Gittinger <cg@exept.de> |
Tue, 17 Jun 2003 16:11:23 +0200 | |
changeset 7403 | 857702a5a921 |
parent 7380 | c704ff45bb80 |
child 7442 | 1b0a20747a64 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
5364 | 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 |
||
5552 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
Number subclass:#Fraction |
5552 | 16 |
instanceVariableNames:'numerator denominator' |
6675 | 17 |
classVariableNames:'FractionOne FractionZero PrintWholeNumbers' |
5552 | 18 |
poolDictionaries:'' |
19 |
category:'Magnitude-Numbers' |
|
1 | 20 |
! |
21 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
22 |
!Fraction class methodsFor:'documentation'! |
88 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
5364 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Instances of Fraction represent fractional numbers consisting of |
|
41 |
a numerator and denominator. Both are themselfes arbitrary precision |
|
6675 | 42 |
integers. |
43 |
Fractions are usually created by dividing Integers using / (for exact division). |
|
44 |
Notice, that all operations on fractions reduce their result; this means, that |
|
45 |
the result of a fraction-operation may return an integer. |
|
46 |
Aka: |
|
47 |
(1 / 7) * 7 -> 1 (not 0.99999999...) |
|
1295 | 48 |
|
1892 | 49 |
Mixed mode arithmetic: |
6675 | 50 |
fraction op fraction -> fraction/integer |
5364 | 51 |
fraction op fix -> fix; scale is fix's scale |
6675 | 52 |
fraction op integer -> fraction/integer |
5364 | 53 |
fraction op float -> float |
1892 | 54 |
|
6675 | 55 |
|
56 |
[classVariables:] |
|
57 |
PrintWholeNumbers Booolean experimental: |
|
58 |
controls how fractions which are greater than 1 are printed. |
|
59 |
if true, print them as a sum of an integral and the fractional part. |
|
60 |
(Large ones are easier to read this way) |
|
61 |
(17/3) printString -> '(5+(2/3))' |
|
62 |
for now, the default is false, for backward compatibility |
|
63 |
||
1295 | 64 |
[author:] |
5364 | 65 |
Claus Gittinger |
1556 | 66 |
|
67 |
[see also:] |
|
5364 | 68 |
Number |
7380 | 69 |
FixedPoint Float ShortFloat LongFloat Integer Complex |
1295 | 70 |
" |
88 | 71 |
! ! |
1 | 72 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
73 |
!Fraction class methodsFor:'initialization'! |
1 | 74 |
|
75 |
initialize |
|
302 | 76 |
FractionZero isNil ifTrue:[ |
5364 | 77 |
FractionZero := self numerator:0 denominator:1. |
78 |
FractionOne := self numerator:1 denominator:1 |
|
302 | 79 |
] |
1 | 80 |
! ! |
81 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
82 |
!Fraction class methodsFor:'instance creation'! |
1 | 83 |
|
84 |
new |
|
85 |
"create and return a new fraction with value 0" |
|
86 |
||
54 | 87 |
^ self numerator:0 denominator:1 |
1 | 88 |
! |
89 |
||
90 |
numerator:num denominator:den |
|
91 |
"create and return a new fraction with numerator num and denominator den" |
|
92 |
||
2792 | 93 |
|newFraction| |
94 |
||
1 | 95 |
%{ /* NOCONTEXT */ |
369 | 96 |
|
13 | 97 |
/* this check allows subclassing .. */ |
1 | 98 |
if (self == Fraction) { |
5364 | 99 |
if (__bothSmallInteger(num, den)) { |
100 |
if (__CanDoQuickAlignedNew(sizeof(struct __Fraction))) { /* OBJECT ALLOCATION */ |
|
101 |
OBJ newFraction; |
|
102 |
int spc; |
|
7140
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
103 |
INT iDen; |
1 | 104 |
|
5364 | 105 |
__qCheckedAlignedNew(newFraction, sizeof(struct __Fraction)); |
106 |
__InstPtr(newFraction)->o_class = self; |
|
7140
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
107 |
iDen = __intVal(den); |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
108 |
if (iDen != 0) { |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
109 |
if (iDen < 0) { |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
110 |
__FractionInstPtr(newFraction)->f_numerator = __MKSMALLINT(- __intVal(num)); |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
111 |
__FractionInstPtr(newFraction)->f_denominator = __MKSMALLINT(- iDen); |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
112 |
} else { |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
113 |
__FractionInstPtr(newFraction)->f_numerator = num; |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
114 |
__FractionInstPtr(newFraction)->f_denominator = den; |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
115 |
} |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
116 |
if (num == __MKSMALLINT(1)) { |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
117 |
/* no need to reduce */ |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
118 |
RETURN ( newFraction ); |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
119 |
} |
5364 | 120 |
} |
121 |
} |
|
122 |
} |
|
1 | 123 |
} |
2790 | 124 |
%}. |
7140
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
125 |
den == 0 ifTrue:[ |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
126 |
^ ZeroDivide raiseRequestWith:thisContext. |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
127 |
]. |
2792 | 128 |
newFraction isNil ifTrue:[ |
7140
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
129 |
newFraction := self basicNew setNumerator:num denominator:den. |
2792 | 130 |
]. |
131 |
^ newFraction reduced |
|
7140
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
132 |
|
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
133 |
" |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
134 |
Fraction numerator:1 denominator:3 |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
135 |
Fraction numerator:2 denominator:6 |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
136 |
|
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
137 |
Fraction numerator:1 denominator:0 |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
138 |
Fraction numerator:2 denominator:0 |
f65ec31fc081
oops - noone cared for generating fractions with 0 denominator
Claus Gittinger <cg@exept.de>
parents:
7139
diff
changeset
|
139 |
" |
1 | 140 |
! ! |
141 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
142 |
!Fraction class methodsFor:'constants'! |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
143 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
144 |
pi |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
145 |
"return the constant pi as Fraction" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
146 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
147 |
^ self |
6063 | 148 |
numerator: 314159265358979323846264343 |
149 |
denominator:100000000000000000000000000 |
|
150 |
||
151 |
"/ ^ self |
|
152 |
"/ numerator: 314159265358979323846264338327950288419716939937510582097494459 |
|
153 |
"/ denominator:100000000000000000000000000000000000000000000000000000000000000 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
154 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
155 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
156 |
Fraction pi |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
157 |
Fraction pi asFloat |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
158 |
Float pi |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
159 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
160 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
161 |
"Modified: 5.11.1996 / 11:11:44 / cg" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
162 |
! |
701 | 163 |
|
164 |
unity |
|
1555 | 165 |
"return the neutral element for multiplication (1 / 1)" |
701 | 166 |
|
167 |
^ FractionOne |
|
1555 | 168 |
|
169 |
"Modified: 18.7.1996 / 12:26:06 / cg" |
|
701 | 170 |
! |
171 |
||
172 |
zero |
|
1555 | 173 |
"return the neutral element for addition (0 / 1)" |
701 | 174 |
|
175 |
^ FractionZero |
|
1555 | 176 |
|
177 |
"Modified: 18.7.1996 / 12:26:12 / cg" |
|
701 | 178 |
! ! |
179 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
180 |
!Fraction class methodsFor:'queries'! |
3 | 181 |
|
182 |
isBuiltInClass |
|
1264 | 183 |
"return true if this class is known by the run-time-system. |
184 |
Here, true is returned for myself, false for subclasses." |
|
3 | 185 |
|
186 |
^ self == Fraction |
|
1264 | 187 |
|
188 |
"Modified: 23.4.1996 / 15:59:10 / cg" |
|
3 | 189 |
! ! |
190 |
||
1 | 191 |
!Fraction methodsFor:'accessing'! |
192 |
||
193 |
denominator |
|
194 |
"return the denominator" |
|
195 |
||
196 |
^ denominator |
|
197 |
! |
|
198 |
||
701 | 199 |
numerator |
200 |
"return the numerator" |
|
1 | 201 |
|
701 | 202 |
^ numerator |
1 | 203 |
! ! |
204 |
||
205 |
!Fraction methodsFor:'arithmetic'! |
|
206 |
||
701 | 207 |
* aNumber |
208 |
"return the product of the receiver and the argument, aNumber" |
|
209 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
210 |
"/ notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
211 |
"/ the following code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
212 |
"/ and exists as an optimization, to speed up those cases. |
7355 | 213 |
"/ also notice, that checks for those cases must be inlinable without |
214 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
215 |
"/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
216 |
"/ Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
217 |
"/ mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
218 |
"/ (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
219 |
|
7355 | 220 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
6646 | 221 |
^ self class |
222 |
numerator:(numerator * aNumber) |
|
223 |
denominator:denominator |
|
701 | 224 |
]. |
225 |
(aNumber isMemberOf:Float) ifTrue:[ |
|
5364 | 226 |
^ (numerator * aNumber) / denominator |
701 | 227 |
]. |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
228 |
|
701 | 229 |
^ aNumber productFromFraction:self |
1892 | 230 |
|
2792 | 231 |
"Modified: 28.7.1997 / 19:09:23 / cg" |
701 | 232 |
! |
233 |
||
1 | 234 |
+ aNumber |
235 |
"return the sum of the receiver and the argument, aNumber" |
|
236 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
237 |
"/ notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
238 |
"/ the following code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
239 |
"/ and exists as an optimization, to speed up those cases. |
7355 | 240 |
"/ also notice, that checks for those cases must be inlinable without |
241 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
242 |
"/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
243 |
"/ Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
244 |
"/ mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
245 |
"/ (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
246 |
|
7355 | 247 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
6646 | 248 |
^ self class |
7355 | 249 |
numerator:(numerator + (denominator * aNumber)) |
250 |
denominator:denominator |
|
1 | 251 |
]. |
16 | 252 |
(aNumber isMemberOf:Float) ifTrue:[ |
7355 | 253 |
^ (numerator asFloat / denominator asFloat) + aNumber |
16 | 254 |
]. |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
255 |
|
1 | 256 |
^ aNumber sumFromFraction:self |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
257 |
|
2792 | 258 |
"Modified: 28.7.1997 / 19:09:16 / cg" |
1 | 259 |
! |
260 |
||
261 |
- aNumber |
|
262 |
"return the difference of the receiver and the argument, aNumber" |
|
263 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
264 |
"/ notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
265 |
"/ the following code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
266 |
"/ and exists as an optimization, to speed up those cases. |
7355 | 267 |
"/ also notice, that checks for those cases must be inlinable without |
268 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
269 |
"/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
270 |
"/ Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
271 |
"/ mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
272 |
"/ (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
273 |
|
7355 | 274 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
6646 | 275 |
^ self class |
276 |
numerator:(numerator - (denominator * aNumber)) |
|
277 |
denominator:denominator |
|
1 | 278 |
]. |
16 | 279 |
(aNumber isMemberOf:Float) ifTrue:[ |
5364 | 280 |
^ (numerator asFloat / denominator asFloat) - aNumber |
16 | 281 |
]. |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
282 |
|
1 | 283 |
^ aNumber differenceFromFraction:self |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
284 |
|
1892 | 285 |
" |
286 |
(1/3) - (1/9) |
|
287 |
(1/9) - (1/3) |
|
288 |
(999/1000) - (1/1000) |
|
289 |
(999/1000) - (1/1000000) |
|
290 |
(999000/1000000) - (1/1000000) |
|
291 |
" |
|
292 |
||
2792 | 293 |
"Modified: 28.7.1997 / 19:09:11 / cg" |
1 | 294 |
! |
295 |
||
296 |
/ aNumber |
|
297 |
"return the quotient of the receiver and the argument, aNumber" |
|
298 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
299 |
"/ notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
300 |
"/ the following code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
301 |
"/ and exists as an optimization, to speed up those cases. |
7355 | 302 |
"/ also notice, that checks for those cases must be inlinable without |
303 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
304 |
"/ |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
305 |
"/ Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
306 |
"/ mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
307 |
"/ (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
308 |
|
7355 | 309 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
6646 | 310 |
^ self class |
311 |
numerator:numerator |
|
312 |
denominator:(denominator * aNumber) |
|
16 | 313 |
]. |
314 |
(aNumber isMemberOf:Float) ifTrue:[ |
|
5364 | 315 |
^ numerator / (denominator * aNumber) |
16 | 316 |
]. |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
317 |
|
1 | 318 |
^ aNumber quotientFromFraction:self |
1892 | 319 |
|
2792 | 320 |
"Modified: 28.7.1997 / 19:09:06 / cg" |
1 | 321 |
! |
322 |
||
323 |
// aNumber |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
324 |
"return the integer quotient of dividing the receiver by aNumber with |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
325 |
truncation towards negative infinity." |
1 | 326 |
|
327 |
^ (numerator * aNumber denominator) // (denominator * aNumber numerator) |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
328 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
329 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
330 |
0.5 // 1 |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
331 |
-0.5 // 1 |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3899
diff
changeset
|
332 |
(1/2) // 1 = 0 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3899
diff
changeset
|
333 |
(-1/2) // 1 = -1 ifFalse:[self halt]. |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
334 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
335 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3899
diff
changeset
|
336 |
"Modified: / 5.11.1996 / 11:47:14 / cg" |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3899
diff
changeset
|
337 |
"Modified: / 13.2.1998 / 09:15:35 / stefan" |
1 | 338 |
! |
339 |
||
340 |
negated |
|
341 |
"optional - could use inherited method ..." |
|
342 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
343 |
^ self class |
5364 | 344 |
numerator:(numerator negated) |
345 |
denominator:denominator |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
346 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
347 |
"Modified: 5.11.1996 / 10:29:11 / cg" |
1 | 348 |
! |
349 |
||
350 |
reciprocal |
|
351 |
"optional - could use inherited method ..." |
|
352 |
||
353 |
numerator == 1 ifTrue:[^ denominator]. |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
354 |
^ self class |
5364 | 355 |
numerator:denominator |
356 |
denominator:numerator |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
357 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
358 |
"Modified: 5.11.1996 / 10:29:22 / cg" |
1 | 359 |
! ! |
360 |
||
701 | 361 |
!Fraction methodsFor:'coercing & converting'! |
362 |
||
1892 | 363 |
asFixedPoint |
364 |
"return the receiver as fixedPoint number. |
|
365 |
Q: what should the scale be here ?" |
|
366 |
||
367 |
^ FixedPoint numerator:numerator denominator:denominator scale:2 |
|
368 |
||
369 |
" |
|
370 |
(1/2) asFixedPoint |
|
371 |
" |
|
372 |
||
373 |
"Created: 5.11.1996 / 15:15:54 / cg" |
|
374 |
! |
|
375 |
||
2140 | 376 |
asFixedPoint:scale |
377 |
"return the receiver as fixedPoint number, with the given number |
|
378 |
of post-decimal-point digits." |
|
379 |
||
380 |
^ FixedPoint numerator:numerator denominator:denominator scale:scale |
|
381 |
||
382 |
" |
|
383 |
(1/2) asFixedPoint:2 |
|
384 |
(1/3) asFixedPoint:2 |
|
385 |
(1/3) asFixedPoint:5 |
|
386 |
(2/3) asFixedPoint:2 |
|
387 |
(2/3) asFixedPoint:5 |
|
388 |
" |
|
389 |
||
390 |
"Created: 5.11.1996 / 15:15:54 / cg" |
|
391 |
"Modified: 10.1.1997 / 19:54:50 / cg" |
|
392 |
! |
|
393 |
||
701 | 394 |
asFloat |
395 |
"return a float with (approximately) my value" |
|
396 |
||
6576 | 397 |
|num den numShift denShift bits| |
6571
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
398 |
|
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
399 |
(numerator class == SmallInteger and:[denominator class == SmallInteger]) ifTrue:[ |
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
400 |
^ (numerator asFloat) / (denominator asFloat) |
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
401 |
]. |
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
402 |
|
6576 | 403 |
"Do it the hard way: reduce magnitude and undo reduction on the quotient" |
6571
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
404 |
|
6576 | 405 |
bits := Float precision * 2. "number of bits to preserve (conservative)" |
6571
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
406 |
num := numerator abs. |
6576 | 407 |
numShift := bits - num highBit. "(num highBit - bits) negated" |
408 |
numShift < 0 ifTrue:[num := num bitShift:numShift] ifFalse:[numShift := 0]. |
|
409 |
||
410 |
den := denominator. |
|
411 |
denShift := bits - den highBit. "(den highBit - bits) negated" |
|
412 |
denShift < 0 ifTrue:[den := den bitShift:denShift] ifFalse:[denShift := 0]. |
|
413 |
||
414 |
^ (num asFloat / den asFloat) * (2.0 raisedToInteger:denShift-numShift) * (num sign) |
|
6571
101905a14870
Fix #asFloat for non-trivial Fractions
Stefan Vogel <sv@exept.de>
parents:
6486
diff
changeset
|
415 |
|
6576 | 416 |
" |
417 |
(5/9) asFloat |
|
418 |
(-5/9) asFloat |
|
419 |
(500000000000/900000000000) asFloat |
|
420 |
(-500000000000/900000000000) asFloat |
|
421 |
(500000000000/9) asFloat |
|
422 |
(5/900000000000) asFloat |
|
423 |
89012345678901234567 asFloat / 123456789123456789 asFloat |
|
424 |
(89012345678901234567 / 123456789123456789) asFloat |
|
425 |
||
426 |
( |
|
427 |
180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125 |
|
428 |
/ |
|
429 |
180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250 |
|
430 |
) asFloat |
|
431 |
||
432 |
180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125 |
|
433 |
asFloat / |
|
434 |
180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250 |
|
435 |
asFloat |
|
436 |
" |
|
701 | 437 |
! |
1 | 438 |
|
701 | 439 |
asFraction |
440 |
"return the receiver as fraction - thats itself" |
|
441 |
||
442 |
^ self |
|
443 |
! |
|
444 |
||
445 |
asInteger |
|
446 |
"return an integer with my value - will usually truncate" |
|
1 | 447 |
|
448 |
^ numerator // denominator |
|
449 |
! |
|
450 |
||
701 | 451 |
asLargeInteger |
452 |
"return an integer with my value - will usually truncate" |
|
453 |
||
454 |
^ self asInteger asLargeInteger |
|
455 |
! |
|
456 |
||
7355 | 457 |
asLongFloat |
458 |
"return a long float with (approximately) my value" |
|
459 |
||
460 |
|num den numShift denShift bits| |
|
461 |
||
462 |
(numerator class == SmallInteger and:[denominator class == SmallInteger]) ifTrue:[ |
|
463 |
^ (numerator asLongFloat) / (denominator asLongFloat) |
|
464 |
]. |
|
465 |
||
466 |
"Do it the hard way: reduce magnitude and undo reduction on the quotient" |
|
467 |
||
468 |
bits := LongFloat precision * 2. "number of bits to preserve (conservative)" |
|
469 |
num := numerator abs. |
|
470 |
numShift := bits - num highBit. "(num highBit - bits) negated" |
|
471 |
numShift < 0 ifTrue:[num := num bitShift:numShift] ifFalse:[numShift := 0]. |
|
472 |
||
473 |
den := denominator. |
|
474 |
denShift := bits - den highBit. "(den highBit - bits) negated" |
|
475 |
denShift < 0 ifTrue:[den := den bitShift:denShift] ifFalse:[denShift := 0]. |
|
476 |
||
477 |
^ (num asLongFloat / den asLongFloat) * (2.0 raisedToInteger:denShift-numShift) * (num sign) |
|
478 |
||
479 |
" |
|
480 |
(5/9) asLongFloat |
|
481 |
(-5/9) asLongFloat |
|
482 |
(500000000000/900000000000) asLongFloat |
|
483 |
(-500000000000/900000000000) asLongFloat |
|
484 |
(500000000000/9) asLongFloat |
|
485 |
(5/900000000000) asLongFloat |
|
486 |
89012345678901234567 asFloat / 123456789123456789 asLongFloat |
|
487 |
(89012345678901234567 / 123456789123456789) asLongFloat |
|
488 |
||
489 |
( |
|
490 |
180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125 |
|
491 |
/ |
|
492 |
180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250 |
|
493 |
) asLongFloat |
|
494 |
||
495 |
180338700661043257034670206806167960222709397862806840937993331366591676308781197477183367018067356365812757479444845320188679437752013593674158587947149815441890236037219685250845721864713487208757788709113534916165172927384095182655935222723385253851776639985379367854545495930551624041981995105743408203125 |
|
496 |
asLongFloat / |
|
497 |
180331613628627651967947866455016278082980736719853750685591387625058011528928110602436691256100991596843001549483950600930062886280582766771424470965440873615557144641435276844465734361353086032476712374317224249252177316815544331763696909434844464464323192083930469387098582956241443753242492675781250 |
|
498 |
asLongFloat |
|
499 |
" |
|
500 |
! |
|
501 |
||
1200 | 502 |
asShortFloat |
6576 | 503 |
"return a short float with (approximately) my value" |
504 |
||
505 |
(numerator class == SmallInteger and:[denominator class == SmallInteger]) ifTrue:[ |
|
506 |
^ (numerator asShortFloat) / (denominator asShortFloat) |
|
507 |
]. |
|
1200 | 508 |
|
6576 | 509 |
^ self asFloat asShortFloat |
1200 | 510 |
|
6576 | 511 |
" |
512 |
(5/9) asShortFloat |
|
513 |
(500000000000/900000000000) asShortFloat |
|
514 |
(500000000000/9) asShortFloat |
|
515 |
" |
|
1200 | 516 |
! |
517 |
||
701 | 518 |
coerce:aNumber |
519 |
"return aNumber converted into receivers type" |
|
520 |
||
521 |
^ aNumber asFraction |
|
522 |
! |
|
523 |
||
524 |
generality |
|
525 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
526 |
||
527 |
^ 60 |
|
528 |
! ! |
|
529 |
||
530 |
!Fraction methodsFor:'comparing'! |
|
531 |
||
532 |
< aNumber |
|
533 |
"return true if the receiver is less |
|
534 |
than aNumber, false otherwise." |
|
1 | 535 |
|
701 | 536 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
5364 | 537 |
^ numerator < (denominator * aNumber) |
701 | 538 |
]. |
539 |
^ aNumber lessFromFraction:self |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
540 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
541 |
"Modified: 5.11.1996 / 10:30:52 / cg" |
701 | 542 |
! |
543 |
||
544 |
= aNumber |
|
545 |
"return true, if the argument represents the same numeric value |
|
546 |
as the receiver, false otherwise" |
|
547 |
||
548 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
6891
212aa8576cf7
oops - did not compare correctly against unnormalized numbers
Claus Gittinger <cg@exept.de>
parents:
6675
diff
changeset
|
549 |
(denominator == 1) ifFalse:[ |
212aa8576cf7
oops - did not compare correctly against unnormalized numbers
Claus Gittinger <cg@exept.de>
parents:
6675
diff
changeset
|
550 |
^ numerator = (aNumber * denominator) |
212aa8576cf7
oops - did not compare correctly against unnormalized numbers
Claus Gittinger <cg@exept.de>
parents:
6675
diff
changeset
|
551 |
]. |
5364 | 552 |
^ numerator = aNumber |
1 | 553 |
]. |
7355 | 554 |
^ aNumber equalFromFraction:self |
3631
26a44b284912
handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
555 |
|
26a44b284912
handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
556 |
"Modified: / 7.7.1998 / 17:17:07 / cg" |
701 | 557 |
! |
558 |
||
559 |
> aNumber |
|
560 |
"return true if the receiver is greater |
|
561 |
than aNumber, false otherwise." |
|
562 |
"optional - could use inherited method ..." |
|
563 |
||
564 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
5364 | 565 |
^ numerator > (denominator * aNumber) |
701 | 566 |
]. |
7355 | 567 |
^ aNumber < self |
4593 | 568 |
! |
569 |
||
570 |
hash |
|
571 |
"return a number for hashing; redefined, since fractions compare |
|
572 |
by numeric value (i.e. (9/3) = 3), therefore (9/3) hash must be the same |
|
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
573 |
as 3 hash." |
4593 | 574 |
|
575 |
(denominator = 1) ifTrue:[^ numerator hash]. |
|
576 |
||
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
577 |
^ self asFloat hash |
4593 | 578 |
|
579 |
" |
|
580 |
3 hash |
|
581 |
(9/3) hash |
|
582 |
3.0 hash |
|
583 |
(1/2) hash |
|
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
584 |
(1/4) hash |
4593 | 585 |
0.0 hash |
586 |
0.5 hash |
|
587 |
0.25 hash |
|
588 |
0.4 hash |
|
589 |
" |
|
5364 | 590 |
! |
591 |
||
592 |
sameFractionValueAs:aNumber |
|
593 |
"return true, if the argument represents the same numeric value |
|
594 |
as the receiver, false otherwise" |
|
595 |
||
596 |
|rSelf rNum| |
|
597 |
||
598 |
rSelf := self reduced. |
|
599 |
rNum := aNumber reduced. |
|
600 |
rSelf denominator = rNum denominator ifTrue:[ |
|
601 |
^ rSelf numerator = rNum numerator |
|
602 |
]. |
|
603 |
^ false |
|
1 | 604 |
! ! |
605 |
||
606 |
!Fraction methodsFor:'double dispatching'! |
|
607 |
||
7355 | 608 |
differenceFromFixedPoint:aFixedPoint |
609 |
|n d otherDenominator otherNumerator| |
|
610 |
||
611 |
otherDenominator := aFixedPoint denominator. |
|
612 |
otherNumerator := aFixedPoint numerator. |
|
613 |
||
614 |
"save a multiplication if possible" |
|
615 |
otherDenominator == denominator ifTrue:[ |
|
616 |
n := otherNumerator - numerator. |
|
617 |
d := otherDenominator. |
|
618 |
] ifFalse:[ |
|
619 |
n := (otherNumerator * denominator) - (numerator * otherDenominator). |
|
620 |
d := otherDenominator * denominator. |
|
621 |
]. |
|
622 |
^ aFixedPoint class |
|
623 |
numerator:n |
|
624 |
denominator:d |
|
625 |
scale:(aFixedPoint scale) |
|
626 |
||
627 |
" |
|
628 |
((1/3) asFixedPoint:2) - (1/3) |
|
629 |
((1/3) asFixedPoint:2) - (2/3) |
|
630 |
" |
|
631 |
! |
|
632 |
||
701 | 633 |
differenceFromFloat:aFloat |
634 |
"sent when a float does not know how to subtract the receiver, a fraction" |
|
1 | 635 |
|
701 | 636 |
^ (aFloat * denominator - numerator) / denominator |
1 | 637 |
! |
638 |
||
7355 | 639 |
differenceFromFraction:aFraction |
640 |
|n d otherDenominator otherNumerator| |
|
641 |
||
642 |
otherDenominator := aFraction denominator. |
|
643 |
otherNumerator := aFraction numerator. |
|
644 |
||
645 |
"save a multiplication if possible" |
|
646 |
otherDenominator == denominator ifTrue:[ |
|
647 |
n := otherNumerator - numerator. |
|
648 |
d := otherDenominator. |
|
649 |
] ifFalse:[ |
|
650 |
n := (otherNumerator * denominator) - (numerator * otherDenominator). |
|
651 |
d := otherDenominator * denominator. |
|
652 |
]. |
|
653 |
^ aFraction class |
|
654 |
numerator:n |
|
655 |
denominator:d |
|
656 |
||
657 |
" |
|
658 |
((1/3) asFixedPoint:2) - (1/3) |
|
659 |
((1/3) asFixedPoint:2) - (2/3) |
|
660 |
" |
|
661 |
! |
|
662 |
||
1 | 663 |
differenceFromInteger:anInteger |
213 | 664 |
"sent when an integer does not know how to subtract the receiver, a fraction" |
1 | 665 |
|
7355 | 666 |
^ self class |
5364 | 667 |
numerator:((anInteger * denominator) - numerator) |
7355 | 668 |
denominator:denominator |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
669 |
|
2792 | 670 |
"Modified: 28.7.1997 / 19:08:53 / cg" |
1 | 671 |
! |
672 |
||
7355 | 673 |
equalFromFraction:aFraction |
674 |
denominator = aFraction denominator ifFalse:[^ false]. |
|
675 |
^ numerator = aFraction numerator |
|
676 |
! |
|
677 |
||
678 |
equalFromInteger:anInteger |
|
679 |
"sent when an integer does not know how to compare to the receiver, a fraction" |
|
680 |
||
681 |
"as I am always reduced, this test should not be required. |
|
682 |
However, it is here for subclasses and to allow comparing unnormalized fractions, |
|
683 |
which might be encountered internally" |
|
684 |
||
685 |
denominator = 1 ifFalse:[^ false]. |
|
686 |
^ numerator = anInteger |
|
687 |
! |
|
688 |
||
689 |
lessFromFraction:aFraction |
|
690 |
"sent when a fraction does not know how to compare to the receiver" |
|
691 |
||
692 |
|n d| |
|
693 |
||
694 |
d := aFraction denominator. |
|
695 |
n := aFraction numerator. |
|
696 |
||
697 |
"/ save a multiplication if possible |
|
698 |
d == denominator ifTrue:[ |
|
699 |
^ n < numerator |
|
700 |
]. |
|
701 |
^ (denominator * n) < (numerator * d) |
|
702 |
! |
|
703 |
||
701 | 704 |
lessFromInteger:anInteger |
705 |
"sent when an integer does not know how to compare to the receiver, a fraction" |
|
706 |
||
707 |
^ (denominator * anInteger) < numerator |
|
708 |
! |
|
709 |
||
7355 | 710 |
productFromFixedPoint:aFixedPoint |
711 |
^ aFixedPoint class |
|
712 |
numerator:(aFixedPoint numerator * numerator) |
|
713 |
denominator:(aFixedPoint denominator * denominator) |
|
714 |
scale:(aFixedPoint scale) |
|
715 |
||
716 |
" |
|
717 |
((1/3) asFixedPoint:2) * 2 |
|
718 |
((1/3) asFixedPoint:2) * (1/2) |
|
719 |
((1/3) asFixedPoint:2) * (3/2) |
|
720 |
" |
|
721 |
! |
|
722 |
||
701 | 723 |
productFromFloat:aFloat |
724 |
"sent when a float does not know how to multiply the receiver, a fraction" |
|
725 |
||
726 |
^ aFloat * numerator / denominator |
|
727 |
! |
|
728 |
||
7355 | 729 |
productFromFraction:aFraction |
730 |
^ aFraction class |
|
731 |
numerator:(aFraction numerator * numerator) |
|
732 |
denominator:(aFraction denominator * denominator) |
|
733 |
||
734 |
" |
|
735 |
((1/3) asFixedPoint:2) * 2 |
|
736 |
((1/3) asFixedPoint:2) * (1/2) |
|
737 |
((1/3) asFixedPoint:2) * (3/2) |
|
738 |
" |
|
739 |
! |
|
740 |
||
1 | 741 |
productFromInteger:anInteger |
213 | 742 |
"sent when an integer does not know how to multiply the receiver, a fraction" |
1 | 743 |
|
7355 | 744 |
^ self class |
5364 | 745 |
numerator:(anInteger * numerator) |
7355 | 746 |
denominator:denominator |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
747 |
|
2792 | 748 |
"Modified: 28.7.1997 / 19:06:22 / cg" |
1 | 749 |
! |
750 |
||
7355 | 751 |
quotientFromFixedPoint:aFixedPoint |
752 |
^ aFixedPoint class |
|
753 |
numerator:(aFixedPoint numerator * denominator) |
|
754 |
denominator:(aFixedPoint denominator * numerator) |
|
755 |
scale:(aFixedPoint scale) |
|
756 |
||
757 |
" |
|
758 |
((1/3) asFixedPoint:2) / 2 |
|
759 |
((1/3) asFixedPoint:2) / (1/2) |
|
760 |
" |
|
761 |
! |
|
762 |
||
701 | 763 |
quotientFromFloat:aFloat |
764 |
"sent when a float does not know how to divide by the receiver, a fraction" |
|
765 |
||
766 |
^ (aFloat * denominator) / numerator |
|
767 |
! |
|
768 |
||
7355 | 769 |
quotientFromFraction:aFraction |
770 |
^ aFraction class |
|
771 |
numerator:(aFraction numerator * denominator) |
|
772 |
denominator:(aFraction denominator * numerator) |
|
773 |
||
774 |
" |
|
775 |
(1/3) / (1/2) |
|
776 |
(1/3) / (3/2) |
|
777 |
" |
|
778 |
! |
|
779 |
||
324 | 780 |
quotientFromInteger:anInteger |
781 |
"sent when an integer does not know how to divide by the receiver, a fraction" |
|
782 |
||
7355 | 783 |
^ self class |
5364 | 784 |
numerator:(anInteger * denominator) |
7355 | 785 |
denominator:numerator |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
786 |
|
2792 | 787 |
"Modified: 28.7.1997 / 19:08:46 / cg" |
324 | 788 |
! |
789 |
||
7355 | 790 |
sumFromFixedPoint:aFixedPoint |
791 |
|n d otherDenominator otherNumerator| |
|
792 |
||
793 |
otherDenominator := aFixedPoint denominator. |
|
794 |
otherNumerator := aFixedPoint numerator. |
|
795 |
||
796 |
"save a multiplication if possible" |
|
797 |
otherDenominator == denominator ifTrue:[ |
|
798 |
n := otherNumerator + numerator. |
|
799 |
d := otherDenominator. |
|
800 |
] ifFalse:[ |
|
801 |
n := (otherNumerator * denominator) + (numerator * otherDenominator). |
|
802 |
d := otherDenominator * denominator. |
|
803 |
]. |
|
804 |
^ aFixedPoint class |
|
805 |
numerator:n |
|
806 |
denominator:d |
|
807 |
scale:(aFixedPoint scale) |
|
808 |
||
809 |
" |
|
810 |
((1/3) asFixedPoint:2) + (1/3) |
|
811 |
((1/3) asFixedPoint:2) + (2/3) |
|
812 |
" |
|
813 |
! |
|
814 |
||
1 | 815 |
sumFromFloat:aFloat |
213 | 816 |
"sent when a float does not know how to add the receiver, a fraction" |
1 | 817 |
|
818 |
^ (aFloat * denominator + numerator) / denominator |
|
819 |
! |
|
820 |
||
7355 | 821 |
sumFromFraction:aFraction |
822 |
|n d otherDenominator otherNumerator| |
|
823 |
||
824 |
otherDenominator := aFraction denominator. |
|
825 |
otherNumerator := aFraction numerator. |
|
826 |
||
827 |
"save a multiplication if possible" |
|
828 |
otherDenominator == denominator ifTrue:[ |
|
829 |
n := otherNumerator + numerator. |
|
830 |
d := otherDenominator. |
|
831 |
] ifFalse:[ |
|
832 |
n := (otherNumerator * denominator) + (numerator * otherDenominator). |
|
833 |
d := otherDenominator * denominator. |
|
834 |
]. |
|
835 |
^ aFraction class |
|
836 |
numerator:n |
|
837 |
denominator:d |
|
838 |
||
839 |
" |
|
840 |
(1/3) + (1/3) |
|
841 |
(1/3) + (2/3) |
|
842 |
" |
|
843 |
! |
|
844 |
||
701 | 845 |
sumFromInteger:anInteger |
846 |
"sent when an integer does not know how to add the receiver, a fraction" |
|
1 | 847 |
|
7355 | 848 |
^ self class |
5364 | 849 |
numerator:(numerator + (anInteger * denominator)) |
7355 | 850 |
denominator:denominator |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
851 |
|
2792 | 852 |
"Modified: 28.7.1997 / 19:08:40 / cg" |
1 | 853 |
! ! |
854 |
||
6486 | 855 |
!Fraction methodsFor:'encoding'! |
856 |
||
857 |
encodeOn:anEncoder with:aParameter |
|
858 |
||
859 |
anEncoder encodeFraction:self with:aParameter |
|
860 |
! ! |
|
861 |
||
92 | 862 |
!Fraction methodsFor:'printing & storing'! |
1 | 863 |
|
54 | 864 |
printOn:aStream |
865 |
"append a printed representation of the receiver to the |
|
866 |
argument, aStream" |
|
867 |
||
6675 | 868 |
|t| |
869 |
||
870 |
PrintWholeNumbers == true ifTrue:[ |
|
871 |
"/ experimental: print fractions which are greater than 1 as a sum of |
|
872 |
"/ an integral and the fractional part. They are easier to read this way. |
|
873 |
numerator > denominator ifTrue:[ |
|
874 |
aStream nextPut:$(. |
|
875 |
t := numerator // denominator. |
|
876 |
t printOn:aStream. |
|
877 |
aStream nextPutAll:'+('. |
|
878 |
(numerator - (t*denominator)) printOn:aStream. |
|
879 |
aStream nextPut:$/. |
|
880 |
denominator printOn:aStream. |
|
881 |
aStream nextPutAll:'))'. |
|
882 |
^ self |
|
883 |
]. |
|
884 |
]. |
|
885 |
||
54 | 886 |
aStream nextPut:$(. |
887 |
numerator printOn:aStream. |
|
888 |
aStream nextPut:$/. |
|
889 |
denominator printOn:aStream. |
|
890 |
aStream nextPut:$) |
|
6675 | 891 |
|
892 |
"Modified: / 31.7.2002 / 09:56:41 / cg" |
|
1 | 893 |
! ! |
701 | 894 |
|
895 |
!Fraction methodsFor:'private'! |
|
896 |
||
897 |
reduced |
|
7139 | 898 |
"reduce the receiver; divide the numerator and denominator by their |
899 |
greatest common divisor; if the result is integral, return an Integer. |
|
900 |
Otherwise, return the normalized receiver. |
|
901 |
(i.e. this is destructive wrt. the instance values)" |
|
701 | 902 |
|
2790 | 903 |
|gcd den| |
701 | 904 |
|
2790 | 905 |
den := denominator. |
906 |
den < 0 ifTrue:[ |
|
5364 | 907 |
numerator := numerator negated. |
908 |
den := denominator := den negated. |
|
2789
e3e8707d26b4
make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents:
2140
diff
changeset
|
909 |
]. |
e3e8707d26b4
make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents:
2140
diff
changeset
|
910 |
|
2790 | 911 |
den == 1 ifTrue:[^ numerator]. |
701 | 912 |
numerator == 1 ifTrue:[^ self]. |
913 |
numerator == 0 ifTrue:[^ 0]. |
|
914 |
||
2790 | 915 |
gcd := numerator gcd:den. |
916 |
(gcd ~~ 1) ifTrue:[ |
|
6576 | 917 |
gcd < 0 ifTrue:[ |
918 |
gcd := gcd negated. |
|
919 |
]. |
|
5364 | 920 |
numerator := numerator // gcd. |
921 |
denominator := den := den // gcd. |
|
922 |
(den == 1) ifTrue:[^ numerator]. |
|
701 | 923 |
]. |
924 |
^ self |
|
925 |
! |
|
926 |
||
927 |
setNumerator:num denominator:den |
|
928 |
"set both numerator and denominator" |
|
929 |
||
930 |
numerator := num. |
|
931 |
denominator := den |
|
932 |
! ! |
|
933 |
||
6650 | 934 |
!Fraction methodsFor:'testing'! |
701 | 935 |
|
936 |
isFraction |
|
937 |
"return true, if the receiver is some kind of fraction; |
|
938 |
true is returned here - the method is redefined from Object." |
|
939 |
||
940 |
^ true |
|
6650 | 941 |
! |
701 | 942 |
|
4658
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
943 |
isLiteral |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
944 |
"return true, if the receiver can be used as a literal constant in ST syntax |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
945 |
(i.e. can be used in constant arrays)" |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
946 |
|
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
947 |
^ true |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
948 |
|
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
949 |
! |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
950 |
|
701 | 951 |
negative |
952 |
"return true if the receiver is negative" |
|
953 |
||
954 |
(numerator < 0) ifTrue:[ |
|
5364 | 955 |
^ (denominator < 0) not |
701 | 956 |
]. |
957 |
^ (denominator < 0) |
|
958 |
! ! |
|
959 |
||
5552 | 960 |
!Fraction methodsFor:'truncation & rounding'! |
701 | 961 |
|
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
962 |
fractionPart |
7355 | 963 |
"extract the after-decimal fraction part, |
964 |
such that (self truncated + self fractionPart) = self" |
|
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
965 |
|
6153
e92766db42c6
integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents:
6064
diff
changeset
|
966 |
numerator abs < denominator abs ifTrue:[ |
5364 | 967 |
^ self |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
968 |
]. |
7355 | 969 |
^ (numerator rem: denominator) / denominator |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
970 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
971 |
" |
7355 | 972 |
(3/2) fractionPart + (3/2) truncated |
973 |
(-3/2) fractionPart + (-3/2) truncated |
|
974 |
||
975 |
(3/2) fractionPart |
|
6153
e92766db42c6
integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents:
6064
diff
changeset
|
976 |
(-3/2) fractionPart |
7355 | 977 |
(3/2) asFloat fractionPart |
978 |
(-3/2) asFloat fractionPart |
|
979 |
(2/3) fractionPart |
|
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
980 |
((3/2)*(15/4)) fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
981 |
((2/3)*(4/15)) fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
982 |
" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
983 |
|
6153
e92766db42c6
integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents:
6064
diff
changeset
|
984 |
"Modified: / 5.11.2001 / 17:55:25 / cg" |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
985 |
! |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
986 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
987 |
integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
988 |
"extract the pre-decimal integer part." |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
989 |
|
6153
e92766db42c6
integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents:
6064
diff
changeset
|
990 |
numerator abs < denominator abs ifTrue:[ |
5364 | 991 |
^ 0 |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
992 |
]. |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
993 |
^ super integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
994 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
995 |
" |
6153
e92766db42c6
integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents:
6064
diff
changeset
|
996 |
(3/2) integerPart |
e92766db42c6
integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents:
6064
diff
changeset
|
997 |
(-3/2) integerPart |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
998 |
(2/3) integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
999 |
((3/2)*(15/4)) integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
1000 |
((2/3)*(4/15)) integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
1001 |
" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
1002 |
|
6153
e92766db42c6
integerPart and fractionPart fixed for negative numbers
Claus Gittinger <cg@exept.de>
parents:
6064
diff
changeset
|
1003 |
"Modified: / 5.11.2001 / 17:55:01 / cg" |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
1004 |
! |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
1005 |
|
701 | 1006 |
rounded |
1007 |
"return the receiver rounded to the nearest integer as integer" |
|
1008 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1009 |
"/ mhmh - what about -(1/2) |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1010 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1011 |
|t| |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1012 |
|
701 | 1013 |
self negative ifTrue:[ |
5364 | 1014 |
t := self - (1/2) |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1015 |
] ifFalse:[ |
5364 | 1016 |
t := self + (1/2) |
701 | 1017 |
]. |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1018 |
^ t truncated. |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1019 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1020 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1021 |
(1/3) rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1022 |
(1/3) negated rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1023 |
(1/2) rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1024 |
(1/2) negated rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1025 |
0.5 rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1026 |
-0.5 rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1027 |
(2/3) rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1028 |
(2/3) negated rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1029 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1030 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1031 |
"Modified: 5.11.1996 / 11:32:32 / cg" |
701 | 1032 |
! |
1033 |
||
1034 |
truncated |
|
1035 |
"return the receiver truncated towards zero as Integer" |
|
1036 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1037 |
^ numerator quo: denominator |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1038 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1039 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1040 |
(3/2) truncated |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1041 |
(3/2) negated truncated |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1042 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1043 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1044 |
"Modified: 5.11.1996 / 12:18:46 / cg" |
701 | 1045 |
! ! |
1046 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1047 |
!Fraction class methodsFor:'documentation'! |
701 | 1048 |
|
1049 |
version |
|
7403 | 1050 |
^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.65 2003-06-17 14:09:33 cg Exp $' |
701 | 1051 |
! ! |
6891
212aa8576cf7
oops - did not compare correctly against unnormalized numbers
Claus Gittinger <cg@exept.de>
parents:
6675
diff
changeset
|
1052 |
|
701 | 1053 |
Fraction initialize! |