author | Claus Gittinger <cg@exept.de> |
Wed, 13 May 1998 23:38:30 +0200 | |
changeset 3443 | d57ea75d3ac5 |
parent 3426 | a648de89ac72 |
child 3732 | bf041aa09cc4 |
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:[ |
|
1200 | 122 |
^ DivisionByZeroSignal raise. |
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 |
||
130 |
"Modified: 17.4.1996 / 12:36:21 / cg" |
|
55 | 131 |
! |
132 |
||
133 |
// aNumber |
|
134 |
"return the integer quotient of dividing the receiver by aNumber with |
|
1882 | 135 |
truncation towards negative infinity." |
55 | 136 |
|
137 |
^ (self / aNumber) floor asInteger |
|
1882 | 138 |
|
139 |
"Modified: 5.11.1996 / 11:45:37 / cg" |
|
55 | 140 |
! ! |
141 |
||
142 |
!LimitedPrecisionReal methodsFor:'coercion and converting'! |
|
143 |
||
2141 | 144 |
asFixedPoint |
145 |
"return the receiver as fixedPoint number. |
|
146 |
Q: what should the scale be here ?" |
|
147 |
||
148 |
^ self asFraction asFixedPoint |
|
149 |
||
150 |
" |
|
151 |
0.3 asFixedPoint |
|
152 |
0.5 asFixedPoint |
|
153 |
(1/5) asFloat asFixedPoint |
|
154 |
(1/3) asFloat asFixedPoint |
|
155 |
(2/3) asFloat asFixedPoint |
|
156 |
(1/8) asFloat asFixedPoint |
|
157 |
3.14159 asFixedPoint |
|
3060 | 158 |
0.0000001 asFraction |
159 |
0.0000001 asFixedPoint |
|
2141 | 160 |
" |
161 |
||
3060 | 162 |
"Modified: / 25.10.1997 / 15:36:54 / cg" |
2141 | 163 |
! |
164 |
||
165 |
asFixedPoint:scale |
|
166 |
"return the receiver as fixedPoint number with the given |
|
167 |
number of post-decimal-digits." |
|
168 |
||
169 |
^ self asFraction asFixedPoint:scale |
|
170 |
||
171 |
" |
|
172 |
0.3 asFixedPoint:3 |
|
173 |
0.5 asFixedPoint:3 |
|
174 |
(1/5) asFloat asFixedPoint:1 |
|
175 |
(1/8) asFloat asFixedPoint:1 |
|
176 |
3.14159 asFixedPoint:2 |
|
177 |
3.14159 asFixedPoint:3 |
|
178 |
(3.14159 asFixedPoint:2) asFixedPoint:5 |
|
179 |
" |
|
180 |
||
181 |
"Modified: 10.1.1997 / 19:59:42 / cg" |
|
182 |
! |
|
183 |
||
55 | 184 |
asFraction |
3060 | 185 |
"return a corresponding fraction or integer |
186 |
(fractions with 1 as denominator are not allowed/useful) |
|
55 | 187 |
- notice, that 'aFract asFloat asFraction' does not always return |
188 |
a good fraction ... due to rounding errors when converting to float" |
|
189 |
||
3060 | 190 |
|fract digits power num denom eI| |
55 | 191 |
|
192 |
"we (indirectly) use printf which knows the precision of floats" |
|
193 |
||
194 |
fract := self fractionPart. |
|
3060 | 195 |
fract = 0.0 ifTrue:[ |
196 |
^ self asInteger. |
|
197 |
]. |
|
198 |
||
199 |
"/ use printf, so we dont need to know anything |
|
200 |
"/ about float representation here. |
|
201 |
||
202 |
digits := (fract printfPrintString:'%.16f'). |
|
203 |
eI := digits size. |
|
204 |
[(digits at:eI) == $0] whileTrue:[ |
|
205 |
eI := eI - 1 |
|
206 |
]. |
|
207 |
||
208 |
power := eI - 3 + 1. |
|
55 | 209 |
num := (self - fract) asInteger. |
210 |
denom := (10 raisedToInteger:power). |
|
211 |
num := num * denom. |
|
3060 | 212 |
num := num + (fract * denom) asInteger. |
213 |
||
2793 | 214 |
^ Fraction numerator:num denominator:denom |
55 | 215 |
|
3060 | 216 |
" |
217 |
0.3 asFraction |
|
218 |
0.5 asFraction |
|
219 |
(1/5) asFloat asFraction |
|
220 |
(1/8) asFloat asFraction |
|
221 |
(1/13) asFloat asFraction |
|
222 |
3.14159 asFraction |
|
223 |
1.3 asFraction |
|
224 |
1.0 asFraction |
|
225 |
" |
|
2793 | 226 |
|
3060 | 227 |
"Modified: / 25.10.1997 / 16:41:19 / cg" |
55 | 228 |
! |
229 |
||
230 |
asInteger |
|
231 |
"return an integer with same value - might truncate" |
|
232 |
||
3185 | 233 |
|max maxF| |
55 | 234 |
|
2388 | 235 |
self isNaN ifTrue:[ |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
236 |
^ self class |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
237 |
raise:#domainErrorSignal |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
238 |
receiver:self |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
239 |
selector:#asInteger |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
240 |
errorString:'receiver is NaN in #asInteger' |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
241 |
|
2388 | 242 |
]. |
243 |
||
3426 | 244 |
"/ NOTICE: this must be redefined in float |
245 |
"/ subclasses to handle the smallinteger range; |
|
246 |
"/ i.e. this may only be invoked for reals |
|
247 |
"/ which are NOT within the smallInt range. |
|
248 |
"/ otherwise, endless recursion is the consequence. |
|
249 |
||
3137 | 250 |
max := SmallInteger maxVal // 2 + 1. |
251 |
maxF := max asFloat. |
|
3426 | 252 |
|
3137 | 253 |
^ (self quo:maxF) * max + (self rem:maxF) truncated |
55 | 254 |
|
3137 | 255 |
" |
256 |
12345.0 asInteger |
|
257 |
1e15 asInteger |
|
258 |
1e33 asInteger |
|
259 |
" |
|
2388 | 260 |
|
261 |
"Modified: 12.2.1997 / 16:45:07 / cg" |
|
701 | 262 |
! |
263 |
||
264 |
coerce:aNumber |
|
265 |
"return aNumber converted into receivers type" |
|
266 |
||
1200 | 267 |
"/ as soon as Float are float & Double are doubles, |
268 |
"/ use: |
|
269 |
"/ ^ aNumber asDouble |
|
270 |
||
271 |
^ aNumber asFloat |
|
272 |
||
273 |
"Modified: 17.4.1996 / 12:36:46 / cg" |
|
701 | 274 |
! |
275 |
||
276 |
generality |
|
277 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
278 |
||
279 |
^ 80 |
|
280 |
! ! |
|
281 |
||
282 |
!LimitedPrecisionReal methodsFor:'comparing'! |
|
283 |
||
284 |
< aNumber |
|
285 |
"return true, if the argument is greater" |
|
286 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
287 |
"/ 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
|
288 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
289 |
"/ ^ aNumber lessFromDouble:self asDouble |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
290 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
291 |
^ aNumber lessFromFloat:self asFloat |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
292 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
293 |
"Modified: 17.4.1996 / 13:34:50 / cg" |
701 | 294 |
! |
295 |
||
296 |
<= aNumber |
|
297 |
"return true, if the argument is greater or equal" |
|
298 |
||
299 |
^ self retry:#<= coercing:aNumber |
|
300 |
! |
|
301 |
||
302 |
= aNumber |
|
303 |
"return true, if the arguments value are equal" |
|
304 |
||
305 |
^ self retry:#= coercing:aNumber |
|
306 |
! |
|
307 |
||
308 |
> aNumber |
|
309 |
"return true, if the argument is less" |
|
310 |
||
311 |
^ self retry:#> coercing:aNumber |
|
312 |
! |
|
313 |
||
314 |
>= aNumber |
|
315 |
"return true, if the argument is less or equal" |
|
316 |
||
317 |
^ self retry:#>= coercing:aNumber |
|
318 |
! |
|
319 |
||
320 |
~= aNumber |
|
321 |
"return true, if the arguments value are not equal" |
|
322 |
||
323 |
^ self retry:#~= coercing:aNumber |
|
324 |
! ! |
|
325 |
||
326 |
!LimitedPrecisionReal methodsFor:'copying'! |
|
327 |
||
328 |
deepCopy |
|
329 |
"return a deep copy of myself |
|
330 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
331 |
||
332 |
^ self |
|
333 |
! |
|
334 |
||
335 |
deepCopyUsing:aDictionary |
|
336 |
"return a deep copy of myself |
|
337 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
338 |
||
339 |
^ self |
|
340 |
! |
|
341 |
||
342 |
shallowCopy |
|
343 |
"return a shallow copy of the receiver" |
|
344 |
||
345 |
^ self |
|
346 |
! |
|
347 |
||
348 |
simpleDeepCopy |
|
349 |
"return a deep copy of the receiver |
|
350 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
351 |
||
352 |
^ self |
|
55 | 353 |
! ! |
354 |
||
355 |
!LimitedPrecisionReal methodsFor:'double dispatching'! |
|
356 |
||
357 |
differenceFromFraction:aFraction |
|
213 | 358 |
"sent when a fraction does not know how to subtract the receiver, a float" |
55 | 359 |
|
360 |
|d| |
|
361 |
||
362 |
d := aFraction denominator. |
|
363 |
^ (aFraction numerator - (self * d)) / d |
|
364 |
! |
|
365 |
||
366 |
productFromFraction:aFraction |
|
213 | 367 |
"sent when a fraction does not know how to multiply the receiver, a float" |
55 | 368 |
|
369 |
^ self * aFraction numerator / aFraction denominator |
|
370 |
! |
|
371 |
||
372 |
quotientFromFraction:aFraction |
|
213 | 373 |
"sent when a fraction does not know how to divide by the receiver, a float" |
55 | 374 |
|
375 |
^ aFraction numerator / (self * aFraction denominator) |
|
701 | 376 |
! |
377 |
||
378 |
sumFromFraction:aFraction |
|
379 |
"sent when a fraction does not know how to add the receiver, a float" |
|
380 |
||
381 |
|d| |
|
382 |
||
383 |
d := aFraction denominator. |
|
384 |
^ (self * d + aFraction numerator) / d |
|
385 |
! ! |
|
386 |
||
387 |
!LimitedPrecisionReal methodsFor:'printing & storing'! |
|
388 |
||
389 |
printOn:aStream |
|
390 |
"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
|
391 |
the argument, aStream. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
392 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
393 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
394 |
#printOn: as basic print mechanism." |
701 | 395 |
|
396 |
aStream nextPutAll:self printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
397 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
398 |
"Modified: / 20.1.1998 / 14:10:46 / stefan" |
1200 | 399 |
! |
400 |
||
401 |
printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
402 |
"return a printed representation of the receiver |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
403 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
404 |
#printOn: as basic print mechanism." |
1200 | 405 |
|
406 |
^ self subclassResponsibility |
|
407 |
||
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
408 |
"Created: / 17.4.1996 / 12:12:20 / cg" |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
409 |
"Modified: / 20.1.1998 / 14:10:47 / stefan" |
701 | 410 |
! ! |
411 |
||
412 |
!LimitedPrecisionReal methodsFor:'testing'! |
|
413 |
||
3148
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
414 |
isFinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
415 |
^ self subclassResponsibility |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
416 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
417 |
"Created: / 7.1.1998 / 12:02:06 / stefan" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
418 |
! |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
419 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
420 |
isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
421 |
"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
|
422 |
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
|
423 |
however, inline C-code could produce them ..." |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
424 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
425 |
^ (self isFinite or:[self isNaN]) not. |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
426 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
427 |
" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
428 |
1.0 isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
429 |
(0.0 uncheckedDivide: 0.0) isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
430 |
(1.0 uncheckedDivide: 0.0) isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
431 |
" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
432 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
433 |
"Modified: / 7.1.1998 / 12:01:30 / stefan" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
434 |
! |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
435 |
|
2388 | 436 |
isNaN |
437 |
^ self subclassResponsibility |
|
438 |
||
439 |
"Modified: 12.2.1997 / 16:45:27 / cg" |
|
440 |
! |
|
441 |
||
701 | 442 |
isReal |
443 |
"return true, if the receiver is some kind of real number; |
|
444 |
false is returned here - the method is redefined from Object." |
|
445 |
||
446 |
^ true |
|
447 |
! |
|
448 |
||
449 |
negative |
|
450 |
"return true if the receiver is less than zero" |
|
451 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
452 |
"/ 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
|
453 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
454 |
"/ ^ self asDouble negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
455 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
456 |
^ self asFloat negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
457 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
458 |
"Modified: 17.4.1996 / 13:35:00 / cg" |
701 | 459 |
! |
460 |
||
461 |
positive |
|
462 |
"return true if the receiver is greater or equal to zero" |
|
463 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
464 |
"/ 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
|
465 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
466 |
"/ ^ self asDouble positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
467 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
468 |
^ self asFloat positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
469 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
470 |
"Modified: 17.4.1996 / 13:35:10 / cg" |
55 | 471 |
! ! |
472 |
||
473 |
!LimitedPrecisionReal methodsFor:'truncation and rounding'! |
|
474 |
||
475 |
fractionPart |
|
1865
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
476 |
"return a float with value from digits after the decimal point. |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
477 |
(i.e. the receiver minus its truncated value)" |
55 | 478 |
|
479 |
^ self - self truncated asFloat |
|
480 |
||
1865
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
481 |
" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
482 |
1234.56789 fractionPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
483 |
1.2345e6 fractionPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
484 |
" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
485 |
|
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
486 |
"Modified: 4.11.1996 / 20:26:54 / cg" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
487 |
! |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
488 |
|
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
489 |
integerPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
490 |
"return a float with value from digits before the decimal point |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
491 |
(i.e. the truncated value)" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
492 |
|
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
493 |
^ self truncated asFloat |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
494 |
|
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
495 |
" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
496 |
1234.56789 integerPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
497 |
1.2345e6 integerPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
498 |
" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
499 |
|
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
500 |
"Modified: 4.11.1996 / 20:26:21 / cg" |
55 | 501 |
! ! |
502 |
||
701 | 503 |
!LimitedPrecisionReal class methodsFor:'documentation'! |
55 | 504 |
|
701 | 505 |
version |
3426 | 506 |
^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.28 1998-05-08 12:02:08 cg Exp $' |
55 | 507 |
! ! |