author | Claus Gittinger <cg@exept.de> |
Tue, 02 Oct 2001 10:15:17 +0200 | |
changeset 6063 | e07421c13ca0 |
parent 5552 | 31b5cc144476 |
child 6064 | 04bde2eeb749 |
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' |
17 |
classVariableNames:'FractionOne FractionZero' |
|
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 |
|
324 | 42 |
integers. Fractions are usually created by dividing Integers using / |
1295 | 43 |
(for exact division). |
44 |
||
1892 | 45 |
Mixed mode arithmetic: |
5364 | 46 |
fraction op fraction -> fraction |
47 |
fraction op fix -> fix; scale is fix's scale |
|
48 |
fraction op integer -> fraction |
|
49 |
fraction op float -> float |
|
1892 | 50 |
|
1295 | 51 |
[author:] |
5364 | 52 |
Claus Gittinger |
1556 | 53 |
|
54 |
[see also:] |
|
5364 | 55 |
Number |
56 |
Float Integer FixedPoint |
|
1295 | 57 |
" |
88 | 58 |
! ! |
1 | 59 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
60 |
!Fraction class methodsFor:'initialization'! |
1 | 61 |
|
62 |
initialize |
|
302 | 63 |
FractionZero isNil ifTrue:[ |
5364 | 64 |
FractionZero := self numerator:0 denominator:1. |
65 |
FractionOne := self numerator:1 denominator:1 |
|
302 | 66 |
] |
1 | 67 |
! ! |
68 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
69 |
!Fraction class methodsFor:'instance creation'! |
1 | 70 |
|
71 |
new |
|
72 |
"create and return a new fraction with value 0" |
|
73 |
||
54 | 74 |
^ self numerator:0 denominator:1 |
1 | 75 |
! |
76 |
||
77 |
numerator:num denominator:den |
|
78 |
"create and return a new fraction with numerator num and denominator den" |
|
79 |
||
2792 | 80 |
|newFraction| |
81 |
||
1 | 82 |
%{ /* NOCONTEXT */ |
369 | 83 |
|
13 | 84 |
/* this check allows subclassing .. */ |
1 | 85 |
if (self == Fraction) { |
5364 | 86 |
if (__bothSmallInteger(num, den)) { |
87 |
if (__CanDoQuickAlignedNew(sizeof(struct __Fraction))) { /* OBJECT ALLOCATION */ |
|
88 |
OBJ newFraction; |
|
89 |
int spc; |
|
1 | 90 |
|
5364 | 91 |
__qCheckedAlignedNew(newFraction, sizeof(struct __Fraction)); |
92 |
__InstPtr(newFraction)->o_class = self; |
|
93 |
if (__intVal(den) < 0) { |
|
94 |
__FractionInstPtr(newFraction)->f_numerator = __MKSMALLINT(- __intVal(num)); |
|
95 |
__FractionInstPtr(newFraction)->f_denominator = __MKSMALLINT(- __intVal(den)); |
|
96 |
} else { |
|
97 |
__FractionInstPtr(newFraction)->f_numerator = num; |
|
98 |
__FractionInstPtr(newFraction)->f_denominator = den; |
|
99 |
} |
|
100 |
if (num == __MKSMALLINT(1)) { |
|
101 |
RETURN ( newFraction ); |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
1 | 105 |
} |
2790 | 106 |
%}. |
2792 | 107 |
newFraction isNil ifTrue:[ |
5364 | 108 |
newFraction := self basicNew setNumerator:num denominator:den. |
2792 | 109 |
]. |
110 |
^ newFraction reduced |
|
1 | 111 |
! ! |
112 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
113 |
!Fraction class methodsFor:'constants'! |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
114 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
115 |
pi |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
116 |
"return the constant pi as Fraction" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
117 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
118 |
^ self |
6063 | 119 |
numerator: 314159265358979323846264343 |
120 |
denominator:100000000000000000000000000 |
|
121 |
||
122 |
"/ ^ self |
|
123 |
"/ numerator: 314159265358979323846264338327950288419716939937510582097494459 |
|
124 |
"/ denominator:100000000000000000000000000000000000000000000000000000000000000 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
125 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
126 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
127 |
Fraction pi |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
128 |
Fraction pi asFloat |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
129 |
Float pi |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
130 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
131 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
132 |
"Modified: 5.11.1996 / 11:11:44 / cg" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
133 |
! |
701 | 134 |
|
135 |
unity |
|
1555 | 136 |
"return the neutral element for multiplication (1 / 1)" |
701 | 137 |
|
138 |
^ FractionOne |
|
1555 | 139 |
|
140 |
"Modified: 18.7.1996 / 12:26:06 / cg" |
|
701 | 141 |
! |
142 |
||
143 |
zero |
|
1555 | 144 |
"return the neutral element for addition (0 / 1)" |
701 | 145 |
|
146 |
^ FractionZero |
|
1555 | 147 |
|
148 |
"Modified: 18.7.1996 / 12:26:12 / cg" |
|
701 | 149 |
! ! |
150 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
151 |
!Fraction class methodsFor:'queries'! |
3 | 152 |
|
153 |
isBuiltInClass |
|
1264 | 154 |
"return true if this class is known by the run-time-system. |
155 |
Here, true is returned for myself, false for subclasses." |
|
3 | 156 |
|
157 |
^ self == Fraction |
|
1264 | 158 |
|
159 |
"Modified: 23.4.1996 / 15:59:10 / cg" |
|
3 | 160 |
! ! |
161 |
||
1 | 162 |
!Fraction methodsFor:'accessing'! |
163 |
||
164 |
denominator |
|
165 |
"return the denominator" |
|
166 |
||
167 |
^ denominator |
|
168 |
! |
|
169 |
||
701 | 170 |
numerator |
171 |
"return the numerator" |
|
1 | 172 |
|
701 | 173 |
^ numerator |
1 | 174 |
! ! |
175 |
||
176 |
!Fraction methodsFor:'arithmetic'! |
|
177 |
||
701 | 178 |
* aNumber |
179 |
"return the product of the receiver and the argument, aNumber" |
|
180 |
||
181 |
|n d| |
|
182 |
||
183 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
5364 | 184 |
^ (self class numerator:(numerator * aNumber) |
185 |
denominator:denominator) |
|
701 | 186 |
]. |
187 |
aNumber isFraction ifTrue:[ |
|
5364 | 188 |
aNumber isFixedPoint ifFalse:[ "/ the value was corrent, but the scale is lost |
189 |
n := numerator * aNumber numerator. |
|
190 |
d := denominator * aNumber denominator. |
|
191 |
^ (self class numerator:n denominator:d) |
|
192 |
] |
|
701 | 193 |
]. |
194 |
(aNumber isMemberOf:Float) ifTrue:[ |
|
5364 | 195 |
^ (numerator * aNumber) / denominator |
701 | 196 |
]. |
197 |
^ aNumber productFromFraction:self |
|
1892 | 198 |
|
2792 | 199 |
"Modified: 28.7.1997 / 19:09:23 / cg" |
701 | 200 |
! |
201 |
||
1 | 202 |
+ aNumber |
203 |
"return the sum of the receiver and the argument, aNumber" |
|
204 |
||
205 |
|n d| |
|
206 |
||
207 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
5364 | 208 |
^ (self class numerator:(numerator + (denominator * aNumber)) |
209 |
denominator:denominator) |
|
1 | 210 |
]. |
259 | 211 |
aNumber isFraction ifTrue:[ |
5364 | 212 |
aNumber isFixedPoint ifFalse:[ "/ the value was corrent, but the scale is lost |
213 |
n := aNumber numerator. |
|
214 |
d := aNumber denominator. |
|
1 | 215 |
|
5364 | 216 |
"save a multiplication if possible" |
217 |
denominator == d ifTrue:[ |
|
218 |
n := numerator + n |
|
219 |
] ifFalse:[ |
|
220 |
n := (numerator * d) + (n * denominator). |
|
221 |
d := denominator * d. |
|
222 |
]. |
|
223 |
^ (self class numerator:n denominator:d) |
|
224 |
] |
|
1 | 225 |
]. |
16 | 226 |
(aNumber isMemberOf:Float) ifTrue:[ |
5364 | 227 |
^ aNumber + (numerator asFloat / denominator asFloat) |
16 | 228 |
]. |
1 | 229 |
^ aNumber sumFromFraction:self |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
230 |
|
2792 | 231 |
"Modified: 28.7.1997 / 19:09:16 / cg" |
1 | 232 |
! |
233 |
||
234 |
- aNumber |
|
235 |
"return the difference of the receiver and the argument, aNumber" |
|
236 |
||
237 |
|n d| |
|
238 |
||
239 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
5364 | 240 |
^ (self class numerator:(numerator - (denominator * aNumber)) |
241 |
denominator:denominator) |
|
1 | 242 |
]. |
259 | 243 |
aNumber isFraction ifTrue:[ |
5364 | 244 |
aNumber isFixedPoint ifFalse:[ "/ the value was corrent, but the scale is lost |
245 |
n := aNumber numerator. |
|
246 |
d := aNumber denominator. |
|
1 | 247 |
|
5364 | 248 |
"save a multiplication if possible" |
249 |
denominator == d ifTrue:[ |
|
250 |
n := numerator - n |
|
251 |
] ifFalse:[ |
|
252 |
n := (numerator * d) - (n * denominator). |
|
253 |
d := denominator * d |
|
254 |
]. |
|
255 |
^ (self class numerator:n denominator:d) |
|
256 |
] |
|
1 | 257 |
]. |
16 | 258 |
(aNumber isMemberOf:Float) ifTrue:[ |
5364 | 259 |
^ (numerator asFloat / denominator asFloat) - aNumber |
16 | 260 |
]. |
1 | 261 |
^ aNumber differenceFromFraction:self |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
262 |
|
1892 | 263 |
" |
264 |
(1/3) - (1/9) |
|
265 |
(1/9) - (1/3) |
|
266 |
(999/1000) - (1/1000) |
|
267 |
(999/1000) - (1/1000000) |
|
268 |
(999000/1000000) - (1/1000000) |
|
269 |
" |
|
270 |
||
2792 | 271 |
"Modified: 28.7.1997 / 19:09:11 / cg" |
1 | 272 |
! |
273 |
||
274 |
/ aNumber |
|
275 |
"return the quotient of the receiver and the argument, aNumber" |
|
276 |
||
277 |
|n d| |
|
278 |
||
16 | 279 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
5364 | 280 |
^ (self class numerator:numerator |
281 |
denominator:(denominator * aNumber)) |
|
16 | 282 |
]. |
259 | 283 |
aNumber isFraction ifTrue:[ |
5364 | 284 |
aNumber isFixedPoint ifFalse:[ "/ the value was corrent, but the scale is lost |
285 |
n := numerator * aNumber denominator. |
|
286 |
d := denominator * aNumber numerator. |
|
287 |
^ (self class numerator:n denominator:d) |
|
288 |
] |
|
1 | 289 |
]. |
16 | 290 |
(aNumber isMemberOf:Float) ifTrue:[ |
5364 | 291 |
^ numerator / (denominator * aNumber) |
16 | 292 |
]. |
1 | 293 |
^ aNumber quotientFromFraction:self |
1892 | 294 |
|
2792 | 295 |
"Modified: 28.7.1997 / 19:09:06 / cg" |
1 | 296 |
! |
297 |
||
298 |
// aNumber |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
299 |
"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
|
300 |
truncation towards negative infinity." |
1 | 301 |
|
302 |
^ (numerator * aNumber denominator) // (denominator * aNumber numerator) |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
303 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
304 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
305 |
0.5 // 1 |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
306 |
-0.5 // 1 |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3899
diff
changeset
|
307 |
(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
|
308 |
(-1/2) // 1 = -1 ifFalse:[self halt]. |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
309 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
310 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3899
diff
changeset
|
311 |
"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
|
312 |
"Modified: / 13.2.1998 / 09:15:35 / stefan" |
1 | 313 |
! |
314 |
||
315 |
negated |
|
316 |
"optional - could use inherited method ..." |
|
317 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
318 |
^ self class |
5364 | 319 |
numerator:(numerator negated) |
320 |
denominator:denominator |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
321 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
322 |
"Modified: 5.11.1996 / 10:29:11 / cg" |
1 | 323 |
! |
324 |
||
325 |
reciprocal |
|
326 |
"optional - could use inherited method ..." |
|
327 |
||
328 |
numerator == 1 ifTrue:[^ denominator]. |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
329 |
^ self class |
5364 | 330 |
numerator:denominator |
331 |
denominator:numerator |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
332 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
333 |
"Modified: 5.11.1996 / 10:29:22 / cg" |
1 | 334 |
! ! |
335 |
||
701 | 336 |
!Fraction methodsFor:'coercing & converting'! |
337 |
||
1892 | 338 |
asFixedPoint |
339 |
"return the receiver as fixedPoint number. |
|
340 |
Q: what should the scale be here ?" |
|
341 |
||
342 |
^ FixedPoint numerator:numerator denominator:denominator scale:2 |
|
343 |
||
344 |
" |
|
345 |
(1/2) asFixedPoint |
|
346 |
" |
|
347 |
||
348 |
"Created: 5.11.1996 / 15:15:54 / cg" |
|
349 |
! |
|
350 |
||
2140 | 351 |
asFixedPoint:scale |
352 |
"return the receiver as fixedPoint number, with the given number |
|
353 |
of post-decimal-point digits." |
|
354 |
||
355 |
^ FixedPoint numerator:numerator denominator:denominator scale:scale |
|
356 |
||
357 |
" |
|
358 |
(1/2) asFixedPoint:2 |
|
359 |
(1/3) asFixedPoint:2 |
|
360 |
(1/3) asFixedPoint:5 |
|
361 |
(2/3) asFixedPoint:2 |
|
362 |
(2/3) asFixedPoint:5 |
|
363 |
" |
|
364 |
||
365 |
"Created: 5.11.1996 / 15:15:54 / cg" |
|
366 |
"Modified: 10.1.1997 / 19:54:50 / cg" |
|
367 |
! |
|
368 |
||
701 | 369 |
asFloat |
370 |
"return a float with (approximately) my value" |
|
371 |
||
372 |
^ (numerator asFloat) / (denominator asFloat) |
|
373 |
! |
|
1 | 374 |
|
701 | 375 |
asFraction |
376 |
"return the receiver as fraction - thats itself" |
|
377 |
||
378 |
^ self |
|
379 |
! |
|
380 |
||
381 |
asInteger |
|
382 |
"return an integer with my value - will usually truncate" |
|
1 | 383 |
|
384 |
^ numerator // denominator |
|
385 |
! |
|
386 |
||
701 | 387 |
asLargeInteger |
388 |
"return an integer with my value - will usually truncate" |
|
389 |
||
390 |
^ self asInteger asLargeInteger |
|
391 |
! |
|
392 |
||
1200 | 393 |
asShortFloat |
394 |
"return a shortFloat with (approximately) my value" |
|
395 |
||
396 |
^ (numerator asShortFloat) / (denominator asShortFloat) |
|
397 |
||
398 |
"Created: 17.4.1996 / 12:21:08 / cg" |
|
399 |
! |
|
400 |
||
701 | 401 |
coerce:aNumber |
402 |
"return aNumber converted into receivers type" |
|
403 |
||
404 |
^ aNumber asFraction |
|
405 |
! |
|
406 |
||
407 |
generality |
|
408 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
409 |
||
410 |
^ 60 |
|
411 |
! ! |
|
412 |
||
413 |
!Fraction methodsFor:'comparing'! |
|
414 |
||
415 |
< aNumber |
|
416 |
"return true if the receiver is less |
|
417 |
than aNumber, false otherwise." |
|
1 | 418 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
419 |
|d n| |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
420 |
|
701 | 421 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
5364 | 422 |
^ numerator < (denominator * aNumber) |
701 | 423 |
]. |
424 |
aNumber isFraction ifTrue:[ |
|
5364 | 425 |
d := aNumber denominator. |
426 |
n := aNumber numerator. |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
427 |
|
5364 | 428 |
"/ save a multiplication if possible |
429 |
d == denominator ifTrue:[ |
|
430 |
^ numerator < n |
|
431 |
]. |
|
432 |
^ (numerator * d) < (denominator * n) |
|
701 | 433 |
]. |
434 |
^ aNumber lessFromFraction:self |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
435 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
436 |
"Modified: 5.11.1996 / 10:30:52 / cg" |
701 | 437 |
! |
438 |
||
439 |
= aNumber |
|
440 |
"return true, if the argument represents the same numeric value |
|
441 |
as the receiver, false otherwise" |
|
442 |
||
443 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
5364 | 444 |
(denominator = 1) ifFalse:[^ false]. |
445 |
^ numerator = aNumber |
|
1 | 446 |
]. |
701 | 447 |
aNumber isFraction ifTrue:[ |
5364 | 448 |
denominator = aNumber denominator ifTrue:[ |
449 |
^ numerator = aNumber numerator |
|
450 |
]. |
|
451 |
^ self sameFractionValueAs:aNumber |
|
3631
26a44b284912
handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
452 |
]. |
26a44b284912
handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
453 |
(aNumber isInteger) ifTrue:[ |
5364 | 454 |
(denominator = 1) ifFalse:[^ false]. |
455 |
^ numerator = aNumber |
|
701 | 456 |
]. |
457 |
^ self retry:#= coercing:aNumber |
|
3631
26a44b284912
handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
458 |
|
26a44b284912
handle largeInteger case in Fraction =
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
459 |
"Modified: / 7.7.1998 / 17:17:07 / cg" |
701 | 460 |
! |
461 |
||
462 |
> aNumber |
|
463 |
"return true if the receiver is greater |
|
464 |
than aNumber, false otherwise." |
|
465 |
"optional - could use inherited method ..." |
|
466 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
467 |
|d n| |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
468 |
|
701 | 469 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
5364 | 470 |
^ numerator > (denominator * aNumber) |
701 | 471 |
]. |
472 |
aNumber isFraction ifTrue:[ |
|
5364 | 473 |
d := aNumber denominator. |
474 |
n := aNumber numerator. |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
475 |
|
5364 | 476 |
"/ save a multiplication if possible |
477 |
d == denominator ifTrue:[ |
|
478 |
^ numerator > n |
|
479 |
]. |
|
480 |
^ (numerator * d) > (denominator * n) |
|
701 | 481 |
]. |
482 |
^ self retry:#> coercing:aNumber |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
483 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
484 |
"Modified: 5.11.1996 / 10:31:28 / cg" |
4593 | 485 |
! |
486 |
||
487 |
hash |
|
488 |
"return a number for hashing; redefined, since fractions compare |
|
489 |
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
|
490 |
as 3 hash." |
4593 | 491 |
|
492 |
(denominator = 1) ifTrue:[^ numerator hash]. |
|
493 |
||
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
494 |
^ self asFloat hash |
4593 | 495 |
|
496 |
" |
|
497 |
3 hash |
|
498 |
(9/3) hash |
|
499 |
3.0 hash |
|
500 |
(1/2) hash |
|
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
501 |
(1/4) hash |
4593 | 502 |
0.0 hash |
503 |
0.5 hash |
|
504 |
0.25 hash |
|
505 |
0.4 hash |
|
506 |
" |
|
5364 | 507 |
! |
508 |
||
509 |
sameFractionValueAs:aNumber |
|
510 |
"return true, if the argument represents the same numeric value |
|
511 |
as the receiver, false otherwise" |
|
512 |
||
513 |
|rSelf rNum| |
|
514 |
||
515 |
rSelf := self reduced. |
|
516 |
rNum := aNumber reduced. |
|
517 |
rSelf denominator = rNum denominator ifTrue:[ |
|
518 |
^ rSelf numerator = rNum numerator |
|
519 |
]. |
|
520 |
^ false |
|
1 | 521 |
! ! |
522 |
||
523 |
!Fraction methodsFor:'double dispatching'! |
|
524 |
||
701 | 525 |
differenceFromFloat:aFloat |
526 |
"sent when a float does not know how to subtract the receiver, a fraction" |
|
1 | 527 |
|
701 | 528 |
^ (aFloat * denominator - numerator) / denominator |
1 | 529 |
! |
530 |
||
531 |
differenceFromInteger:anInteger |
|
213 | 532 |
"sent when an integer does not know how to subtract the receiver, a fraction" |
1 | 533 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
534 |
^ (self class |
5364 | 535 |
numerator:((anInteger * denominator) - numerator) |
536 |
denominator:denominator) |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
537 |
|
2792 | 538 |
"Modified: 28.7.1997 / 19:08:53 / cg" |
1 | 539 |
! |
540 |
||
701 | 541 |
lessFromInteger:anInteger |
542 |
"sent when an integer does not know how to compare to the receiver, a fraction" |
|
543 |
||
544 |
^ (denominator * anInteger) < numerator |
|
545 |
! |
|
546 |
||
547 |
productFromFloat:aFloat |
|
548 |
"sent when a float does not know how to multiply the receiver, a fraction" |
|
549 |
||
550 |
^ aFloat * numerator / denominator |
|
551 |
! |
|
552 |
||
1 | 553 |
productFromInteger:anInteger |
213 | 554 |
"sent when an integer does not know how to multiply the receiver, a fraction" |
1 | 555 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
556 |
^ (self class |
5364 | 557 |
numerator:(anInteger * numerator) |
558 |
denominator:denominator) |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
559 |
|
2792 | 560 |
"Modified: 28.7.1997 / 19:06:22 / cg" |
1 | 561 |
! |
562 |
||
701 | 563 |
quotientFromFloat:aFloat |
564 |
"sent when a float does not know how to divide by the receiver, a fraction" |
|
565 |
||
566 |
^ (aFloat * denominator) / numerator |
|
567 |
! |
|
568 |
||
324 | 569 |
quotientFromInteger:anInteger |
570 |
"sent when an integer does not know how to divide by the receiver, a fraction" |
|
571 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
572 |
^ (self class |
5364 | 573 |
numerator:(anInteger * denominator) |
574 |
denominator:numerator) |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
575 |
|
2792 | 576 |
"Modified: 28.7.1997 / 19:08:46 / cg" |
324 | 577 |
! |
578 |
||
1 | 579 |
sumFromFloat:aFloat |
213 | 580 |
"sent when a float does not know how to add the receiver, a fraction" |
1 | 581 |
|
582 |
^ (aFloat * denominator + numerator) / denominator |
|
583 |
! |
|
584 |
||
701 | 585 |
sumFromInteger:anInteger |
586 |
"sent when an integer does not know how to add the receiver, a fraction" |
|
1 | 587 |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
588 |
^ (self class |
5364 | 589 |
numerator:(numerator + (anInteger * denominator)) |
590 |
denominator:denominator) |
|
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
591 |
|
2792 | 592 |
"Modified: 28.7.1997 / 19:08:40 / cg" |
1 | 593 |
! ! |
594 |
||
92 | 595 |
!Fraction methodsFor:'printing & storing'! |
1 | 596 |
|
54 | 597 |
printOn:aStream |
598 |
"append a printed representation of the receiver to the |
|
599 |
argument, aStream" |
|
600 |
||
601 |
aStream nextPut:$(. |
|
602 |
numerator printOn:aStream. |
|
603 |
aStream nextPut:$/. |
|
604 |
denominator printOn:aStream. |
|
605 |
aStream nextPut:$) |
|
1 | 606 |
! ! |
701 | 607 |
|
608 |
!Fraction methodsFor:'private'! |
|
609 |
||
610 |
reduced |
|
611 |
"reduce the receiver" |
|
612 |
||
2790 | 613 |
|gcd den| |
701 | 614 |
|
2790 | 615 |
den := denominator. |
616 |
den < 0 ifTrue:[ |
|
5364 | 617 |
numerator := numerator negated. |
618 |
den := denominator := den negated. |
|
2789
e3e8707d26b4
make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents:
2140
diff
changeset
|
619 |
]. |
e3e8707d26b4
make certain, that denominator is positive (in #reduce)
Claus Gittinger <cg@exept.de>
parents:
2140
diff
changeset
|
620 |
|
2790 | 621 |
den == 1 ifTrue:[^ numerator]. |
701 | 622 |
numerator == 1 ifTrue:[^ self]. |
623 |
numerator == 0 ifTrue:[^ 0]. |
|
624 |
||
2790 | 625 |
gcd := numerator gcd:den. |
626 |
(gcd ~~ 1) ifTrue:[ |
|
5364 | 627 |
numerator := numerator // gcd. |
628 |
denominator := den := den // gcd. |
|
629 |
den < 0 ifTrue:[ |
|
630 |
numerator := numerator negated. |
|
631 |
den := denominator := den negated. |
|
632 |
]. |
|
633 |
(den == 1) ifTrue:[^ numerator]. |
|
701 | 634 |
]. |
635 |
^ self |
|
636 |
! |
|
637 |
||
638 |
setNumerator:num denominator:den |
|
639 |
"set both numerator and denominator" |
|
640 |
||
641 |
numerator := num. |
|
642 |
denominator := den |
|
643 |
! ! |
|
644 |
||
645 |
!Fraction methodsFor:'queries'! |
|
646 |
||
647 |
isFraction |
|
648 |
"return true, if the receiver is some kind of fraction; |
|
649 |
true is returned here - the method is redefined from Object." |
|
650 |
||
651 |
^ true |
|
652 |
! ! |
|
653 |
||
654 |
!Fraction methodsFor:'testing'! |
|
655 |
||
4658
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
656 |
isLiteral |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
657 |
"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
|
658 |
(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
|
659 |
|
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
660 |
^ true |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
661 |
|
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
662 |
! |
1a74754fbe91
moved isLiteral (complex and FixedPoint are not)
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
663 |
|
701 | 664 |
negative |
665 |
"return true if the receiver is negative" |
|
666 |
||
667 |
(numerator < 0) ifTrue:[ |
|
5364 | 668 |
^ (denominator < 0) not |
701 | 669 |
]. |
670 |
^ (denominator < 0) |
|
671 |
! ! |
|
672 |
||
5552 | 673 |
!Fraction methodsFor:'truncation & rounding'! |
701 | 674 |
|
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
675 |
fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
676 |
"extract the after-decimal fraction part." |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
677 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
678 |
numerator < denominator ifTrue:[ |
5364 | 679 |
^ self |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
680 |
]. |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
681 |
^ super fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
682 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
683 |
" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
684 |
(3/2) fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
685 |
(2/3) fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
686 |
((3/2)*(15/4)) fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
687 |
((2/3)*(4/15)) fractionPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
688 |
" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
689 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
690 |
"Modified: / 28.10.1998 / 17:15:11 / cg" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
691 |
! |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
692 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
693 |
integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
694 |
"extract the pre-decimal integer part." |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
695 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
696 |
numerator < denominator ifTrue:[ |
5364 | 697 |
^ 0 |
3899
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
698 |
]. |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
699 |
^ super integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
700 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
701 |
" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
702 |
(3/2) integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
703 |
(2/3) integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
704 |
((3/2)*(15/4)) integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
705 |
((2/3)*(4/15)) integerPart |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
706 |
" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
707 |
|
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
708 |
"Modified: / 28.10.1998 / 17:16:10 / cg" |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
709 |
! |
aa9b50cdfced
added #fractionPart and #integerPart
Claus Gittinger <cg@exept.de>
parents:
3631
diff
changeset
|
710 |
|
701 | 711 |
rounded |
712 |
"return the receiver rounded to the nearest integer as integer" |
|
713 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
714 |
"/ mhmh - what about -(1/2) |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
715 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
716 |
|t| |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
717 |
|
701 | 718 |
self negative ifTrue:[ |
5364 | 719 |
t := self - (1/2) |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
720 |
] ifFalse:[ |
5364 | 721 |
t := self + (1/2) |
701 | 722 |
]. |
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
723 |
^ t truncated. |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
724 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
725 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
726 |
(1/3) rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
727 |
(1/3) negated rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
728 |
(1/2) rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
729 |
(1/2) negated rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
730 |
0.5 rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
731 |
-0.5 rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
732 |
(2/3) rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
733 |
(2/3) negated rounded |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
734 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
735 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
736 |
"Modified: 5.11.1996 / 11:32:32 / cg" |
701 | 737 |
! |
738 |
||
739 |
truncated |
|
740 |
"return the receiver truncated towards zero as Integer" |
|
741 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
742 |
^ numerator quo: denominator |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
743 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
744 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
745 |
(3/2) truncated |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
746 |
(3/2) negated truncated |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
747 |
" |
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
748 |
|
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
749 |
"Modified: 5.11.1996 / 12:18:46 / cg" |
701 | 750 |
! ! |
751 |
||
1878
5615af5e7f47
fixed truncated & rounded for negative fractions
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
752 |
!Fraction class methodsFor:'documentation'! |
701 | 753 |
|
754 |
version |
|
6063 | 755 |
^ '$Header: /cvs/stx/stx/libbasic/Fraction.st,v 1.51 2001-10-02 08:15:03 cg Exp $' |
701 | 756 |
! ! |
757 |
Fraction initialize! |