author | Claus Gittinger <cg@exept.de> |
Fri, 17 Feb 2006 14:15:58 +0100 | |
changeset 9133 | 2d3e3d083be8 |
parent 9132 | df7fe5738d18 |
child 9137 | 9692c2409b38 |
permissions | -rw-r--r-- |
1886 | 1 |
" |
3060 | 2 |
This is public domain code, not covered by the ST/X copyright. |
3 |
Code is provided 'as is', as a goody, without any warranty. |
|
4 |
||
1886 | 5 |
this comes from: |
6 |
||
7 |
Jan Steinman, Bytesmiths |
|
8 |
2002 Parkside Court, West Linn, OR 97068-2767 USA, +1 503 657 7703 |
|
9 |
Friedlistrasse 19, CH-3006, Bern, Switzerland, +41 31 999 3946 |
|
10 |
||
11 |
this code was published in comp.lang.smalltalk; |
|
12 |
added here as an example ... |
|
13 |
" |
|
14 |
||
5570 | 15 |
"{ Package: 'stx:libbasic' }" |
16 |
||
1886 | 17 |
Fraction subclass:#FixedPoint |
6895 | 18 |
instanceVariableNames:'scale' |
19 |
classVariableNames:'PI_1000' |
|
20 |
poolDictionaries:'' |
|
21 |
category:'Magnitude-Numbers' |
|
1886 | 22 |
! |
23 |
||
24 |
FixedPoint comment:' |
|
25 |
Description: This class implements infinite precision fixed-point numbers. |
|
26 |
It doesn''t really do anything too interesting except creating instances, converting, and printing, |
|
27 |
since its superclass Fraction does all the work. |
|
28 |
||
29 |
Test: "''123456789012345678901234567890.123456789'' asFixed * 1000000000 = 123456789012345678901234567890123456789" |
|
30 |
||
31 |
Notes: 1) The current implementation does not convert arbitrarily-based String representations, |
|
6704 | 32 |
which shouldn''t be too much a problem for financial types.' |
6237
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
33 |
! |
1886 | 34 |
|
35 |
!FixedPoint class methodsFor:'documentation'! |
|
36 |
||
37 |
copyright |
|
38 |
" |
|
3060 | 39 |
This is public domain code, not covered by the ST/X copyright. |
40 |
Code is provided 'as is', as a goody, without any warranty. |
|
41 |
||
1886 | 42 |
this comes from: |
43 |
||
44 |
Jan Steinman, Bytesmiths |
|
45 |
2002 Parkside Court, West Linn, OR 97068-2767 USA, +1 503 657 7703 |
|
46 |
Friedlistrasse 19, CH-3006, Bern, Switzerland, +41 31 999 3946 |
|
47 |
||
48 |
this code was published in comp.lang.smalltalk; |
|
49 |
added here as an example ... |
|
50 |
" |
|
51 |
! |
|
52 |
||
53 |
documentation |
|
54 |
" |
|
7380 | 55 |
This class implements infinite precision fixed-point numbers, |
1886 | 56 |
which internally hold exact (fractional) results, but print themself with |
57 |
a limited number of digits after the decimal point. |
|
7380 | 58 |
|
1886 | 59 |
These can be used in computation, where rounding errors should not accumulate, |
60 |
but only a limited precision is required for the final result. |
|
1898 | 61 |
(i.e. business applications) |
1886 | 62 |
|
63 |
It doesn't really do anything too interesting except creating instances, |
|
64 |
converting, and printing, since its superclass Fraction does all the work. |
|
65 |
||
66 |
Test: |
|
3060 | 67 |
'123456789012345678901234567890.123456789' asFixedPoint * 1000000000 |
1886 | 68 |
-> 123456789012345678901234567890123456789' |
69 |
||
70 |
Notes: 1) The current implementation does not convert arbitrarily-based |
|
71 |
String representations, which shouldn't be too much a problem |
|
72 |
for financial types. |
|
73 |
||
74 |
2) the implementation is a hack - it has not been optimized for speed |
|
75 |
in particular. |
|
76 |
||
1892 | 77 |
Mixed mode arithmetic: |
78 |
fix op fix -> fix, scale is max. of operands |
|
79 |
fix op fraction -> fix; scale is fix's scale |
|
80 |
fix op integer -> fix; scale is fix's scale |
|
81 |
fix op float -> float |
|
82 |
||
1886 | 83 |
[author:] |
84 |
Jan Steinman, Bytesmiths |
|
3060 | 85 |
adapted, modified & enhanced by Claus Gittinger |
1886 | 86 |
|
87 |
[see also:] |
|
9129 | 88 |
Number Fraction Integer Float ShortFloat LongFloat Complex |
1886 | 89 |
" |
90 |
! |
|
91 |
||
92 |
examples |
|
93 |
" |
|
94 |
[exBegin] |
|
95 |
|a b r| |
|
96 |
||
97 |
a := (FixedPoint fromString:'123.456'). |
|
3060 | 98 |
b := '1.10' asFixedPoint. |
1886 | 99 |
r := a + b. |
100 |
Transcript showCR:r. |
|
101 |
Transcript showCR:(r withScale:2). |
|
102 |
Transcript showCR:(r withScale:1). |
|
103 |
Transcript showCR:(r rounded). |
|
104 |
[exEnd] |
|
105 |
||
106 |
[exBegin] |
|
107 |
|a b r| |
|
108 |
||
109 |
a := (FixedPoint fromString:'0.9999999'). |
|
3060 | 110 |
b := 0.0000001 asFixedPoint. |
1886 | 111 |
r := a + b. |
112 |
Transcript showCR:r. |
|
113 |
Transcript showCR:(r withScale:2). |
|
114 |
Transcript showCR:(r withScale:1). |
|
115 |
Transcript showCR:(r rounded). |
|
116 |
[exEnd] |
|
117 |
||
118 |
[exBegin] |
|
119 |
|a b r| |
|
120 |
||
121 |
a := (FixedPoint fromString:'0.9999998'). |
|
122 |
b := (FixedPoint fromString:'0.0000001'). |
|
123 |
r := a + b. |
|
124 |
Transcript showCR:r. |
|
125 |
Transcript showCR:(r withScale:2). |
|
126 |
Transcript showCR:(r withScale:1). |
|
127 |
Transcript showCR:(r rounded). |
|
128 |
[exEnd] |
|
129 |
||
130 |
[exBegin] |
|
131 |
|a b r| |
|
132 |
||
133 |
a := (FixedPoint fromString:'1.0'). |
|
134 |
b := (FixedPoint fromString:'0.0000001'). |
|
135 |
r := a + b. |
|
136 |
Transcript showCR:r. |
|
137 |
Transcript showCR:(r withScale:2). |
|
138 |
Transcript showCR:(r withScale:1). |
|
139 |
Transcript showCR:(r rounded). |
|
140 |
[exEnd] |
|
141 |
||
142 |
[exBegin] |
|
143 |
|a b r| |
|
144 |
||
145 |
a := (FixedPoint fromString:'0.99'). |
|
146 |
b := (FixedPoint fromString:'0.0000001'). |
|
147 |
r := a + b. |
|
148 |
Transcript showCR:r. |
|
149 |
Transcript showCR:(r withScale:2). |
|
150 |
Transcript showCR:(r withScale:1). |
|
151 |
Transcript showCR:(r rounded). |
|
152 |
[exEnd] |
|
153 |
||
154 |
" |
|
155 |
! ! |
|
156 |
||
157 |
!FixedPoint class methodsFor:'instance creation'! |
|
158 |
||
6237
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
159 |
numerator:n denominator:d |
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
160 |
self shouldNotImplement. "use #numerator:denominator:scale" |
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
161 |
"/ ^ self numerator:n denominator:d scale:(d log max:n log) ceiling |
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
162 |
|
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
163 |
" |
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
164 |
self numerator:123 denominator:100 |
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
165 |
" |
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
166 |
! |
4dc908af4f5c
report an error if #numerator:denominator: is invoked
Claus Gittinger <cg@exept.de>
parents:
5570
diff
changeset
|
167 |
|
1886 | 168 |
numerator:n denominator:d scale:s |
169 |
^ self basicNew |
|
6894
64f27ed2753f
do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents:
6886
diff
changeset
|
170 |
setNumerator:n denominator:d scale:s |
64f27ed2753f
do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents:
6886
diff
changeset
|
171 |
"/ ; reduced |
1886 | 172 |
! |
173 |
||
3060 | 174 |
readFrom:aStringOrStream |
175 |
"return the next FixedPoint from the (character-)stream aStream. |
|
176 |
||
177 |
NOTICE: |
|
178 |
This behaves different from the default readFrom:, in returning |
|
179 |
0 (instead of raising an error) in case no number can be read. |
|
180 |
It is unclear, if this is the correct behavior (ST-80 does this) |
|
181 |
- depending on the upcoming ANSI standard, this may change." |
|
182 |
||
183 |
^ self readFrom:aStringOrStream onError:0 |
|
1886 | 184 |
|
3060 | 185 |
" |
6636
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
186 |
FixedPoint readFrom:'123.456' |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
187 |
FixedPoint readFrom:'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788' |
3060 | 188 |
FixedPoint readFrom:(ReadStream on:'foobar') |
189 |
FixedPoint readFrom:(ReadStream on:'foobar') onError:nil |
|
190 |
" |
|
191 |
||
192 |
"Modified: / 25.10.1997 / 15:30:29 / cg" |
|
6895 | 193 |
! |
194 |
||
195 |
readFrom:aStringOrStream onError:exceptionBlock |
|
196 |
"return an instance of me as described on the string or stream, aStringOrStream. |
|
197 |
If an error occurs during conversion, return the result |
|
198 |
from evaluating exceptionBlock" |
|
199 |
||
200 |
| aStream sign integerPart fractionStream char fractionPart scale | |
|
201 |
||
202 |
aStream := aStringOrStream readStream. |
|
203 |
||
204 |
aStream peek == $- ifTrue:[ |
|
205 |
sign := -1. |
|
206 |
aStream next. |
|
207 |
] ifFalse:[ |
|
208 |
sign := 1 |
|
209 |
]. |
|
210 |
||
211 |
(aStream atEnd or:[aStream peek isLetter]) ifTrue: [^ exceptionBlock value]. |
|
212 |
||
213 |
integerPart := (aStream upTo:$.) asNumber. |
|
214 |
(aStream atEnd or: [aStream peek isLetter]) ifTrue: [ |
|
215 |
fractionPart := 0. |
|
216 |
scale := 1. |
|
217 |
] ifFalse:[ |
|
218 |
fractionStream := ReadWriteStream on:(String new: 10). |
|
219 |
[ |
|
220 |
char := aStream next. |
|
221 |
char ~~ nil and:[char isDigit] |
|
222 |
] whileTrue:[ |
|
223 |
fractionStream nextPut:char |
|
224 |
]. |
|
225 |
||
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
226 |
scale := fractionStream position0Based. |
6895 | 227 |
fractionStream reset. |
228 |
fractionPart := Number readFrom:fractionStream. |
|
229 |
]. |
|
230 |
||
231 |
^ self basicNew |
|
232 |
setNumerator:(integerPart * (10 raisedTo:scale) + fractionPart) * sign |
|
233 |
scale:scale |
|
234 |
||
235 |
" |
|
236 |
FixedPoint readFrom:'1.00' |
|
7053
13e04c48e23c
prep for 0-based stream position
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
237 |
FixedPoint readFrom:'123.456' |
6895 | 238 |
FixedPoint readFrom:'-123.456' |
239 |
FixedPoint readFrom:'123' |
|
240 |
FixedPoint readFrom:'-123' |
|
241 |
FixedPoint readFrom:'-123.abcd' onError:[47.5] |
|
242 |
FixedPoint readFrom:'-1a.bcd' onError:[47.5] |
|
243 |
FixedPoint readFrom:'foot' onError:['bad fixedpoint'] |
|
244 |
" |
|
245 |
||
246 |
"Created: / 25.10.1997 / 15:28:59 / cg" |
|
247 |
"Modified: / 25.10.1997 / 15:31:47 / cg" |
|
1886 | 248 |
! ! |
249 |
||
6636
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
250 |
!FixedPoint class methodsFor:'constants'! |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
251 |
|
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
252 |
pi |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
253 |
"pi with 1000 valid digits..." |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
254 |
|
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
255 |
PI_1000 isNil ifTrue:[ |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
256 |
PI_1000 := self |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
257 |
readFrom:'3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632788' |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
258 |
]. |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
259 |
^ PI_1000. |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
260 |
|
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
261 |
" |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
262 |
self pi squared |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
263 |
self pi reciprocal |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
264 |
1 / self pi |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
265 |
self pi * 1000000000000000000000000000000000000000000 |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
266 |
" |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
267 |
! ! |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
268 |
|
6898 | 269 |
!FixedPoint class methodsFor:'queries'! |
270 |
||
271 |
exponentCharacter |
|
272 |
^ $s |
|
273 |
! ! |
|
274 |
||
1886 | 275 |
!FixedPoint methodsFor:'accessing'! |
276 |
||
277 |
scale |
|
2538 | 278 |
"return the number of places of significance that is carried by the receiver." |
1886 | 279 |
|
280 |
^ scale |
|
2538 | 281 |
|
282 |
"Modified: 12.4.1997 / 11:21:05 / cg" |
|
1886 | 283 |
! ! |
284 |
||
285 |
!FixedPoint methodsFor:'arithmetic'! |
|
286 |
||
287 |
* aNumber |
|
288 |
"return the product of the receiver and the argument, aNumber. |
|
289 |
Redefined to care for the scale if the argument is another fixPoint number. |
|
7355 | 290 |
The results scale is the maximum of the receivers scale and the arguments scale." |
1886 | 291 |
|
7355 | 292 |
"/ notice: |
293 |
"/ the following code handles some common cases, |
|
294 |
"/ and exists as an optimization, to speed up those cases. |
|
295 |
"/ also notice, that checks for those cases must be inlinable without |
|
296 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
297 |
||
298 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
1886 | 299 |
^ self class |
300 |
numerator:(numerator * aNumber) |
|
301 |
denominator:denominator |
|
302 |
scale:scale |
|
303 |
]. |
|
304 |
^ aNumber productFromFixedPoint:self |
|
305 |
||
306 |
" |
|
307 |
|a r| |
|
308 |
||
309 |
a := (FixedPoint fromString:'123.456'). |
|
310 |
r := a * 5. |
|
311 |
Transcript showCR:r. |
|
312 |
Transcript showCR:(r withScale:2). |
|
313 |
" |
|
314 |
||
315 |
" |
|
316 |
|a b r| |
|
317 |
||
318 |
a := (FixedPoint fromString:'123.456'). |
|
319 |
b := (FixedPoint fromString:'1.10'). |
|
320 |
r := a * b. |
|
321 |
Transcript showCR:r. |
|
322 |
Transcript showCR:(r withScale:2). |
|
323 |
" |
|
324 |
||
325 |
" |
|
326 |
|a b r| |
|
327 |
||
328 |
a := (FixedPoint fromString:'123.456'). |
|
329 |
b := (FixedPoint fromString:'-1.10'). |
|
330 |
r := a * b. |
|
331 |
Transcript showCR:r. |
|
332 |
Transcript showCR:(r withScale:2). |
|
333 |
" |
|
334 |
||
335 |
" |
|
336 |
|a b r| |
|
337 |
||
338 |
a := (FixedPoint fromString:'0.9999999'). |
|
339 |
b := (FixedPoint fromString:'0.9999999'). |
|
340 |
r := a * b. |
|
341 |
Transcript show:'fixed (exact) : '; showCR:r. |
|
342 |
Transcript show:'fixed (scale2) : '; showCR:(r withScale:2). |
|
343 |
||
344 |
Transcript show:'float (inexact): '; showCR:(0.9999999 * 0.9999999). |
|
345 |
" |
|
346 |
||
347 |
" |
|
348 |
|a b r| |
|
349 |
||
350 |
a := 1. |
|
351 |
b := (FixedPoint fromString:'0.9999999'). |
|
352 |
r := a * b. |
|
353 |
Transcript show:'fixed (exact) : '; showCR:r. |
|
354 |
Transcript show:'fixed (scale2) : '; showCR:(r withScale:2). |
|
355 |
||
356 |
Transcript show:'float (inexact): '; showCR:(0.9999999 * 0.9999999). |
|
357 |
" |
|
6636
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
358 |
|
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
359 |
" |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
360 |
|a r| |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
361 |
|
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
362 |
a := (FixedPoint fromString:'123.456'). |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
363 |
r := a * 5.0. |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
364 |
Transcript showCR:r. |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
365 |
Transcript showCR:(r withScale:2). |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
366 |
" |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
367 |
|
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
368 |
" |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
369 |
|a r| |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
370 |
|
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
371 |
a := (FixedPoint fromString:'123.456'). |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
372 |
r := 5.0 * a. |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
373 |
Transcript showCR:r. |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
374 |
Transcript showCR:(r withScale:2). |
dedc341eb3ab
arithmetic with integers fixed;
Claus Gittinger <cg@exept.de>
parents:
6625
diff
changeset
|
375 |
" |
1886 | 376 |
! |
377 |
||
378 |
+ aNumber |
|
379 |
"return the sum of the receiver and the argument, aNumber. |
|
380 |
Redefined to care for the scale if the argument is another fixPoint number. |
|
7355 | 381 |
The results scale will be the maximum of the receivers and the arguments scale." |
1886 | 382 |
|
7355 | 383 |
|n| |
1886 | 384 |
|
7355 | 385 |
"/ notice: |
386 |
"/ the following code handles some common cases, |
|
387 |
"/ and exists as an optimization, to speed up those cases. |
|
388 |
"/ also notice, that checks for those cases must be inlinable without |
|
389 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
1886 | 390 |
|
7355 | 391 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
1886 | 392 |
"save a multiplication if possible" |
7355 | 393 |
denominator == 1 ifTrue:[ |
394 |
n := numerator + aNumber. |
|
6645
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
395 |
] ifFalse:[ |
7355 | 396 |
n := numerator + (aNumber * denominator). |
6645
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
397 |
]. |
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
398 |
^ self class |
7355 | 399 |
numerator:n |
400 |
denominator:denominator |
|
401 |
scale:scale |
|
6645
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
402 |
]. |
1886 | 403 |
^ aNumber sumFromFixedPoint:self |
404 |
||
405 |
" |
|
7355 | 406 |
((1/3) asFixedPoint:2) + 1 |
407 |
((1/3) asFixedPoint:2) + (1/3) |
|
408 |
" |
|
409 |
" |
|
1886 | 410 |
|a b| |
411 |
||
412 |
a := (FixedPoint fromString:'123.456'). |
|
413 |
b := (FixedPoint fromString:'1.10'). |
|
414 |
a + b |
|
415 |
" |
|
416 |
" |
|
417 |
|a b| |
|
418 |
||
419 |
a := (FixedPoint fromString:'0.9999999'). |
|
420 |
b := (FixedPoint fromString:'0.0000001'). |
|
421 |
a + b |
|
422 |
" |
|
423 |
||
424 |
" |
|
425 |
|a b| |
|
426 |
||
427 |
a := (FixedPoint fromString:'0.99'). |
|
428 |
b := (FixedPoint fromString:'0.0000001'). |
|
429 |
a + b |
|
430 |
" |
|
431 |
||
432 |
" |
|
433 |
|a b| |
|
434 |
||
435 |
a := (FixedPoint fromString:'0.99'). |
|
436 |
b := (FixedPoint fromString:'0.0000001'). |
|
437 |
(a + b) withScale:2 |
|
438 |
" |
|
439 |
||
440 |
" |
|
441 |
|a b| |
|
442 |
||
443 |
a := (FixedPoint fromString:'0.99'). |
|
444 |
b := (FixedPoint fromString:'0.0000001'). |
|
445 |
(a + b) withScale:1 |
|
446 |
" |
|
447 |
||
448 |
" |
|
449 |
|a b| |
|
450 |
||
451 |
a := 1. |
|
452 |
b := (FixedPoint fromString:'0.0000001'). |
|
453 |
Transcript showCR:((a + b) withScale:1). |
|
454 |
Transcript showCR:(a + b) |
|
455 |
" |
|
456 |
! |
|
457 |
||
458 |
- aNumber |
|
459 |
"return the difference of the receiver and the argument, aNumber. |
|
460 |
Redefined to care for the scale if the argument is another fixPoint number. |
|
7355 | 461 |
The results scale is the maximum of the receivers scale and the arguments scale." |
1886 | 462 |
|
7355 | 463 |
|n| |
1886 | 464 |
|
7355 | 465 |
"/ notice: |
466 |
"/ the following code handles some common cases, |
|
467 |
"/ and exists as an optimization, to speed up those cases. |
|
468 |
"/ also notice, that checks for those cases must be inlinable without |
|
469 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
1886 | 470 |
|
7355 | 471 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
1886 | 472 |
"save a multiplication if possible" |
7355 | 473 |
denominator == 1 ifTrue:[ |
474 |
n := numerator - aNumber. |
|
6645
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
475 |
] ifFalse:[ |
7355 | 476 |
n := numerator - (aNumber * denominator). |
6645
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
477 |
]. |
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
478 |
^ self class |
7355 | 479 |
numerator:n |
480 |
denominator:denominator |
|
481 |
scale:scale |
|
6645
b25be4db9230
arithmetic with other fixedPoints fixed
Claus Gittinger <cg@exept.de>
parents:
6638
diff
changeset
|
482 |
]. |
1886 | 483 |
^ aNumber differenceFromFixedPoint:self |
484 |
||
485 |
" |
|
486 |
|a b| |
|
487 |
||
488 |
a := (FixedPoint fromString:'123.456'). |
|
489 |
b := (FixedPoint fromString:'1.10'). |
|
7355 | 490 |
a - b |
1886 | 491 |
" |
492 |
||
493 |
" |
|
494 |
|a b| |
|
495 |
||
496 |
a := (FixedPoint fromString:'0.9999999'). |
|
497 |
b := (FixedPoint fromString:'0.0000009'). |
|
498 |
a - b |
|
499 |
" |
|
500 |
||
501 |
" |
|
502 |
|a b| |
|
503 |
||
504 |
a := (FixedPoint fromString:'0.99'). |
|
505 |
b := (FixedPoint fromString:'0.0000001'). |
|
506 |
a - b |
|
507 |
" |
|
508 |
||
509 |
" |
|
510 |
|a b| |
|
511 |
||
512 |
a := (FixedPoint fromString:'0.99'). |
|
513 |
b := (FixedPoint fromString:'0.0000001'). |
|
514 |
(a - b) withScale:2 |
|
515 |
" |
|
516 |
||
517 |
" |
|
518 |
|a b| |
|
519 |
||
520 |
a := (FixedPoint fromString:'0.99'). |
|
521 |
b := (FixedPoint fromString:'0.0000001'). |
|
522 |
(a - b) withScale:1 |
|
523 |
" |
|
524 |
||
525 |
" |
|
526 |
|a b| |
|
527 |
||
528 |
a := (FixedPoint fromString:'0.0000001'). |
|
529 |
b := (FixedPoint fromString:'0.99'). |
|
530 |
(a - b) withScale:2 |
|
531 |
" |
|
532 |
||
533 |
" |
|
534 |
|a b| |
|
535 |
||
536 |
a := 1. |
|
537 |
b := (FixedPoint fromString:'0.0000001'). |
|
538 |
Transcript showCR:((a - b) withScale:1). |
|
539 |
Transcript showCR:(a - b) |
|
540 |
" |
|
541 |
! |
|
542 |
||
543 |
/ aNumber |
|
1898 | 544 |
"return the quotient of the receiver and the argument, aNumber. |
1886 | 545 |
Redefined to care for the scale if the argument is another fixPoint number. |
7355 | 546 |
The results scale is the maximum of the receivers scale and the arguments scale." |
1886 | 547 |
|
7355 | 548 |
"/ notice: |
549 |
"/ the following code handles some common cases, |
|
550 |
"/ and exists as an optimization, to speed up those cases. |
|
551 |
"/ also notice, that checks for those cases must be inlinable without |
|
552 |
"/ a message send; otherwise double-dispatch is just as fast. |
|
553 |
||
554 |
(aNumber isMemberOf:SmallInteger) ifTrue:[ |
|
6886 | 555 |
^ self class |
6894
64f27ed2753f
do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents:
6886
diff
changeset
|
556 |
numerator:numerator |
64f27ed2753f
do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents:
6886
diff
changeset
|
557 |
denominator:(denominator * aNumber) |
64f27ed2753f
do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents:
6886
diff
changeset
|
558 |
scale:scale |
1886 | 559 |
]. |
560 |
||
561 |
^ aNumber quotientFromFixedPoint:self |
|
562 |
||
563 |
" |
|
564 |
|a r| |
|
565 |
||
566 |
a := (FixedPoint fromString:'123.456'). |
|
567 |
r := a / 5. |
|
568 |
Transcript showCR:r. |
|
569 |
Transcript showCR:(r withScale:2). |
|
570 |
Transcript showCR:(r withScale:9). |
|
571 |
" |
|
572 |
||
573 |
" |
|
574 |
|a b r| |
|
575 |
||
576 |
a := (FixedPoint fromString:'123.456'). |
|
577 |
b := (FixedPoint fromString:'1.10'). |
|
578 |
r := a / b. |
|
579 |
Transcript showCR:r. |
|
580 |
Transcript showCR:(r withScale:2). |
|
581 |
" |
|
582 |
||
583 |
" |
|
584 |
|a b r| |
|
585 |
||
586 |
a := (FixedPoint fromString:'-123.456'). |
|
587 |
b := (FixedPoint fromString:'-1.10'). |
|
588 |
r := a / b. |
|
589 |
Transcript showCR:r. |
|
590 |
Transcript showCR:(r withScale:2). |
|
591 |
" |
|
592 |
||
593 |
" |
|
594 |
|a b r| |
|
595 |
||
596 |
a := (FixedPoint fromString:'123.456'). |
|
597 |
b := (FixedPoint fromString:'-1.10'). |
|
598 |
r := a / b. |
|
599 |
Transcript showCR:r. |
|
600 |
Transcript showCR:(r withScale:2). |
|
601 |
" |
|
602 |
||
603 |
" |
|
604 |
|a b r| |
|
605 |
||
606 |
a := 1. |
|
607 |
b := (FixedPoint fromString:'0.9999999'). |
|
608 |
r := a / b. |
|
609 |
Transcript show:'fixed (exact) : '; showCR:r. |
|
610 |
Transcript show:'fixed (scale2) : '; showCR:(r withScale:2). |
|
611 |
||
612 |
Transcript show:'float (inexact): '; showCR:(1 / 0.9999999). |
|
613 |
" |
|
6570 | 614 |
! |
615 |
||
616 |
negated |
|
6894
64f27ed2753f
do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents:
6886
diff
changeset
|
617 |
"redefined from Fraction to preserve scale" |
6570 | 618 |
|
619 |
^ self class |
|
620 |
numerator:(numerator negated) |
|
621 |
denominator:denominator |
|
622 |
scale:scale |
|
623 |
! |
|
624 |
||
625 |
reciprocal |
|
6894
64f27ed2753f
do not reduce in instance creation message;
Claus Gittinger <cg@exept.de>
parents:
6886
diff
changeset
|
626 |
"redefined from Fraction to preserve scale" |
6570 | 627 |
|
628 |
numerator == 1 ifTrue:[^ denominator]. |
|
629 |
^ self class |
|
630 |
numerator:denominator |
|
631 |
denominator:numerator |
|
632 |
scale:scale |
|
1886 | 633 |
! ! |
634 |
||
635 |
!FixedPoint methodsFor:'coercing & converting'! |
|
636 |
||
637 |
asFixedPoint |
|
2140 | 638 |
"return the receiver as a fixedPoint number - thats the receiver itself" |
1886 | 639 |
|
640 |
^ self |
|
641 |
||
2140 | 642 |
"Modified: 10.1.1997 / 19:53:14 / cg" |
643 |
! |
|
644 |
||
645 |
asFixedPoint:newScale |
|
7355 | 646 |
"return a fixedPoint with the same value as the receiver, |
647 |
and newScale number of post-decimal digits" |
|
648 |
||
649 |
newScale == scale ifTrue:[^ self]. |
|
2140 | 650 |
|
651 |
^ self class |
|
652 |
numerator:numerator |
|
653 |
denominator:denominator |
|
654 |
scale:newScale |
|
655 |
||
656 |
" |
|
6638 | 657 |
'12345.12345' asFixedPoint:2 |
2140 | 658 |
(FixedPoint fromString:'12345.12345') asFixedPoint:2 |
659 |
||
660 |
((FixedPoint fromString:'0.33333333') |
|
661 |
+ |
|
662 |
(FixedPoint fromString:'0.33333333') |
|
663 |
) asFixedPoint:2 |
|
664 |
" |
|
665 |
||
2538 | 666 |
"Modified: 12.4.1997 / 11:20:37 / cg" |
1886 | 667 |
! |
668 |
||
669 |
asFraction |
|
670 |
"return the receiver as a fraction" |
|
671 |
||
7355 | 672 |
^ Fraction |
1886 | 673 |
numerator:numerator |
7355 | 674 |
denominator:denominator |
1886 | 675 |
|
676 |
" |
|
677 |
(FixedPoint fromString:'0.2') |
|
678 |
(FixedPoint fromString:'0.2') asFraction |
|
679 |
(FixedPoint fromString:'0.2') asFloat |
|
680 |
(FixedPoint fromString:'0.2') asShortFloat |
|
681 |
(FixedPoint fromString:'0.2') asInteger |
|
682 |
" |
|
683 |
! |
|
684 |
||
685 |
coerce:aNumber |
|
686 |
"return aNumber converted into receivers type" |
|
687 |
||
688 |
^ aNumber asFixedPoint |
|
689 |
||
690 |
! |
|
691 |
||
692 |
generality |
|
693 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
694 |
||
695 |
^ 65 |
|
696 |
||
697 |
" |
|
698 |
(FixedPoint fromString:'1.001') + 1 |
|
699 |
(FixedPoint fromString:'1.001') + 1.0 |
|
700 |
(FixedPoint fromString:'1.001') + (1/2) |
|
701 |
(FixedPoint fromString:'1.001') + 1.0 asShortFloat |
|
702 |
(FixedPoint fromString:'1.001') + 1 asLargeInteger |
|
703 |
||
704 |
1 + (FixedPoint fromString:'1.001') |
|
1892 | 705 |
1.0 + (FixedPoint fromString:'1.001') |
1891 | 706 |
(1/2) + (FixedPoint fromString:'1.001') |
1886 | 707 |
1.0 asShortFloat + (FixedPoint fromString:'1.001') |
708 |
1 asLargeInteger + (FixedPoint fromString:'1.001') |
|
709 |
" |
|
710 |
! ! |
|
711 |
||
712 |
!FixedPoint methodsFor:'double dispatching'! |
|
713 |
||
7355 | 714 |
differenceFromFixedPoint:aFixedPoint |
715 |
|n d otherNumerator otherDenominator| |
|
716 |
||
717 |
otherNumerator := aFixedPoint numerator. |
|
718 |
otherDenominator := aFixedPoint denominator. |
|
719 |
||
720 |
"save a multiplication if possible" |
|
721 |
denominator = otherDenominator ifTrue:[ |
|
722 |
n := otherNumerator - numerator. |
|
723 |
d := otherDenominator. |
|
724 |
] ifFalse:[ |
|
725 |
n := (otherNumerator * denominator) - (numerator * otherDenominator). |
|
726 |
d := denominator * otherDenominator. |
|
727 |
]. |
|
728 |
^ self class |
|
729 |
numerator:n |
|
730 |
denominator:d |
|
731 |
scale:(scale max:aFixedPoint scale) |
|
732 |
||
733 |
" |
|
734 |
((1/3) asFixedPoint:2) - ((1/3) asFixedPoint:2) |
|
735 |
((1/3) asFixedPoint:2) - ((2/3) asFixedPoint:2) |
|
736 |
(1/3) - ((2/3) asFixedPoint:2) |
|
737 |
||
738 |
((1/3) asFixedPoint:2) - ((1/3) asFixedPoint:4) |
|
739 |
((1/3) asFixedPoint:2) - ((2/3) asFixedPoint:4) |
|
740 |
" |
|
741 |
! |
|
742 |
||
743 |
differenceFromFraction:aFraction |
|
744 |
|n d otherNumerator otherDenominator| |
|
745 |
||
746 |
otherNumerator := aFraction numerator. |
|
747 |
otherDenominator := aFraction denominator. |
|
748 |
||
749 |
"save a multiplication if possible" |
|
750 |
denominator = otherDenominator ifTrue:[ |
|
751 |
n := otherNumerator - numerator. |
|
752 |
d := otherDenominator. |
|
753 |
] ifFalse:[ |
|
754 |
n := (otherNumerator * denominator) - (numerator * otherDenominator). |
|
755 |
d := denominator * otherDenominator. |
|
756 |
]. |
|
757 |
^ self class |
|
758 |
numerator:n |
|
759 |
denominator:d |
|
760 |
scale:scale |
|
761 |
||
762 |
" |
|
763 |
(1/3) - ((2/3) asFixedPoint:2) |
|
764 |
" |
|
765 |
! |
|
766 |
||
1886 | 767 |
differenceFromInteger:anInteger |
768 |
"sent when an integer does not know how to subtract the receiver. |
|
769 |
Redefined here to preserve the scale." |
|
770 |
||
7355 | 771 |
^ self class |
1886 | 772 |
numerator:((anInteger * denominator) - numerator) |
773 |
denominator:denominator |
|
7355 | 774 |
scale:scale |
775 |
! |
|
776 |
||
777 |
productFromFixedPoint:aFixedPoint |
|
778 |
^ aFixedPoint class |
|
779 |
numerator:(aFixedPoint numerator * numerator) |
|
780 |
denominator:(aFixedPoint denominator * denominator) |
|
781 |
scale:(scale max:aFixedPoint scale) |
|
782 |
||
783 |
" |
|
784 |
((1/3) asFixedPoint:2) * ((1/3) asFixedPoint:4) |
|
785 |
(1/3) * ((1/3) asFixedPoint:4) |
|
786 |
" |
|
787 |
! |
|
788 |
||
789 |
productFromFraction:aFraction |
|
790 |
^ self class |
|
791 |
numerator:(aFraction numerator * numerator) |
|
792 |
denominator:(aFraction denominator * denominator) |
|
793 |
scale:scale |
|
794 |
||
795 |
" |
|
796 |
(1/3) * ((1/3) asFixedPoint:4) |
|
797 |
" |
|
1886 | 798 |
! |
799 |
||
800 |
productFromInteger:anInteger |
|
801 |
"sent when an integer does not know how to multiply the receiver. |
|
802 |
Redefined here to preserve the scale." |
|
803 |
||
7355 | 804 |
^ self class |
1886 | 805 |
numerator:(anInteger * numerator) |
806 |
denominator:denominator |
|
7355 | 807 |
scale:scale |
1886 | 808 |
|
809 |
"Modified: 5.11.1996 / 10:32:28 / cg" |
|
810 |
! |
|
811 |
||
7355 | 812 |
quotientFromFixedPoint:aFixedPoint |
7442 | 813 |
"Return the quotient of the argument, aFixedPoint and the receiver." |
814 |
||
7355 | 815 |
^ aFixedPoint class |
816 |
numerator:(aFixedPoint numerator * denominator) |
|
817 |
denominator:(aFixedPoint denominator * numerator) |
|
818 |
scale:(scale max:aFixedPoint scale) |
|
819 |
||
820 |
" |
|
821 |
((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:2) |
|
822 |
((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:4) |
|
823 |
" |
|
824 |
! |
|
825 |
||
826 |
quotientFromFraction:aFraction |
|
7442 | 827 |
"Return the quotient of the argument, aFraction and the receiver. |
828 |
Sent when aFraction does not know how to divide by the receiver. |
|
829 |
Redefined here to preserve the scale." |
|
830 |
||
7355 | 831 |
^ aFraction class |
832 |
numerator:(aFraction numerator * denominator) |
|
833 |
denominator:(aFraction denominator * numerator) |
|
834 |
scale:scale |
|
835 |
||
836 |
" |
|
837 |
((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:2) |
|
838 |
((1/3) asFixedPoint:2) / ((1/3) asFixedPoint:4) |
|
839 |
" |
|
840 |
! |
|
841 |
||
1886 | 842 |
quotientFromInteger:anInteger |
7442 | 843 |
"Return the quotient of the argument, anInteger and the receiver. |
844 |
Sent when anInteger does not know how to divide by the receiver. |
|
1886 | 845 |
Redefined here to preserve the scale." |
846 |
||
7355 | 847 |
^ self class |
1886 | 848 |
numerator:(anInteger * denominator) |
849 |
denominator:numerator |
|
7355 | 850 |
scale:scale |
1886 | 851 |
|
852 |
"Modified: 5.11.1996 / 10:32:35 / cg" |
|
853 |
! |
|
854 |
||
7355 | 855 |
sumFromFixedPoint:aFixedPoint |
856 |
|n d otherNumerator otherDenominator| |
|
857 |
||
858 |
otherNumerator := aFixedPoint numerator. |
|
859 |
otherDenominator := aFixedPoint denominator. |
|
860 |
||
861 |
"save a multiplication if possible" |
|
862 |
denominator = otherDenominator ifTrue:[ |
|
863 |
n := numerator + otherNumerator. |
|
864 |
d := otherDenominator. |
|
865 |
] ifFalse:[ |
|
866 |
n := (numerator * otherDenominator) + (otherNumerator * denominator). |
|
867 |
d := denominator * otherDenominator. |
|
868 |
]. |
|
869 |
^ self class |
|
870 |
numerator:n |
|
871 |
denominator:d |
|
872 |
scale:(scale max:aFixedPoint scale) |
|
873 |
||
874 |
" |
|
875 |
((1/3) asFixedPoint:2) + ((1/3) asFixedPoint:2) |
|
876 |
((1/3) asFixedPoint:2) + ((2/3) asFixedPoint:2) |
|
877 |
||
878 |
((1/3) asFixedPoint:2) + ((1/3) asFixedPoint:4) |
|
879 |
" |
|
880 |
! |
|
881 |
||
882 |
sumFromFraction:aFraction |
|
883 |
|n d otherNumerator otherDenominator| |
|
884 |
||
885 |
otherNumerator := aFraction numerator. |
|
886 |
otherDenominator := aFraction denominator. |
|
887 |
||
888 |
"save a multiplication if possible" |
|
889 |
denominator = otherDenominator ifTrue:[ |
|
890 |
n := numerator + otherNumerator. |
|
891 |
d := otherDenominator. |
|
892 |
] ifFalse:[ |
|
893 |
n := (numerator * otherDenominator) + (otherNumerator * denominator). |
|
894 |
d := denominator * otherDenominator. |
|
895 |
]. |
|
896 |
^ self class |
|
897 |
numerator:n |
|
898 |
denominator:d |
|
899 |
scale:scale |
|
900 |
||
901 |
" |
|
902 |
(1/3) + ((1/3) asFixedPoint:2) |
|
903 |
" |
|
904 |
! |
|
905 |
||
1886 | 906 |
sumFromInteger:anInteger |
907 |
"sent when an integer does not know how to add the receiver. |
|
908 |
Redefined here to preserve the scale." |
|
909 |
||
7355 | 910 |
^ self class |
1886 | 911 |
numerator:(numerator + (anInteger * denominator)) |
912 |
denominator:denominator |
|
7355 | 913 |
scale:scale |
1886 | 914 |
|
915 |
"Modified: 5.11.1996 / 10:32:43 / cg" |
|
916 |
! ! |
|
917 |
||
5570 | 918 |
!FixedPoint methodsFor:'printing & storing'! |
1886 | 919 |
|
9131 | 920 |
printDecimalOn:aStream roundToScale:roundToScale |
2538 | 921 |
"append to the argument, aStream, a printed representation of the receiver. |
1886 | 922 |
For printout, only scale post-decimal digits are printed |
923 |
(and the printout is rounded to that many digits)" |
|
924 |
||
9133
2d3e3d083be8
storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents:
9132
diff
changeset
|
925 |
|e integerPart fractionPart negative num rest| |
1886 | 926 |
|
927 |
numerator < 0 ifTrue:[ |
|
928 |
negative := true. |
|
929 |
num := numerator negated. |
|
930 |
] ifFalse:[ |
|
931 |
negative := false. |
|
932 |
num := numerator. |
|
933 |
]. |
|
934 |
integerPart := (num // denominator). |
|
935 |
fractionPart := (num \\ denominator). |
|
9131 | 936 |
roundToScale ifTrue:[ |
937 |
e := 10 raisedTo:scale. |
|
938 |
] ifFalse:[ |
|
939 |
e := denominator. |
|
940 |
]. |
|
1886 | 941 |
|
942 |
"/ the most common case is a denominator fitting the scale |
|
943 |
"/ (fixedPoint numbers are created this way) |
|
944 |
||
945 |
e == denominator ifFalse:[ |
|
946 |
fractionPart := fractionPart * (e * 10) // denominator. |
|
947 |
fractionPart := (fractionPart roundTo:10) // 10. |
|
948 |
||
949 |
fractionPart >= e ifTrue:[ |
|
950 |
integerPart := integerPart + 1. |
|
951 |
fractionPart := 0. |
|
952 |
] |
|
953 |
]. |
|
954 |
||
955 |
"/ |
|
956 |
"/ add a 1000..., so we can (mis-)use integer-printString ... |
|
957 |
"/ the highest-1 will be cutoff after padding. |
|
958 |
"/ |
|
959 |
fractionPart := e + fractionPart. |
|
960 |
||
961 |
negative ifTrue:[ |
|
962 |
aStream nextPut:$- |
|
963 |
]. |
|
964 |
integerPart printOn:aStream. |
|
9131 | 965 |
roundToScale ifTrue:[ |
966 |
scale > 0 ifTrue:[ |
|
967 |
aStream nextPut: $.. |
|
968 |
((fractionPart printStringPaddedTo:scale with:$0) copyFrom:2) printOn:aStream |
|
969 |
]. |
|
970 |
] ifFalse:[ |
|
9133
2d3e3d083be8
storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents:
9132
diff
changeset
|
971 |
rest := ((fractionPart printString) copyFrom:2). |
2d3e3d083be8
storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents:
9132
diff
changeset
|
972 |
rest notEmpty ifTrue:[ |
2d3e3d083be8
storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents:
9132
diff
changeset
|
973 |
aStream nextPut: $.. |
2d3e3d083be8
storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents:
9132
diff
changeset
|
974 |
rest printOn:aStream |
2d3e3d083be8
storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents:
9132
diff
changeset
|
975 |
] |
6897 | 976 |
]. |
1886 | 977 |
|
978 |
" |
|
979 |
(FixedPoint fromString:'0.66666666') |
|
980 |
(FixedPoint fromString:'0.66666666') withScale:2 |
|
981 |
(FixedPoint fromString:'0.99999999') |
|
982 |
(FixedPoint fromString:'0.99999999') withScale:2 |
|
983 |
(FixedPoint fromString:'1.00000001') |
|
984 |
(FixedPoint fromString:'1.00000001') withScale:2 |
|
985 |
(FixedPoint fromString:'1.005') |
|
986 |
(FixedPoint fromString:'1.005') withScale:2 |
|
987 |
(FixedPoint fromString:'1.005') withScale:1 |
|
6897 | 988 |
(FixedPoint fromString:'1.5') |
989 |
(FixedPoint fromString:'1.5') withScale:2 |
|
990 |
(FixedPoint fromString:'1.5') withScale:1 |
|
991 |
(FixedPoint fromString:'1.5') withScale:0 |
|
1886 | 992 |
|
993 |
(FixedPoint fromString:'-0.66666666') |
|
994 |
(FixedPoint fromString:'-0.66666666') withScale:2 |
|
995 |
(FixedPoint fromString:'-0.99999999') |
|
996 |
(FixedPoint fromString:'-0.99999999') withScale:2 |
|
997 |
(FixedPoint fromString:'-1.00000001') |
|
998 |
(FixedPoint fromString:'-1.00000001') withScale:2 |
|
999 |
(FixedPoint fromString:'-1.005') |
|
1000 |
(FixedPoint fromString:'-1.005') withScale:2 |
|
1001 |
(FixedPoint fromString:'-1.005') withScale:1 |
|
1002 |
(FixedPoint fromString:'-1.05') |
|
1003 |
(FixedPoint fromString:'-1.05') withScale:2 |
|
1004 |
(FixedPoint fromString:'-1.05') withScale:1 |
|
1005 |
(FixedPoint fromString:'-1.04') |
|
1006 |
(FixedPoint fromString:'-1.04') withScale:2 |
|
1007 |
(FixedPoint fromString:'-1.04') withScale:1 |
|
1008 |
" |
|
1009 |
||
1010 |
" |
|
1011 |
|a b r| |
|
1012 |
||
1013 |
a := (FixedPoint fromString:'0.66666666') withScale:2. |
|
1014 |
b := (FixedPoint fromString:'0.33333333'). |
|
1015 |
r := (a + b) withScale:4. |
|
1016 |
Transcript show:'printout with scale of 4 :'; showCR:r. |
|
1017 |
Transcript show:'more precise value :'; showCR:(r withScale:8) |
|
1018 |
" |
|
2538 | 1019 |
|
1020 |
"Modified: 12.4.1997 / 11:20:51 / cg" |
|
9131 | 1021 |
! |
1022 |
||
1023 |
printOn: aStream |
|
1024 |
"append to the argument, aStream, a printed representation of the receiver. |
|
1025 |
For printout, only scale post-decimal digits are printed |
|
1026 |
(and the printout is rounded to that many digits)" |
|
1027 |
||
1028 |
self printDecimalOn:aStream roundToScale:true |
|
1029 |
||
1030 |
" |
|
1031 |
(FixedPoint fromString:'0.66666666') |
|
1032 |
(FixedPoint fromString:'0.66666666') withScale:2 |
|
1033 |
(FixedPoint fromString:'0.99999999') |
|
1034 |
(FixedPoint fromString:'0.99999999') withScale:2 |
|
1035 |
(FixedPoint fromString:'1.00000001') |
|
1036 |
(FixedPoint fromString:'1.00000001') withScale:2 |
|
1037 |
(FixedPoint fromString:'1.005') |
|
1038 |
(FixedPoint fromString:'1.005') withScale:2 |
|
1039 |
(FixedPoint fromString:'1.005') withScale:1 |
|
1040 |
(FixedPoint fromString:'1.5') |
|
1041 |
(FixedPoint fromString:'1.5') withScale:2 |
|
1042 |
(FixedPoint fromString:'1.5') withScale:1 |
|
1043 |
(FixedPoint fromString:'1.5') withScale:0 |
|
1044 |
||
1045 |
(FixedPoint fromString:'-0.66666666') |
|
1046 |
(FixedPoint fromString:'-0.66666666') withScale:2 |
|
1047 |
(FixedPoint fromString:'-0.99999999') |
|
1048 |
(FixedPoint fromString:'-0.99999999') withScale:2 |
|
1049 |
(FixedPoint fromString:'-1.00000001') |
|
1050 |
(FixedPoint fromString:'-1.00000001') withScale:2 |
|
1051 |
(FixedPoint fromString:'-1.005') |
|
1052 |
(FixedPoint fromString:'-1.005') withScale:2 |
|
1053 |
(FixedPoint fromString:'-1.005') withScale:1 |
|
1054 |
(FixedPoint fromString:'-1.05') |
|
1055 |
(FixedPoint fromString:'-1.05') withScale:2 |
|
1056 |
(FixedPoint fromString:'-1.05') withScale:1 |
|
1057 |
(FixedPoint fromString:'-1.04') |
|
1058 |
(FixedPoint fromString:'-1.04') withScale:2 |
|
1059 |
(FixedPoint fromString:'-1.04') withScale:1 |
|
1060 |
" |
|
1061 |
||
1062 |
" |
|
1063 |
|a b r| |
|
1064 |
||
1065 |
a := (FixedPoint fromString:'0.66666666') withScale:2. |
|
1066 |
b := (FixedPoint fromString:'0.33333333'). |
|
1067 |
r := (a + b) withScale:4. |
|
1068 |
Transcript show:'printout with scale of 4 :'; showCR:r. |
|
1069 |
Transcript show:'more precise value :'; showCR:(r withScale:8) |
|
1070 |
" |
|
1071 |
||
1072 |
"Modified: 12.4.1997 / 11:20:51 / cg" |
|
1073 |
! |
|
1074 |
||
1075 |
storeOn:aStream |
|
9132 | 1076 |
"notice: we MUST preserve the full internal precision when storing/reloading" |
1077 |
||
9131 | 1078 |
self printDecimalOn:aStream roundToScale:false. |
1079 |
aStream nextPut:$s. |
|
1080 |
scale storeOn:aStream. |
|
1081 |
||
1082 |
" |
|
1083 |
((FixedPoint fromString:'0.66666666') ) storeString |
|
1084 |
((FixedPoint fromString:'0.66666666') withScale:2 ) storeString |
|
1085 |
((FixedPoint fromString:'1.5') ) storeString |
|
1086 |
((FixedPoint fromString:'1.5') withScale:2 ) storeString |
|
1087 |
((FixedPoint fromString:'1.5') withScale:1 ) storeString |
|
1088 |
((FixedPoint fromString:'1.5') withScale:0 ) storeString |
|
1089 |
" |
|
1090 |
! |
|
1091 |
||
1092 |
storeString |
|
1093 |
^ String streamContents:[:s | self storeOn:s] |
|
1094 |
||
1095 |
" |
|
1096 |
((FixedPoint fromString:'0.66666666') ) storeString |
|
1097 |
((FixedPoint fromString:'0.66666666') withScale:2 ) storeString |
|
1098 |
((FixedPoint fromString:'1.5') ) storeString |
|
1099 |
((FixedPoint fromString:'1.5') withScale:2 ) storeString |
|
1100 |
((FixedPoint fromString:'1.5') withScale:1 ) storeString |
|
1101 |
((FixedPoint fromString:'1.5') withScale:0 ) storeString |
|
1102 |
" |
|
1886 | 1103 |
! ! |
1104 |
||
1105 |
!FixedPoint methodsFor:'private'! |
|
1106 |
||
1107 |
reduced |
|
1108 |
|gc| |
|
1109 |
||
1110 |
scale isNil ifTrue:[ |
|
1111 |
"/ to catch inherited Fraction reduce calls |
|
1112 |
self error:'should not happen'. |
|
1113 |
scale := 3 |
|
1114 |
]. |
|
1115 |
||
6573
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1116 |
(denominator < 0) ifTrue:[ |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1117 |
numerator := numerator negated. |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1118 |
denominator := denominator negated |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1119 |
]. |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1120 |
|
1886 | 1121 |
denominator == 1 ifTrue:[^ numerator]. |
1122 |
numerator == 1 ifTrue:[^ self]. |
|
1123 |
numerator == 0 ifTrue:[^ 0]. |
|
1124 |
||
1125 |
gc := numerator gcd:denominator. |
|
6573
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1126 |
gc < 0 ifTrue:[ |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1127 |
gc := gc negated |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1128 |
]. |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1129 |
gc := gc gcd:(10 raisedToInteger:scale). |
1886 | 1130 |
|
6573
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1131 |
(gc ~~ 1) ifTrue:[ |
1886 | 1132 |
numerator := numerator // gc. |
6573
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1133 |
denominator := denominator // gc. |
4ea758ea3d4b
reduce when creating new FixedPoints
Stefan Vogel <sv@exept.de>
parents:
6570
diff
changeset
|
1134 |
denominator == 1 ifTrue:[^ numerator]. |
1886 | 1135 |
]. |
1136 |
||
1137 |
^ self |
|
1138 |
! |
|
1139 |
||
3731
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1140 |
scale:newScale |
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1141 |
"set the scale." |
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1142 |
|
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1143 |
scale := newScale. |
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1144 |
|
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1145 |
"Modified: / 12.4.1997 / 11:22:02 / cg" |
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1146 |
"Created: / 5.8.1998 / 13:28:49 / cg" |
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1147 |
! |
8c2ef8f76670
added #scale: for protocol completeness.
Claus Gittinger <cg@exept.de>
parents:
3060
diff
changeset
|
1148 |
|
1886 | 1149 |
setNumerator:nInteger denominator:d scale:s |
2538 | 1150 |
"initialize the instance variables. |
1151 |
Assumes that the fraction as specified by numerator and denominator |
|
1152 |
is already reduced." |
|
1886 | 1153 |
|
1154 |
scale := s. |
|
1155 |
super |
|
1156 |
setNumerator:nInteger |
|
1157 |
denominator:d |
|
2538 | 1158 |
|
1159 |
"Modified: 12.4.1997 / 11:21:47 / cg" |
|
1886 | 1160 |
! |
1161 |
||
1162 |
setNumerator:nInteger scale:s |
|
2538 | 1163 |
"initialize the instance variables. |
1164 |
Assumes that the fraction as specified by numerator and denominator |
|
1165 |
is already reduced." |
|
1886 | 1166 |
|
1167 |
scale := s. |
|
1168 |
super |
|
1169 |
setNumerator:nInteger |
|
1170 |
denominator:(10 raisedTo:s) |
|
2538 | 1171 |
|
1172 |
"Modified: 12.4.1997 / 11:21:55 / cg" |
|
1886 | 1173 |
! |
1174 |
||
1175 |
setScale:newScale |
|
2538 | 1176 |
"initialize the scale instance variables." |
1886 | 1177 |
|
1178 |
scale := newScale. |
|
2538 | 1179 |
|
1180 |
"Modified: 12.4.1997 / 11:22:02 / cg" |
|
1886 | 1181 |
! ! |
1182 |
||
6650 | 1183 |
!FixedPoint methodsFor:'testing'! |
1891 | 1184 |
|
1185 |
isFixedPoint |
|
1186 |
"return true, if the receiver is some kind of fixedPoint number; |
|
1187 |
true is returned here - the method is redefined from Object." |
|
1188 |
||
1189 |
^ true |
|
1190 |
||
1191 |
||
1192 |
! ! |
|
1193 |
||
7376
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1194 |
!FixedPoint methodsFor:'truncation & rounding'! |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1195 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1196 |
roundedToScale |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1197 |
"return the receiver rounded to my scale |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1198 |
(i.e. return a number which has the value which is shown when printing)" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1199 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1200 |
|n scale10| |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1201 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1202 |
scale10 := 10 raisedToInteger:scale. |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1203 |
n := ((numerator * scale10) + (denominator bitShift:-1)) // denominator. |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1204 |
^ self class |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1205 |
numerator:n |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1206 |
denominator:scale10 |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1207 |
scale:scale. |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1208 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1209 |
" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1210 |
((2/3) asFixedPoint:2) |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1211 |
((2/3) asFixedPoint:2) rounded |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1212 |
((2/3) asFixedPoint:2) roundedToScale |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1213 |
" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1214 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1215 |
"Modified: 5.11.1996 / 12:18:46 / cg" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1216 |
! |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1217 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1218 |
truncatedToScale |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1219 |
"return the receiver truncated towards zero to my scale" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1220 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1221 |
|n scale10| |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1222 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1223 |
scale10 := 10 raisedToInteger:scale. |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1224 |
n := (numerator * scale10) quo:denominator. |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1225 |
^ self class |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1226 |
numerator:n |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1227 |
denominator:scale10 |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1228 |
scale:scale. |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1229 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1230 |
" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1231 |
((2/3) asFixedPoint:2) |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1232 |
((2/3) asFixedPoint:2) truncated |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1233 |
((2/3) asFixedPoint:2) truncatedToScale |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1234 |
" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1235 |
|
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1236 |
"Modified: 5.11.1996 / 12:18:46 / cg" |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1237 |
! ! |
a166651de99e
truncatedToScale/roundedToScale
Claus Gittinger <cg@exept.de>
parents:
7355
diff
changeset
|
1238 |
|
1886 | 1239 |
!FixedPoint class methodsFor:'documentation'! |
1240 |
||
1241 |
version |
|
9133
2d3e3d083be8
storeOn fixed for negative numbers with 0 scale
Claus Gittinger <cg@exept.de>
parents:
9132
diff
changeset
|
1242 |
^ '$Header: /cvs/stx/stx/libbasic/FixedPoint.st,v 1.34 2006-02-17 13:15:58 cg Exp $' |
1886 | 1243 |
! ! |