author | Claus Gittinger <cg@exept.de> |
Thu, 07 May 1998 20:02:53 +0200 | |
changeset 3422 | 09c13ab58bb2 |
parent 3395 | 02f47135d80f |
child 3426 | a648de89ac72 |
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 |
||
3137 | 244 |
max := SmallInteger maxVal // 2 + 1. |
245 |
maxF := max asFloat. |
|
246 |
^ (self quo:maxF) * max + (self rem:maxF) truncated |
|
55 | 247 |
|
3137 | 248 |
" |
249 |
12345.0 asInteger |
|
250 |
1e15 asInteger |
|
251 |
1e33 asInteger |
|
252 |
" |
|
2388 | 253 |
|
254 |
"Modified: 12.2.1997 / 16:45:07 / cg" |
|
701 | 255 |
! |
256 |
||
257 |
coerce:aNumber |
|
258 |
"return aNumber converted into receivers type" |
|
259 |
||
1200 | 260 |
"/ as soon as Float are float & Double are doubles, |
261 |
"/ use: |
|
262 |
"/ ^ aNumber asDouble |
|
263 |
||
264 |
^ aNumber asFloat |
|
265 |
||
266 |
"Modified: 17.4.1996 / 12:36:46 / cg" |
|
701 | 267 |
! |
268 |
||
269 |
generality |
|
270 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
271 |
||
272 |
^ 80 |
|
273 |
! ! |
|
274 |
||
275 |
!LimitedPrecisionReal methodsFor:'comparing'! |
|
276 |
||
277 |
< aNumber |
|
278 |
"return true, if the argument is greater" |
|
279 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
280 |
"/ 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
|
281 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
282 |
"/ ^ aNumber lessFromDouble:self asDouble |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
283 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
284 |
^ aNumber lessFromFloat:self asFloat |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
285 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
286 |
"Modified: 17.4.1996 / 13:34:50 / cg" |
701 | 287 |
! |
288 |
||
289 |
<= aNumber |
|
290 |
"return true, if the argument is greater or equal" |
|
291 |
||
292 |
^ self retry:#<= coercing:aNumber |
|
293 |
! |
|
294 |
||
295 |
= aNumber |
|
296 |
"return true, if the arguments value are equal" |
|
297 |
||
298 |
^ self retry:#= coercing:aNumber |
|
299 |
! |
|
300 |
||
301 |
> aNumber |
|
302 |
"return true, if the argument is less" |
|
303 |
||
304 |
^ self retry:#> coercing:aNumber |
|
305 |
! |
|
306 |
||
307 |
>= aNumber |
|
308 |
"return true, if the argument is less or equal" |
|
309 |
||
310 |
^ self retry:#>= coercing:aNumber |
|
311 |
! |
|
312 |
||
313 |
~= aNumber |
|
314 |
"return true, if the arguments value are not equal" |
|
315 |
||
316 |
^ self retry:#~= coercing:aNumber |
|
317 |
! ! |
|
318 |
||
319 |
!LimitedPrecisionReal methodsFor:'copying'! |
|
320 |
||
321 |
deepCopy |
|
322 |
"return a deep copy of myself |
|
323 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
324 |
||
325 |
^ self |
|
326 |
! |
|
327 |
||
328 |
deepCopyUsing:aDictionary |
|
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 |
shallowCopy |
|
336 |
"return a shallow copy of the receiver" |
|
337 |
||
338 |
^ self |
|
339 |
! |
|
340 |
||
341 |
simpleDeepCopy |
|
342 |
"return a deep copy of the receiver |
|
343 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
344 |
||
345 |
^ self |
|
55 | 346 |
! ! |
347 |
||
348 |
!LimitedPrecisionReal methodsFor:'double dispatching'! |
|
349 |
||
350 |
differenceFromFraction:aFraction |
|
213 | 351 |
"sent when a fraction does not know how to subtract the receiver, a float" |
55 | 352 |
|
353 |
|d| |
|
354 |
||
355 |
d := aFraction denominator. |
|
356 |
^ (aFraction numerator - (self * d)) / d |
|
357 |
! |
|
358 |
||
359 |
productFromFraction:aFraction |
|
213 | 360 |
"sent when a fraction does not know how to multiply the receiver, a float" |
55 | 361 |
|
362 |
^ self * aFraction numerator / aFraction denominator |
|
363 |
! |
|
364 |
||
365 |
quotientFromFraction:aFraction |
|
213 | 366 |
"sent when a fraction does not know how to divide by the receiver, a float" |
55 | 367 |
|
368 |
^ aFraction numerator / (self * aFraction denominator) |
|
701 | 369 |
! |
370 |
||
371 |
sumFromFraction:aFraction |
|
372 |
"sent when a fraction does not know how to add the receiver, a float" |
|
373 |
||
374 |
|d| |
|
375 |
||
376 |
d := aFraction denominator. |
|
377 |
^ (self * d + aFraction numerator) / d |
|
378 |
! ! |
|
379 |
||
380 |
!LimitedPrecisionReal methodsFor:'printing & storing'! |
|
381 |
||
382 |
printOn:aStream |
|
383 |
"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
|
384 |
the argument, aStream. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
385 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
386 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
387 |
#printOn: as basic print mechanism." |
701 | 388 |
|
389 |
aStream nextPutAll:self printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
390 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
391 |
"Modified: / 20.1.1998 / 14:10:46 / stefan" |
1200 | 392 |
! |
393 |
||
394 |
printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
395 |
"return a printed representation of the receiver |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
396 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
397 |
#printOn: as basic print mechanism." |
1200 | 398 |
|
399 |
^ self subclassResponsibility |
|
400 |
||
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
401 |
"Created: / 17.4.1996 / 12:12:20 / cg" |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
402 |
"Modified: / 20.1.1998 / 14:10:47 / stefan" |
701 | 403 |
! ! |
404 |
||
405 |
!LimitedPrecisionReal methodsFor:'testing'! |
|
406 |
||
3148
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
407 |
isFinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
408 |
^ self subclassResponsibility |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
409 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
410 |
"Created: / 7.1.1998 / 12:02:06 / stefan" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
411 |
! |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
412 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
413 |
isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
414 |
"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
|
415 |
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
|
416 |
however, inline C-code could produce them ..." |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
417 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
418 |
^ (self isFinite or:[self isNaN]) not. |
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 |
" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
421 |
1.0 isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
422 |
(0.0 uncheckedDivide: 0.0) isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
423 |
(1.0 uncheckedDivide: 0.0) isInfinite |
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 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
426 |
"Modified: / 7.1.1998 / 12:01:30 / stefan" |
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 |
|
2388 | 429 |
isNaN |
430 |
^ self subclassResponsibility |
|
431 |
||
432 |
"Modified: 12.2.1997 / 16:45:27 / cg" |
|
433 |
! |
|
434 |
||
701 | 435 |
isReal |
436 |
"return true, if the receiver is some kind of real number; |
|
437 |
false is returned here - the method is redefined from Object." |
|
438 |
||
439 |
^ true |
|
440 |
! |
|
441 |
||
442 |
negative |
|
443 |
"return true if the receiver is less than zero" |
|
444 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
445 |
"/ 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
|
446 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
447 |
"/ ^ self asDouble negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
448 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
449 |
^ self asFloat negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
450 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
451 |
"Modified: 17.4.1996 / 13:35:00 / cg" |
701 | 452 |
! |
453 |
||
454 |
positive |
|
455 |
"return true if the receiver is greater or equal to zero" |
|
456 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
457 |
"/ 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
|
458 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
459 |
"/ ^ self asDouble positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
460 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
461 |
^ self asFloat positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
462 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
463 |
"Modified: 17.4.1996 / 13:35:10 / cg" |
55 | 464 |
! ! |
465 |
||
466 |
!LimitedPrecisionReal methodsFor:'truncation and rounding'! |
|
467 |
||
468 |
fractionPart |
|
1865
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
469 |
"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
|
470 |
(i.e. the receiver minus its truncated value)" |
55 | 471 |
|
472 |
^ self - self truncated asFloat |
|
473 |
||
1865
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
474 |
" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
475 |
1234.56789 fractionPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
476 |
1.2345e6 fractionPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
477 |
" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
478 |
|
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
479 |
"Modified: 4.11.1996 / 20:26:54 / cg" |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
480 |
! |
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 |
integerPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
483 |
"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
|
484 |
(i.e. the truncated value)" |
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 |
^ self truncated asFloat |
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 |
1234.56789 integerPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
490 |
1.2345e6 integerPart |
5168897c326f
added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1295
diff
changeset
|
491 |
" |
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 |
"Modified: 4.11.1996 / 20:26:21 / cg" |
55 | 494 |
! ! |
495 |
||
701 | 496 |
!LimitedPrecisionReal class methodsFor:'documentation'! |
55 | 497 |
|
701 | 498 |
version |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
499 |
^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.27 1998-04-22 19:12:26 cg Exp $' |
55 | 500 |
! ! |