author | Claus Gittinger <cg@exept.de> |
Tue, 31 Jul 2001 17:10:05 +0200 | |
changeset 5897 | 793b0adad934 |
parent 5883 | 658ff91cef9e |
child 5954 | d706efecb134 |
permissions | -rw-r--r-- |
55 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
213 | 3 |
All Rights Reserved |
55 | 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 |
||
5470
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
14 |
|
55 | 15 |
Number subclass:#LimitedPrecisionReal |
1200 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Magnitude-Numbers' |
|
55 | 20 |
! |
21 |
||
88 | 22 |
!LimitedPrecisionReal class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
213 | 27 |
All Rights Reserved |
55 | 28 |
|
88 | 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 |
! |
|
55 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
40 |
Abstract superclass for single and double (and maybe more) |
|
41 |
precision real numbers (i.e. Float and Double). |
|
92 | 42 |
|
43 |
Due to historic reasons, ST/X's Floats are what Doubles are in ST-80. |
|
44 |
This may change soon (implementing LPReal is a first step towards this). |
|
1295 | 45 |
|
46 |
[author:] |
|
47 |
Claus Gittinger |
|
1893 | 48 |
|
49 |
[see also:] |
|
50 |
Fraction FixedPoint |
|
88 | 51 |
" |
52 |
! ! |
|
55 | 53 |
|
54 |
!LimitedPrecisionReal class methodsFor:'instance creation'! |
|
55 |
||
56 |
new:aNumber |
|
57 |
"catch this message - not allowed for floats/doubles" |
|
58 |
||
59 |
self error:'Floats/Doubles cannot be created with new:' |
|
60 |
! ! |
|
61 |
||
62 |
!LimitedPrecisionReal methodsFor:'accessing'! |
|
63 |
||
64 |
at:index |
|
65 |
"redefined to prevent access to individual bytes in a real." |
|
66 |
||
67 |
self error:'not allowed for floats/doubles' |
|
68 |
! |
|
69 |
||
70 |
at:index put:aValue |
|
71 |
"redefined to prevent access to individual bytes in a real" |
|
72 |
||
73 |
self error:'not allowed for floats/doubles' |
|
74 |
! ! |
|
75 |
||
76 |
!LimitedPrecisionReal methodsFor:'arithmetic'! |
|
77 |
||
701 | 78 |
* aNumber |
79 |
"return the product of the receiver and the argument, aNumber" |
|
80 |
||
1200 | 81 |
"/ as soon as Float are float & Double are doubles, |
82 |
"/ use: |
|
83 |
"/ ^ aNumber productFromDouble:self asDouble |
|
84 |
||
85 |
^ aNumber productFromFloat:self asFloat |
|
86 |
||
87 |
"Modified: 17.4.1996 / 12:35:36 / cg" |
|
701 | 88 |
! |
89 |
||
55 | 90 |
+ aNumber |
91 |
"return the sum of the receiver and the argument, aNumber" |
|
92 |
||
1200 | 93 |
"/ as soon as Float are float & Double are doubles, |
94 |
"/ use: |
|
95 |
"/ ^ aNumber sumFromDouble:self asDouble |
|
96 |
||
97 |
^ aNumber sumFromFloat:self asFloat |
|
98 |
||
99 |
"Modified: 17.4.1996 / 12:35:55 / cg" |
|
55 | 100 |
! |
101 |
||
102 |
- aNumber |
|
103 |
"return the difference of the receiver and the argument, aNumber" |
|
104 |
||
1200 | 105 |
"/ as soon as Float are float & Double are doubles, |
106 |
"/ use: |
|
107 |
"/ ^ aNumber differenceFromDouble:self asDouble |
|
108 |
||
109 |
^ aNumber differenceFromFloat:self asFloat |
|
110 |
||
111 |
"Modified: 17.4.1996 / 12:36:07 / cg" |
|
55 | 112 |
! |
113 |
||
114 |
/ aNumber |
|
115 |
"return the quotient of the receiver and the argument, aNumber" |
|
116 |
||
117 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
3898
diff
changeset
|
118 |
^ DivisionByZeroSignal raiseRequest. |
55 | 119 |
]. |
1200 | 120 |
"/ as soon as Float are float & Double are doubles, |
121 |
"/ use: |
|
122 |
"/ ^ aNumber quotientFromDouble:self asDouble |
|
123 |
||
124 |
^ aNumber quotientFromFloat:self asFloat |
|
125 |
||
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
3898
diff
changeset
|
126 |
"Modified: / 17.4.1996 / 12:36:21 / cg" |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
3898
diff
changeset
|
127 |
"Modified: / 26.7.1999 / 10:46:11 / stefan" |
55 | 128 |
! |
129 |
||
130 |
// aNumber |
|
131 |
"return the integer quotient of dividing the receiver by aNumber with |
|
1882 | 132 |
truncation towards negative infinity." |
55 | 133 |
|
134 |
^ (self / aNumber) floor asInteger |
|
1882 | 135 |
|
136 |
"Modified: 5.11.1996 / 11:45:37 / cg" |
|
55 | 137 |
! ! |
138 |
||
5238 | 139 |
!LimitedPrecisionReal methodsFor:'coercing & converting'! |
55 | 140 |
|
2141 | 141 |
asFixedPoint |
142 |
"return the receiver as fixedPoint number. |
|
143 |
Q: what should the scale be here ?" |
|
144 |
||
145 |
^ self asFraction asFixedPoint |
|
146 |
||
147 |
" |
|
148 |
0.3 asFixedPoint |
|
149 |
0.5 asFixedPoint |
|
150 |
(1/5) asFloat asFixedPoint |
|
151 |
(1/3) asFloat asFixedPoint |
|
152 |
(2/3) asFloat asFixedPoint |
|
153 |
(1/8) asFloat asFixedPoint |
|
154 |
3.14159 asFixedPoint |
|
3060 | 155 |
0.0000001 asFraction |
156 |
0.0000001 asFixedPoint |
|
2141 | 157 |
" |
158 |
||
3060 | 159 |
"Modified: / 25.10.1997 / 15:36:54 / cg" |
2141 | 160 |
! |
161 |
||
162 |
asFixedPoint:scale |
|
163 |
"return the receiver as fixedPoint number with the given |
|
164 |
number of post-decimal-digits." |
|
165 |
||
166 |
^ self asFraction asFixedPoint:scale |
|
167 |
||
168 |
" |
|
3732 | 169 |
0.3 asFixedPoint:4 |
2141 | 170 |
0.3 asFixedPoint:3 |
3732 | 171 |
0.3 asFixedPoint:2 |
172 |
0.3 asFixedPoint:1 |
|
173 |
0.3 asFixedPoint:0 |
|
174 |
||
2141 | 175 |
0.5 asFixedPoint:3 |
176 |
(1/5) asFloat asFixedPoint:1 |
|
177 |
(1/8) asFloat asFixedPoint:1 |
|
178 |
3.14159 asFixedPoint:2 |
|
179 |
3.14159 asFixedPoint:3 |
|
180 |
(3.14159 asFixedPoint:2) asFixedPoint:5 |
|
181 |
" |
|
182 |
||
3732 | 183 |
"Modified: / 5.8.1998 / 13:29:51 / cg" |
2141 | 184 |
! |
185 |
||
55 | 186 |
asFraction |
5883 | 187 |
"Answer a rational number (Integer or Fraction) representing the receiver. |
188 |
This conversion uses the continued fraction method to approximate |
|
189 |
a floating point number." |
|
190 |
||
191 |
|num1 denom1 num2 denom2 int frac newD temp limit| |
|
55 | 192 |
|
5883 | 193 |
limit := (self class unity * 10) raisedTo:self defaultNumberOfDigits. |
194 |
num1 := self truncated. |
|
195 |
denom1 := 1. "The first of two alternating denominators" |
|
196 |
num2 := 1. "The second numerator" |
|
197 |
denom2 := 0. "The second denominator--will update" |
|
198 |
int := num1. "The integer part of self" |
|
199 |
frac := self fractionPart. |
|
200 |
[frac = 0] whileFalse:[ |
|
201 |
newD := 1.0 / frac. |
|
202 |
int := newD truncated. |
|
203 |
frac := newD fractionPart. "save the fractional part for next time" |
|
204 |
temp := num2. "old numerator and save it" |
|
205 |
num2 := num1. |
|
206 |
num1 := num1 * int + temp. "Update first numerator" |
|
207 |
temp := denom2. "old denominator and save it" |
|
208 |
denom2 := denom1. |
|
209 |
denom1 := int * denom1 + temp. "Update first denominator" |
|
210 |
limit < denom1 ifTrue:[ |
|
211 |
"Is ratio past float precision? If so, pick which of the two ratios to use" |
|
212 |
num2 = 0.0 ifTrue:[ |
|
213 |
"Is second denominator 0?" |
|
214 |
^ Fraction numerator:num1 denominator:denom1 |
|
215 |
]. |
|
216 |
^ Fraction numerator:num2 denominator:denom2 |
|
217 |
] |
|
3060 | 218 |
]. |
219 |
||
5883 | 220 |
"If fractional part is zero, return the first ratio" |
221 |
denom1 = 1 ifTrue:[ |
|
222 |
"Am i really an Integer?" |
|
223 |
^ num1 "Yes, return Integer result" |
|
3060 | 224 |
]. |
5883 | 225 |
"Otherwise return Fraction result" |
226 |
^ Fraction numerator:num1 denominator:denom1 |
|
55 | 227 |
|
3060 | 228 |
" |
5883 | 229 |
1.1 asFraction |
230 |
1.2 asFraction |
|
231 |
0.3 asFraction |
|
3060 | 232 |
0.5 asFraction |
233 |
(1/5) asFloat asFraction |
|
5883 | 234 |
(1/8) asFloat asFraction |
235 |
(1/13) asFloat asFraction |
|
236 |
3.14159 asFraction |
|
237 |
3.14159 asFraction asFloat |
|
238 |
1.3 asFraction |
|
239 |
1.0 asFraction |
|
3060 | 240 |
" |
2793 | 241 |
|
3060 | 242 |
"Modified: / 25.10.1997 / 16:41:19 / cg" |
55 | 243 |
! |
244 |
||
245 |
asInteger |
|
246 |
"return an integer with same value - might truncate" |
|
247 |
||
3185 | 248 |
|max maxF| |
55 | 249 |
|
2388 | 250 |
self isNaN ifTrue:[ |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
251 |
^ self class |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
252 |
raise:#domainErrorSignal |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
253 |
receiver:self |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
254 |
selector:#asInteger |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
255 |
errorString:'receiver is NaN in #asInteger' |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
256 |
|
2388 | 257 |
]. |
258 |
||
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
259 |
self abs < 2e16 ifTrue:[ |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
260 |
"/ NOTICE: this must be redefined in float |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
261 |
"/ subclasses to handle the smallinteger range; |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
262 |
"/ i.e. this may only be invoked for reals |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
263 |
"/ which are NOT within the smallInt range. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
264 |
"/ otherwise, endless recursion is the consequence. |
3426 | 265 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
266 |
max := SmallInteger maxVal // 2 + 1. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
267 |
maxF := max asFloat. |
3426 | 268 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
269 |
^ (self quo:maxF) * max + (self rem:maxF) truncated |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
270 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
271 |
^ self asTrueFraction |
55 | 272 |
|
3137 | 273 |
" |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
274 |
12345.0 asInteger |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
275 |
1e15 asInteger |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
276 |
1e33 asInteger asFloat |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
277 |
1e303 asInteger asFloat |
3137 | 278 |
" |
2388 | 279 |
|
280 |
"Modified: 12.2.1997 / 16:45:07 / cg" |
|
701 | 281 |
! |
282 |
||
5883 | 283 |
asRational |
284 |
"Answer a Rational number--Integer or Fraction--representing the receiver. |
|
285 |
Same as asFraction fro st-80 compatibility." |
|
286 |
||
287 |
^ self asFraction |
|
288 |
||
289 |
" |
|
290 |
1.1 asRational |
|
291 |
1.2 asRational |
|
292 |
0.3 asRational |
|
293 |
0.5 asRational |
|
294 |
(1/5) asFloat asRational |
|
295 |
(1/8) asFloat asRational |
|
296 |
(1/13) asFloat asRational |
|
297 |
3.14159 asRational |
|
298 |
3.14159 asRational asFloat |
|
299 |
1.3 asRational |
|
300 |
1.0 asRational |
|
301 |
" |
|
302 |
! |
|
303 |
||
701 | 304 |
coerce:aNumber |
305 |
"return aNumber converted into receivers type" |
|
306 |
||
1200 | 307 |
"/ as soon as Float are float & Double are doubles, |
308 |
"/ use: |
|
309 |
"/ ^ aNumber asDouble |
|
310 |
||
311 |
^ aNumber asFloat |
|
312 |
||
313 |
"Modified: 17.4.1996 / 12:36:46 / cg" |
|
701 | 314 |
! |
315 |
||
3898 | 316 |
fractionalPart |
317 |
"This has been renamed to #fractionPart for ST80 compatibility. |
|
318 |
||
319 |
extract the after-decimal fraction part. |
|
320 |
the floats value is |
|
321 |
float truncated + float fractionalPart" |
|
322 |
||
5868 | 323 |
<resource:#obsolete> |
324 |
||
3898 | 325 |
self obsoleteMethodWarning:'please use #fractionPart'. |
326 |
^ self fractionPart |
|
327 |
||
328 |
"Modified: / 28.10.1998 / 17:10:12 / cg" |
|
329 |
"Created: / 28.10.1998 / 17:10:32 / cg" |
|
330 |
! |
|
331 |
||
701 | 332 |
generality |
333 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
334 |
||
335 |
^ 80 |
|
336 |
! ! |
|
337 |
||
338 |
!LimitedPrecisionReal methodsFor:'comparing'! |
|
339 |
||
340 |
< aNumber |
|
341 |
"return true, if the argument is greater" |
|
342 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
343 |
"/ as soon as Float are float & Double are doubles, |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
344 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
345 |
"/ ^ aNumber lessFromDouble:self asDouble |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
346 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
347 |
^ aNumber lessFromFloat:self asFloat |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
348 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
349 |
"Modified: 17.4.1996 / 13:34:50 / cg" |
701 | 350 |
! |
351 |
||
352 |
<= aNumber |
|
353 |
"return true, if the argument is greater or equal" |
|
354 |
||
355 |
^ self retry:#<= coercing:aNumber |
|
356 |
! |
|
357 |
||
358 |
= aNumber |
|
359 |
"return true, if the arguments value are equal" |
|
360 |
||
361 |
^ self retry:#= coercing:aNumber |
|
362 |
! |
|
363 |
||
364 |
> aNumber |
|
365 |
"return true, if the argument is less" |
|
366 |
||
367 |
^ self retry:#> coercing:aNumber |
|
368 |
! |
|
369 |
||
370 |
>= aNumber |
|
371 |
"return true, if the argument is less or equal" |
|
372 |
||
373 |
^ self retry:#>= coercing:aNumber |
|
374 |
! |
|
375 |
||
376 |
~= aNumber |
|
377 |
"return true, if the arguments value are not equal" |
|
378 |
||
379 |
^ self retry:#~= coercing:aNumber |
|
380 |
! ! |
|
381 |
||
382 |
!LimitedPrecisionReal methodsFor:'copying'! |
|
383 |
||
384 |
deepCopy |
|
385 |
"return a deep copy of myself |
|
386 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
387 |
||
388 |
^ self |
|
389 |
! |
|
390 |
||
391 |
deepCopyUsing:aDictionary |
|
392 |
"return a deep copy of myself |
|
393 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
394 |
||
395 |
^ self |
|
396 |
! |
|
397 |
||
398 |
shallowCopy |
|
399 |
"return a shallow copy of the receiver" |
|
400 |
||
401 |
^ self |
|
402 |
! |
|
403 |
||
404 |
simpleDeepCopy |
|
405 |
"return a deep copy of the receiver |
|
406 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
407 |
||
408 |
^ self |
|
55 | 409 |
! ! |
410 |
||
411 |
!LimitedPrecisionReal methodsFor:'double dispatching'! |
|
412 |
||
413 |
differenceFromFraction:aFraction |
|
213 | 414 |
"sent when a fraction does not know how to subtract the receiver, a float" |
55 | 415 |
|
416 |
|d| |
|
417 |
||
418 |
d := aFraction denominator. |
|
419 |
^ (aFraction numerator - (self * d)) / d |
|
420 |
! |
|
421 |
||
422 |
productFromFraction:aFraction |
|
213 | 423 |
"sent when a fraction does not know how to multiply the receiver, a float" |
55 | 424 |
|
425 |
^ self * aFraction numerator / aFraction denominator |
|
426 |
! |
|
427 |
||
428 |
quotientFromFraction:aFraction |
|
213 | 429 |
"sent when a fraction does not know how to divide by the receiver, a float" |
55 | 430 |
|
431 |
^ aFraction numerator / (self * aFraction denominator) |
|
701 | 432 |
! |
433 |
||
434 |
sumFromFraction:aFraction |
|
435 |
"sent when a fraction does not know how to add the receiver, a float" |
|
436 |
||
437 |
|d| |
|
438 |
||
439 |
d := aFraction denominator. |
|
440 |
^ (self * d + aFraction numerator) / d |
|
441 |
! ! |
|
442 |
||
5470
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
443 |
!LimitedPrecisionReal methodsFor:'encoding'! |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
444 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
445 |
encodeOn:anEncoder with:aParameter |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
446 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
447 |
anEncoder encodeFloat:self with:aParameter |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
448 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
449 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
450 |
! ! |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
451 |
|
701 | 452 |
!LimitedPrecisionReal methodsFor:'printing & storing'! |
453 |
||
454 |
printOn:aStream |
|
455 |
"append a printed representation of the receiver to |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
456 |
the argument, aStream. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
457 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
458 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
459 |
#printOn: as basic print mechanism." |
701 | 460 |
|
461 |
aStream nextPutAll:self printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
462 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
463 |
"Modified: / 20.1.1998 / 14:10:46 / stefan" |
1200 | 464 |
! |
465 |
||
466 |
printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
467 |
"return a printed representation of the receiver |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
468 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
469 |
#printOn: as basic print mechanism." |
1200 | 470 |
|
471 |
^ self subclassResponsibility |
|
472 |
||
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
473 |
"Created: / 17.4.1996 / 12:12:20 / cg" |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
474 |
"Modified: / 20.1.1998 / 14:10:47 / stefan" |
701 | 475 |
! ! |
476 |
||
5557 | 477 |
!LimitedPrecisionReal methodsFor:'queries'! |
478 |
||
5883 | 479 |
defaultNumberOfDigits |
480 |
self subclassResponsibility |
|
481 |
! |
|
482 |
||
5557 | 483 |
size |
484 |
"redefined since reals are kludgy (ByteArry)" |
|
485 |
||
486 |
^ 0 |
|
487 |
! ! |
|
5470
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
488 |
|
701 | 489 |
!LimitedPrecisionReal methodsFor:'testing'! |
490 |
||
3148
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
491 |
isFinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
492 |
^ self subclassResponsibility |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
493 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
494 |
"Created: / 7.1.1998 / 12:02:06 / stefan" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
495 |
! |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
496 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
497 |
isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
498 |
"return true, if the receiver is an infinite float (Inf). |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
499 |
These are not created by ST/X float operations (they raise an exception); |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
500 |
however, inline C-code could produce them ..." |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
501 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
502 |
^ (self isFinite or:[self isNaN]) not. |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
503 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
504 |
" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
505 |
1.0 isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
506 |
(0.0 uncheckedDivide: 0.0) isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
507 |
(1.0 uncheckedDivide: 0.0) isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
508 |
" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
509 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
510 |
"Modified: / 7.1.1998 / 12:01:30 / stefan" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
511 |
! |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
512 |
|
2388 | 513 |
isNaN |
514 |
^ self subclassResponsibility |
|
515 |
||
516 |
"Modified: 12.2.1997 / 16:45:27 / cg" |
|
517 |
! |
|
518 |
||
701 | 519 |
isReal |
520 |
"return true, if the receiver is some kind of real number; |
|
521 |
false is returned here - the method is redefined from Object." |
|
522 |
||
523 |
^ true |
|
524 |
! |
|
525 |
||
526 |
negative |
|
527 |
"return true if the receiver is less than zero" |
|
528 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
529 |
"/ as soon as Float are float & Double are doubles, |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
530 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
531 |
"/ ^ self asDouble negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
532 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
533 |
^ self asFloat negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
534 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
535 |
"Modified: 17.4.1996 / 13:35:00 / cg" |
701 | 536 |
! |
537 |
||
5357 | 538 |
numberOfBits |
539 |
"return the size (in bits) of the real; |
|
540 |
typically, this is 64 for Floats and 32 for ShortFloats, |
|
541 |
but who knows ..." |
|
542 |
||
543 |
self subclassResponsibility |
|
544 |
! |
|
545 |
||
701 | 546 |
positive |
547 |
"return true if the receiver is greater or equal to zero" |
|
548 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
549 |
"/ as soon as Float are float & Double are doubles, |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
550 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
551 |
"/ ^ self asDouble positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
552 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
553 |
^ self asFloat positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
554 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
555 |
"Modified: 17.4.1996 / 13:35:10 / cg" |
55 | 556 |
! ! |
557 |
||
701 | 558 |
!LimitedPrecisionReal class methodsFor:'documentation'! |
55 | 559 |
|
701 | 560 |
version |
5883 | 561 |
^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.38 2001-06-26 14:03:35 cg Exp $' |
55 | 562 |
! ! |