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