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