author | Claus Gittinger <cg@exept.de> |
Tue, 15 Apr 1997 13:05:18 +0200 | |
changeset 2549 | 9ca8a3fcdaa7 |
parent 2401 | ffc0dcc555cb |
child 3014 | 9934bb63d455 |
permissions | -rw-r--r-- |
1197 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
||
14 |
||
15 |
LimitedPrecisionReal variableByteSubclass:#ShortFloat |
|
16 |
instanceVariableNames:'' |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
17 |
classVariableNames:'' |
1197 | 18 |
poolDictionaries:'' |
19 |
category:'Magnitude-Numbers' |
|
20 |
! |
|
21 |
||
2394 | 22 |
!ShortFloat primitiveDefinitions! |
23 |
%{ |
|
24 |
||
25 |
/* |
|
26 |
* includes, defines, structure definitions |
|
27 |
* and typedefs come here. |
|
28 |
*/ |
|
29 |
||
30 |
#if defined (_AIX) |
|
31 |
# include <float.h> |
|
32 |
#endif |
|
2395 | 33 |
#if defined(IRIX) |
34 |
# include <nan.h> |
|
35 |
#endif |
|
2397 | 36 |
#if defined(LINUX) |
37 |
# include <nan.h> |
|
38 |
#endif |
|
2400 | 39 |
#if defined(solaris) || defined(sunos) |
2398 | 40 |
# include <nan.h> |
41 |
#endif |
|
2394 | 42 |
|
43 |
%} |
|
44 |
! ! |
|
45 |
||
1880 | 46 |
!ShortFloat class methodsFor:'documentation'! |
1197 | 47 |
|
48 |
copyright |
|
49 |
" |
|
50 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
51 |
All Rights Reserved |
|
52 |
||
53 |
This software is furnished under a license and may be used |
|
54 |
only in accordance with the terms of that license and with the |
|
55 |
inclusion of the above copyright notice. This software may not |
|
56 |
be provided or otherwise made available to, or used by, any |
|
57 |
other person. No title to or ownership of the software is |
|
58 |
hereby transferred. |
|
59 |
" |
|
60 |
||
61 |
||
62 |
! |
|
63 |
||
64 |
documentation |
|
65 |
" |
|
66 |
ShortFloats represent rational numbers with limited precision. In ST/X, Float uses |
|
67 |
the underlying C-compilers double implementation, while ShortFloats are |
|
68 |
mapped onto C-floats. |
|
69 |
Therefore instances of Float are usually represented by the 8-byte IEE |
|
70 |
double precision float format, while ShortFloats use 4byte IEE format. |
|
71 |
(but there is no guaranty). |
|
72 |
||
73 |
Notice, that ST/X Floats are what Doubles are in ST-80 and ShortFloats are |
|
74 |
ST-80's Floats respectively. |
|
75 |
This may change in one of the next versions (at least on machines, which |
|
76 |
provide different float and double types in their C-compiler. |
|
77 |
||
78 |
WARNING: |
|
79 |
The layout of shortFloat instances is known by the runtime system and the compiler; |
|
80 |
you may not add instance variables here. |
|
81 |
Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats, |
|
82 |
and does its float-checks by an identity compare with the ShortFloat-class. |
|
83 |
(i.e. your subclasses instances may not be recognized as float-like objects, |
|
84 |
thus mixed mode arithmetic will always coerce them, effectively slowing things down). |
|
85 |
||
86 |
This may be changed, to use a flag bit in the class. |
|
1295 | 87 |
|
88 |
[author:] |
|
89 |
Claus Gittinger |
|
1556 | 90 |
|
91 |
[see also:] |
|
92 |
Number |
|
1893 | 93 |
Float Fraction FixedPoint Integer |
1197 | 94 |
" |
95 |
||
96 |
! ! |
|
97 |
||
1880 | 98 |
!ShortFloat class methodsFor:'instance creation'! |
1207 | 99 |
|
100 |
basicNew |
|
101 |
"return a new shortFloat - here we return 0.0 |
|
102 |
- shortFloats are usually NOT created this way ... |
|
103 |
Its implemented here to allow things like binary store & load |
|
104 |
of shortFloats. (but even this support will go away eventually, its not |
|
105 |
a good idea to store the bits of a float - the reader might have a |
|
106 |
totally different representation - so floats will eventually be |
|
107 |
binary stored in a device independent format." |
|
108 |
||
109 |
%{ /* NOCONTEXT */ |
|
110 |
OBJ newFloat; |
|
111 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
112 |
__qMKSFLOAT(newFloat, 0.0); |
1207 | 113 |
RETURN (newFloat); |
114 |
%} |
|
115 |
! ! |
|
116 |
||
1880 | 117 |
!ShortFloat class methodsFor:'constants'! |
1197 | 118 |
|
119 |
pi |
|
1260 | 120 |
"return the constant pi as ShortFloat" |
1197 | 121 |
|
122 |
^ 3.14159 asShortFloat |
|
123 |
||
1260 | 124 |
"Modified: 23.4.1996 / 09:26:31 / cg" |
1197 | 125 |
! |
126 |
||
127 |
unity |
|
1260 | 128 |
"return the neutral element for multiplication (1.0) as ShortFloat" |
1197 | 129 |
|
130 |
^ 1.0 asShortFloat |
|
131 |
||
1260 | 132 |
"Modified: 23.4.1996 / 09:26:51 / cg" |
1197 | 133 |
! |
134 |
||
135 |
zero |
|
1260 | 136 |
"return the neutral element for addition (0.0) as ShortFloat" |
1197 | 137 |
|
138 |
^ 0.0 asShortFloat |
|
139 |
||
1260 | 140 |
"Modified: 23.4.1996 / 09:26:45 / cg" |
1197 | 141 |
! ! |
142 |
||
1880 | 143 |
!ShortFloat class methodsFor:'queries'! |
1197 | 144 |
|
145 |
isBuiltInClass |
|
1264 | 146 |
"return true if this class is known by the run-time-system. |
147 |
Here, true is returned for myself, false for subclasses." |
|
1197 | 148 |
|
149 |
^ self == ShortFloat |
|
150 |
||
1264 | 151 |
"Modified: 23.4.1996 / 16:00:23 / cg" |
1197 | 152 |
! ! |
153 |
||
154 |
!ShortFloat methodsFor:'arithmetic'! |
|
155 |
||
156 |
* aNumber |
|
157 |
"return the product of the receiver and the argument, aNumber" |
|
158 |
||
159 |
%{ /* NOCONTEXT */ |
|
160 |
||
161 |
OBJ newFloat; |
|
162 |
float result; |
|
163 |
double dResult; |
|
164 |
||
165 |
if (__isSmallInteger(aNumber)) { |
|
166 |
result = __shortFloatVal(self) * (float)(__intVal(aNumber)); |
|
167 |
retResult: |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
168 |
__qMKSFLOAT(newFloat, result); |
1197 | 169 |
RETURN ( newFloat ); |
170 |
} |
|
171 |
if (__isShortFloat(aNumber)) { |
|
172 |
result = __shortFloatVal(self) * __shortFloatVal(aNumber); |
|
173 |
goto retResult; |
|
174 |
} |
|
175 |
if (__isFloatLike(aNumber)) { |
|
176 |
dResult = (double) __shortFloatVal(self)* __floatVal(aNumber); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
177 |
__qMKFLOAT(newFloat, dResult); |
1197 | 178 |
RETURN ( newFloat ); |
179 |
||
180 |
} |
|
181 |
%}. |
|
182 |
^ aNumber productFromShortFloat:self |
|
183 |
! |
|
184 |
||
185 |
+ aNumber |
|
186 |
"return the sum of the receiver and the argument, aNumber" |
|
187 |
||
188 |
%{ /* NOCONTEXT */ |
|
189 |
||
190 |
OBJ newFloat; |
|
191 |
float result; |
|
192 |
double dResult; |
|
193 |
||
194 |
if (__isSmallInteger(aNumber)) { |
|
195 |
result = __shortFloatVal(self) + (float)(__intVal(aNumber)); |
|
196 |
retResult: |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
197 |
__qMKSFLOAT(newFloat, result); |
1197 | 198 |
RETURN ( newFloat ); |
199 |
} |
|
200 |
if (__isShortFloat(aNumber)) { |
|
201 |
result = __shortFloatVal(self) + __shortFloatVal(aNumber); |
|
202 |
goto retResult; |
|
203 |
} |
|
204 |
if (__isFloatLike(aNumber)) { |
|
205 |
dResult = (double) __shortFloatVal(self) + __floatVal(aNumber); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
206 |
__qMKFLOAT(newFloat, dResult); |
1197 | 207 |
RETURN ( newFloat ); |
208 |
||
209 |
} |
|
210 |
%}. |
|
211 |
^ aNumber sumFromShortFloat:self |
|
212 |
! |
|
213 |
||
214 |
- aNumber |
|
215 |
"return the difference of the receiver and the argument, aNumber" |
|
216 |
||
217 |
%{ /* NOCONTEXT */ |
|
218 |
||
219 |
OBJ newFloat; |
|
220 |
float result; |
|
221 |
double dResult; |
|
222 |
||
223 |
if (__isSmallInteger(aNumber)) { |
|
224 |
result = __shortFloatVal(self) - (float)(__intVal(aNumber)); |
|
225 |
retResult: |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
226 |
__qMKSFLOAT(newFloat, result); |
1197 | 227 |
RETURN ( newFloat ); |
228 |
} |
|
229 |
if (__isShortFloat(aNumber)) { |
|
230 |
result = __shortFloatVal(self) - __shortFloatVal(aNumber); |
|
231 |
goto retResult; |
|
232 |
} |
|
233 |
if (__isFloatLike(aNumber)) { |
|
234 |
dResult = (double) __shortFloatVal(self) - __floatVal(aNumber); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
235 |
__qMKFLOAT(newFloat, dResult); |
1197 | 236 |
RETURN ( newFloat ); |
237 |
||
238 |
} |
|
239 |
%}. |
|
240 |
^ aNumber differenceFromShortFloat:self |
|
241 |
! |
|
242 |
||
243 |
/ aNumber |
|
244 |
"return the quotient of the receiver and the argument, aNumber" |
|
245 |
||
246 |
%{ /* NOCONTEXT */ |
|
247 |
||
248 |
OBJ newFloat; |
|
249 |
float result, val; |
|
250 |
double dResult, dVal; |
|
251 |
||
252 |
if (__isSmallInteger(aNumber)) { |
|
253 |
if (aNumber != __MKSMALLINT(0)) { |
|
254 |
result = __shortFloatVal(self) / (float)(__intVal(aNumber)); |
|
255 |
retResult: |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
256 |
__qMKSFLOAT(newFloat, result); |
1197 | 257 |
RETURN ( newFloat ); |
258 |
} |
|
259 |
} |
|
260 |
if (__isShortFloat(aNumber)) { |
|
261 |
val = __shortFloatVal(aNumber); |
|
262 |
if (val != 0.0) { |
|
263 |
result = __shortFloatVal(self) / val; |
|
264 |
goto retResult; |
|
265 |
} |
|
266 |
} |
|
267 |
if (__isFloatLike(aNumber)) { |
|
268 |
dVal = __floatVal(aNumber); |
|
269 |
if (dVal != 0.0) { |
|
270 |
dResult = (double) __shortFloatVal(self) / dVal; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
271 |
__qMKFLOAT(newFloat, dResult); |
1197 | 272 |
} |
273 |
RETURN ( newFloat ); |
|
274 |
||
275 |
} |
|
276 |
%}. |
|
277 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
278 |
" |
|
279 |
No, you shalt not divide by zero |
|
280 |
" |
|
281 |
^ DivisionByZeroSignal raise. |
|
282 |
]. |
|
283 |
^ aNumber quotientFromFloat:self |
|
284 |
||
285 |
! |
|
286 |
||
287 |
negated |
|
288 |
"return myself negated" |
|
289 |
||
290 |
%{ /* NOCONTEXT */ |
|
291 |
OBJ newFloat; |
|
292 |
float rslt = - __shortFloatVal(self); |
|
293 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
294 |
__qMKSFLOAT(newFloat, rslt); |
1197 | 295 |
RETURN ( newFloat ); |
296 |
%} |
|
297 |
||
298 |
! ! |
|
299 |
||
300 |
!ShortFloat methodsFor:'coercion and converting'! |
|
301 |
||
302 |
asFloat |
|
303 |
"return a Float with same value as the receiver" |
|
304 |
||
305 |
%{ /* NOCONTEXT */ |
|
306 |
||
307 |
OBJ newFloat; |
|
308 |
double dVal = (double)__shortFloatVal(self); |
|
309 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
310 |
__qMKFLOAT(newFloat, dVal); |
1197 | 311 |
RETURN ( newFloat ); |
312 |
%} |
|
313 |
||
314 |
" |
|
1583 | 315 |
1.0 asShortFloat asFloat |
1197 | 316 |
" |
317 |
! |
|
318 |
||
319 |
asInteger |
|
320 |
"return an integer with same value - might truncate" |
|
321 |
||
322 |
%{ /* NOCONTEXT */ |
|
1670 | 323 |
float fVal; |
1197 | 324 |
|
1670 | 325 |
fVal = __shortFloatVal(self); |
326 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
|
327 |
RETURN ( __MKSMALLINT( (INT)fVal) ); |
|
1197 | 328 |
} |
329 |
%}. |
|
330 |
^ super asInteger |
|
331 |
||
332 |
" |
|
333 |
12345.0 asShortFloat asInteger |
|
334 |
1e15 asShortFloat asInteger |
|
335 |
" |
|
336 |
! |
|
337 |
||
338 |
asShortFloat |
|
339 |
"return a ShortFloat with same value as the receiver - thats me" |
|
340 |
||
341 |
^ self |
|
1200 | 342 |
! |
343 |
||
344 |
generality |
|
345 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
346 |
||
347 |
^ 70 |
|
348 |
||
349 |
||
1197 | 350 |
! ! |
351 |
||
352 |
!ShortFloat methodsFor:'comparing'! |
|
353 |
||
354 |
< aNumber |
|
355 |
"return true, if the argument is greater" |
|
356 |
||
357 |
%{ /* NOCONTEXT */ |
|
358 |
||
359 |
if (__isSmallInteger(aNumber)) { |
|
360 |
RETURN ( (__shortFloatVal(self) < (float)(__intVal(aNumber))) ? true : false ); |
|
361 |
} |
|
362 |
if (__isFloatLike(aNumber)) { |
|
363 |
RETURN ( (double)(__shortFloatVal(self) < __floatVal(aNumber)) ? true : false ); |
|
364 |
} |
|
365 |
if (__isShortFloat(aNumber)) { |
|
366 |
RETURN ( (__shortFloatVal(self) < __shortFloatVal(aNumber)) ? true : false ); |
|
367 |
} |
|
368 |
%}. |
|
369 |
^ aNumber lessFromShortFloat:self |
|
370 |
||
1200 | 371 |
" |
372 |
1.0 asShortFloat > (1/3) |
|
373 |
" |
|
1197 | 374 |
! |
375 |
||
376 |
<= aNumber |
|
377 |
"return true, if the argument is greater or equal" |
|
378 |
||
379 |
%{ /* NOCONTEXT */ |
|
380 |
||
381 |
if (__isSmallInteger(aNumber)) { |
|
382 |
RETURN ( (__shortFloatVal(self) <= (float)(__intVal(aNumber))) ? true : false ); |
|
383 |
} |
|
384 |
if (__isFloatLike(aNumber)) { |
|
385 |
RETURN ( (double)(__shortFloatVal(self) <= __floatVal(aNumber)) ? true : false ); |
|
386 |
} |
|
387 |
if (__isShortFloat(aNumber)) { |
|
388 |
RETURN ( (__shortFloatVal(self) <= __shortFloatVal(aNumber)) ? true : false ); |
|
389 |
} |
|
390 |
%}. |
|
391 |
^ self retry:#<= coercing:aNumber |
|
392 |
||
393 |
! |
|
394 |
||
395 |
= aNumber |
|
396 |
"return true, if the arguments value are equal by value" |
|
397 |
||
398 |
%{ /* NOCONTEXT */ |
|
399 |
||
400 |
if (__isSmallInteger(aNumber)) { |
|
401 |
RETURN ( (__shortFloatVal(self) == (float)(__intVal(aNumber))) ? true : false ); |
|
402 |
} |
|
403 |
if (__isFloatLike(aNumber)) { |
|
404 |
RETURN ( (double)(__shortFloatVal(self) == __floatVal(aNumber)) ? true : false ); |
|
405 |
} |
|
406 |
if (__isShortFloat(aNumber)) { |
|
407 |
RETURN ( (__shortFloatVal(self) == __shortFloatVal(aNumber)) ? true : false ); |
|
408 |
} |
|
409 |
%}. |
|
410 |
^ self retry:#= coercing:aNumber |
|
411 |
||
412 |
! |
|
413 |
||
414 |
> aNumber |
|
415 |
"return true, if the argument is less" |
|
416 |
||
417 |
%{ /* NOCONTEXT */ |
|
418 |
||
419 |
if (__isSmallInteger(aNumber)) { |
|
420 |
RETURN ( (__shortFloatVal(self) > (float)(__intVal(aNumber))) ? true : false ); |
|
421 |
} |
|
422 |
if (__isFloatLike(aNumber)) { |
|
423 |
RETURN ( (double)(__shortFloatVal(self) > __floatVal(aNumber)) ? true : false ); |
|
424 |
} |
|
425 |
if (__isShortFloat(aNumber)) { |
|
426 |
RETURN ( (__shortFloatVal(self) > __shortFloatVal(aNumber)) ? true : false ); |
|
427 |
} |
|
428 |
%}. |
|
429 |
^ self retry:#> coercing:aNumber |
|
430 |
! |
|
431 |
||
432 |
>= aNumber |
|
433 |
"return true, if the argument is less or equal" |
|
434 |
||
435 |
%{ /* NOCONTEXT */ |
|
436 |
||
437 |
if (__isSmallInteger(aNumber)) { |
|
438 |
RETURN ( (__shortFloatVal(self) >= (float)(__intVal(aNumber))) ? true : false ); |
|
439 |
} |
|
440 |
if (__isFloatLike(aNumber)) { |
|
441 |
RETURN ( (double)(__shortFloatVal(self) >= __floatVal(aNumber)) ? true : false ); |
|
442 |
} |
|
443 |
if (__isShortFloat(aNumber)) { |
|
444 |
RETURN ( (__shortFloatVal(self) >= __shortFloatVal(aNumber)) ? true : false ); |
|
445 |
} |
|
446 |
%}. |
|
447 |
^ self retry:#>= coercing:aNumber |
|
448 |
! |
|
449 |
||
450 |
hash |
|
451 |
"return a number for hashing; redefined, since floats compare |
|
452 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
453 |
as 3 hash." |
|
454 |
||
455 |
|i| |
|
456 |
||
457 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
458 |
i := self asInteger. |
|
459 |
self = i ifTrue:[ |
|
460 |
^ i hash |
|
461 |
]. |
|
462 |
]. |
|
463 |
||
464 |
" |
|
465 |
mhmh take some of my value-bits to hash on |
|
466 |
" |
|
467 |
^ (((self basicAt:4) bitAnd:16r3F) bitShift:24) + |
|
468 |
((self basicAt:3) bitShift:16) + |
|
469 |
((self basicAt:2) bitShift:8) + |
|
470 |
(self basicAt:1) |
|
471 |
||
472 |
" |
|
473 |
1.2345 hash |
|
474 |
1.2345 asShortFloat hash |
|
475 |
1.0 hash |
|
476 |
1.0 asShortFloat hash |
|
477 |
" |
|
478 |
! |
|
479 |
||
480 |
~= aNumber |
|
481 |
"return true, if the arguments value are not equal" |
|
482 |
||
483 |
%{ /* NOCONTEXT */ |
|
484 |
||
485 |
if (__isSmallInteger(aNumber)) { |
|
486 |
RETURN ( (__shortFloatVal(self) != (float)(__intVal(aNumber))) ? true : false ); |
|
487 |
} |
|
488 |
if (__isFloatLike(aNumber)) { |
|
489 |
RETURN ( (double)(__shortFloatVal(self) != __floatVal(aNumber)) ? true : false ); |
|
490 |
} |
|
491 |
if (__isShortFloat(aNumber)) { |
|
492 |
RETURN ( (__shortFloatVal(self) != __shortFloatVal(aNumber)) ? true : false ); |
|
493 |
} |
|
494 |
%}. |
|
495 |
^ self retry:#~= coercing:aNumber |
|
496 |
||
497 |
! ! |
|
498 |
||
499 |
!ShortFloat methodsFor:'printing & storing'! |
|
500 |
||
501 |
printString |
|
502 |
"return a printed representation of the receiver" |
|
503 |
||
504 |
%{ /* NOCONTEXT */ |
|
505 |
||
506 |
char buffer[64]; |
|
507 |
REGISTER char *cp; |
|
508 |
OBJ s; |
|
509 |
||
510 |
/* |
|
511 |
* actually only needed on sparc: since thisContext is |
|
512 |
* in a global register, which gets destroyed by printf, |
|
513 |
* manually save it here - very stupid ... |
|
514 |
*/ |
|
515 |
__BEGIN_PROTECT_REGISTERS__ |
|
516 |
||
517 |
#ifdef SYSV |
|
518 |
sprintf(buffer, "%.6lg", (double)__shortFloatVal(self)); |
|
519 |
#else |
|
520 |
sprintf(buffer, "%.6G", (double)__shortFloatVal(self)); |
|
521 |
#endif |
|
522 |
||
523 |
__END_PROTECT_REGISTERS__ |
|
524 |
||
525 |
/* |
|
526 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
527 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
528 |
*/ |
|
529 |
for (cp = buffer; *cp; cp++) { |
|
530 |
if ((*cp == '.') || (*cp == 'e')) break; |
|
531 |
} |
|
532 |
if (! *cp) { |
|
533 |
*cp++ = '.'; |
|
534 |
*cp++ = '0'; |
|
535 |
*cp = '\0'; |
|
536 |
} |
|
537 |
||
538 |
s = __MKSTRING(buffer COMMA_SND); |
|
539 |
if (s != nil) { |
|
540 |
RETURN (s); |
|
541 |
} |
|
542 |
%}. |
|
543 |
" |
|
544 |
memory allocation (for the new string) failed. |
|
545 |
When we arrive here, there was no memory, even after a garbage collect. |
|
546 |
This means, that the VM wanted to get some more memory from the |
|
547 |
OS, which was not kind enough to give it. |
|
548 |
Bad luck - you should increase the swap space on your machine. |
|
549 |
" |
|
550 |
^ ObjectMemory allocationFailureSignal raise. |
|
551 |
! ! |
|
552 |
||
553 |
!ShortFloat methodsFor:'testing'! |
|
554 |
||
2387 | 555 |
isNaN |
556 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
557 |
These are not created by ST/X float operations (they raise an exception); |
|
558 |
however, inline C-code could produce them ..." |
|
559 |
||
560 |
%{ /* NOCONTEXT */ |
|
561 |
||
2395 | 562 |
/* |
563 |
* sigh - every vendor is playing its own game here ... |
|
564 |
* Q: what are standards worth, anyway ? |
|
565 |
*/ |
|
2392 | 566 |
#ifdef IS_NAN |
567 |
if (IS_NAN(__shortFloatVal(self))) { RETURN (true); } |
|
2393 | 568 |
#endif |
569 |
#ifdef IS_QNAN |
|
2392 | 570 |
if (IS_QNAN(__shortFloatVal(self))) { RETURN (true); } |
2393 | 571 |
#endif |
2392 | 572 |
|
2393 | 573 |
#ifdef FLT_SNAN |
574 |
if (__shortFloatVal(self) == FLT_SNAN) { RETURN (true); } |
|
575 |
#endif |
|
576 |
#ifdef FLT_QNAN |
|
577 |
if (__shortFloatVal(self) == FLT_QNAN) { RETURN (true); } |
|
578 |
#endif |
|
579 |
||
580 |
#ifdef _SNANF |
|
2389 | 581 |
if (__shortFloatVal(self) == _SNAN) { RETURN (true); } |
2393 | 582 |
#endif |
583 |
#ifdef _QNANF |
|
2389 | 584 |
if (__shortFloatVal(self) == _QNAN) { RETURN (true); } |
2393 | 585 |
#endif |
2392 | 586 |
|
2395 | 587 |
#ifdef IsPosNAN |
588 |
if IsPosNAN(__shortFloatVal(self)) { RETURN (true); } |
|
589 |
#endif |
|
590 |
#ifdef IsNegNAN |
|
591 |
if IsNegNAN(__shortFloatVal(self)) { RETURN (true); } |
|
592 |
#endif |
|
593 |
||
2393 | 594 |
#ifdef NAN |
2392 | 595 |
if (__shortFloatVal(self) == NAN) { RETURN (true); } |
2389 | 596 |
#endif |
2400 | 597 |
#ifdef NaN |
2401 | 598 |
if (NaN(__shortFloatVal(self))) { RETURN (true); } |
2400 | 599 |
#endif |
2389 | 600 |
|
2392 | 601 |
%}. |
602 |
^ false |
|
2387 | 603 |
|
604 |
! |
|
605 |
||
1197 | 606 |
negative |
607 |
"return true if the receiver is less than zero" |
|
608 |
||
609 |
%{ /* NOCONTEXT */ |
|
610 |
||
611 |
RETURN ( (__shortFloatVal(self) < 0.0) ? true : false ); |
|
612 |
%} |
|
613 |
||
614 |
||
615 |
! |
|
616 |
||
617 |
positive |
|
618 |
"return true if the receiver is greater or equal to zero" |
|
619 |
||
620 |
%{ /* NOCONTEXT */ |
|
621 |
||
622 |
RETURN ( (__shortFloatVal(self) >= 0.0) ? true : false ); |
|
623 |
%} |
|
624 |
||
1880 | 625 |
! |
626 |
||
627 |
strictlyPositive |
|
628 |
"return true if the receiver is greater than zero" |
|
629 |
||
630 |
%{ /* NOCONTEXT */ |
|
631 |
||
632 |
RETURN ( (__shortFloatVal(self) > 0.0) ? true : false ); |
|
633 |
%} |
|
634 |
||
1197 | 635 |
! ! |
636 |
||
1880 | 637 |
!ShortFloat class methodsFor:'documentation'! |
1197 | 638 |
|
639 |
version |
|
2401 | 640 |
^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.23 1997-02-12 17:05:26 cg Exp $' |
1197 | 641 |
! ! |