author | Claus Gittinger <cg@exept.de> |
Thu, 21 May 1998 13:48:46 +0200 | |
changeset 3473 | 16906f100107 |
parent 3471 | 91bad1642e2f |
child 3528 | bc45c489b1b2 |
permissions | -rw-r--r-- |
1197 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3158 | 3 |
All Rights Reserved |
1197 | 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 |
||
3471 | 30 |
!Float primitiveDefinitions! |
31 |
%{ |
|
32 |
#include <errno.h> |
|
33 |
||
34 |
#ifndef __OPTIMIZE__ |
|
35 |
# define __OPTIMIZE__ |
|
36 |
#endif |
|
37 |
#include <math.h> |
|
38 |
||
39 |
/* |
|
40 |
* on some systems errno is a macro ... check for it here |
|
41 |
*/ |
|
42 |
#ifndef errno |
|
43 |
extern errno; |
|
44 |
#endif |
|
45 |
||
2394 | 46 |
#if defined (_AIX) |
47 |
# include <float.h> |
|
48 |
#endif |
|
2395 | 49 |
#if defined(IRIX) |
50 |
# include <nan.h> |
|
51 |
#endif |
|
2397 | 52 |
#if defined(LINUX) |
53 |
# include <nan.h> |
|
54 |
#endif |
|
2400 | 55 |
#if defined(solaris) || defined(sunos) |
2398 | 56 |
# include <nan.h> |
57 |
#endif |
|
2394 | 58 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
59 |
#ifdef WIN32 |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
60 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
61 |
* no finite(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
62 |
* no isnan(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
63 |
*/ |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
64 |
# ifndef finite |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
65 |
# define finite(x) 1 |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
66 |
# endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
67 |
# ifndef isnan |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
68 |
# define isnan(x) 0 |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
69 |
# endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
70 |
#endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
71 |
|
3414 | 72 |
#ifdef realIX |
73 |
/* |
|
74 |
* no finite(x) |
|
75 |
*/ |
|
76 |
# ifndef finite |
|
77 |
# define finite(x) 1 |
|
78 |
# endif |
|
79 |
#endif |
|
80 |
||
2394 | 81 |
%} |
82 |
! ! |
|
83 |
||
1880 | 84 |
!ShortFloat class methodsFor:'documentation'! |
1197 | 85 |
|
86 |
copyright |
|
87 |
" |
|
88 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3158 | 89 |
All Rights Reserved |
1197 | 90 |
|
91 |
This software is furnished under a license and may be used |
|
92 |
only in accordance with the terms of that license and with the |
|
93 |
inclusion of the above copyright notice. This software may not |
|
94 |
be provided or otherwise made available to, or used by, any |
|
95 |
other person. No title to or ownership of the software is |
|
96 |
hereby transferred. |
|
97 |
" |
|
98 |
||
99 |
||
100 |
! |
|
101 |
||
102 |
documentation |
|
103 |
" |
|
104 |
ShortFloats represent rational numbers with limited precision. In ST/X, Float uses |
|
105 |
the underlying C-compilers double implementation, while ShortFloats are |
|
106 |
mapped onto C-floats. |
|
107 |
Therefore instances of Float are usually represented by the 8-byte IEE |
|
108 |
double precision float format, while ShortFloats use 4byte IEE format. |
|
109 |
(but there is no guaranty). |
|
110 |
||
111 |
Notice, that ST/X Floats are what Doubles are in ST-80 and ShortFloats are |
|
112 |
ST-80's Floats respectively. |
|
113 |
This may change in one of the next versions (at least on machines, which |
|
114 |
provide different float and double types in their C-compiler. |
|
115 |
||
116 |
WARNING: |
|
117 |
The layout of shortFloat instances is known by the runtime system and the compiler; |
|
118 |
you may not add instance variables here. |
|
119 |
Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats, |
|
120 |
and does its float-checks by an identity compare with the ShortFloat-class. |
|
121 |
(i.e. your subclasses instances may not be recognized as float-like objects, |
|
122 |
thus mixed mode arithmetic will always coerce them, effectively slowing things down). |
|
123 |
||
124 |
This may be changed, to use a flag bit in the class. |
|
1295 | 125 |
|
126 |
[author:] |
|
3158 | 127 |
Claus Gittinger |
1556 | 128 |
|
129 |
[see also:] |
|
3158 | 130 |
Number |
131 |
Float Fraction FixedPoint Integer |
|
1197 | 132 |
" |
133 |
||
134 |
! ! |
|
135 |
||
1880 | 136 |
!ShortFloat class methodsFor:'instance creation'! |
1207 | 137 |
|
138 |
basicNew |
|
139 |
"return a new shortFloat - here we return 0.0 |
|
140 |
- shortFloats are usually NOT created this way ... |
|
141 |
Its implemented here to allow things like binary store & load |
|
142 |
of shortFloats. (but even this support will go away eventually, its not |
|
143 |
a good idea to store the bits of a float - the reader might have a |
|
144 |
totally different representation - so floats will eventually be |
|
145 |
binary stored in a device independent format." |
|
146 |
||
147 |
%{ /* NOCONTEXT */ |
|
148 |
OBJ newFloat; |
|
149 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
150 |
__qMKSFLOAT(newFloat, 0.0); |
1207 | 151 |
RETURN (newFloat); |
152 |
%} |
|
3158 | 153 |
! |
154 |
||
155 |
readFrom:aStringOrStream onError:exceptionBlock |
|
156 |
"read a shortFloat from a string" |
|
157 |
||
158 |
|num| |
|
159 |
||
160 |
num := super readFrom:aStringOrStream onError:nil. |
|
161 |
num isNil ifTrue:[ |
|
162 |
^ exceptionBlock value |
|
163 |
]. |
|
164 |
^ num asShortFloat |
|
165 |
||
166 |
" |
|
167 |
ShortFloat readFrom:'0.1' |
|
168 |
ShortFloat readFrom:'0' |
|
169 |
" |
|
170 |
||
171 |
"Modified: / 7.1.1998 / 16:17:59 / cg" |
|
1207 | 172 |
! ! |
173 |
||
1880 | 174 |
!ShortFloat class methodsFor:'constants'! |
1197 | 175 |
|
176 |
pi |
|
1260 | 177 |
"return the constant pi as ShortFloat" |
1197 | 178 |
|
179 |
^ 3.14159 asShortFloat |
|
180 |
||
1260 | 181 |
"Modified: 23.4.1996 / 09:26:31 / cg" |
1197 | 182 |
! |
183 |
||
184 |
unity |
|
1260 | 185 |
"return the neutral element for multiplication (1.0) as ShortFloat" |
1197 | 186 |
|
187 |
^ 1.0 asShortFloat |
|
188 |
||
1260 | 189 |
"Modified: 23.4.1996 / 09:26:51 / cg" |
1197 | 190 |
! |
191 |
||
192 |
zero |
|
1260 | 193 |
"return the neutral element for addition (0.0) as ShortFloat" |
1197 | 194 |
|
195 |
^ 0.0 asShortFloat |
|
196 |
||
1260 | 197 |
"Modified: 23.4.1996 / 09:26:45 / cg" |
1197 | 198 |
! ! |
199 |
||
1880 | 200 |
!ShortFloat class methodsFor:'queries'! |
1197 | 201 |
|
202 |
isBuiltInClass |
|
1264 | 203 |
"return true if this class is known by the run-time-system. |
204 |
Here, true is returned for myself, false for subclasses." |
|
1197 | 205 |
|
206 |
^ self == ShortFloat |
|
207 |
||
1264 | 208 |
"Modified: 23.4.1996 / 16:00:23 / cg" |
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
209 |
! |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
210 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
211 |
isIEEEFormat |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
212 |
"return true, if this machine represents floats in IEEE format. |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
213 |
Currently, no support is provided for non-ieee machines |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
214 |
to convert their floats into this (which is only relevant, |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
215 |
if such a machine wants to send floats as binary to some other |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
216 |
machine). |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
217 |
Machines with non-IEEE format are VAXed and IBM370-type systems |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
218 |
(among others). Today, most systems use IEEE format floats." |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
219 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
220 |
^ true "/ this may be a lie |
1197 | 221 |
! ! |
222 |
||
223 |
!ShortFloat methodsFor:'arithmetic'! |
|
224 |
||
225 |
* aNumber |
|
226 |
"return the product of the receiver and the argument, aNumber" |
|
227 |
||
228 |
%{ /* NOCONTEXT */ |
|
229 |
||
230 |
OBJ newFloat; |
|
231 |
float result; |
|
232 |
double dResult; |
|
233 |
||
234 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 235 |
result = __shortFloatVal(self) * (float)(__intVal(aNumber)); |
1197 | 236 |
retResult: |
3158 | 237 |
__qMKSFLOAT(newFloat, result); |
238 |
RETURN ( newFloat ); |
|
1197 | 239 |
} |
240 |
if (__isShortFloat(aNumber)) { |
|
3158 | 241 |
result = __shortFloatVal(self) * __shortFloatVal(aNumber); |
242 |
goto retResult; |
|
1197 | 243 |
} |
244 |
if (__isFloatLike(aNumber)) { |
|
3158 | 245 |
dResult = (double) __shortFloatVal(self)* __floatVal(aNumber); |
246 |
__qMKFLOAT(newFloat, dResult); |
|
247 |
RETURN ( newFloat ); |
|
1197 | 248 |
|
249 |
} |
|
250 |
%}. |
|
251 |
^ aNumber productFromShortFloat:self |
|
252 |
! |
|
253 |
||
254 |
+ aNumber |
|
255 |
"return the sum of the receiver and the argument, aNumber" |
|
256 |
||
257 |
%{ /* NOCONTEXT */ |
|
258 |
||
259 |
OBJ newFloat; |
|
260 |
float result; |
|
261 |
double dResult; |
|
262 |
||
263 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 264 |
result = __shortFloatVal(self) + (float)(__intVal(aNumber)); |
1197 | 265 |
retResult: |
3158 | 266 |
__qMKSFLOAT(newFloat, result); |
267 |
RETURN ( newFloat ); |
|
1197 | 268 |
} |
269 |
if (__isShortFloat(aNumber)) { |
|
3158 | 270 |
result = __shortFloatVal(self) + __shortFloatVal(aNumber); |
271 |
goto retResult; |
|
1197 | 272 |
} |
273 |
if (__isFloatLike(aNumber)) { |
|
3158 | 274 |
dResult = (double) __shortFloatVal(self) + __floatVal(aNumber); |
275 |
__qMKFLOAT(newFloat, dResult); |
|
276 |
RETURN ( newFloat ); |
|
1197 | 277 |
|
278 |
} |
|
279 |
%}. |
|
280 |
^ aNumber sumFromShortFloat:self |
|
281 |
! |
|
282 |
||
283 |
- aNumber |
|
284 |
"return the difference of the receiver and the argument, aNumber" |
|
285 |
||
286 |
%{ /* NOCONTEXT */ |
|
287 |
||
288 |
OBJ newFloat; |
|
289 |
float result; |
|
290 |
double dResult; |
|
291 |
||
292 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 293 |
result = __shortFloatVal(self) - (float)(__intVal(aNumber)); |
1197 | 294 |
retResult: |
3158 | 295 |
__qMKSFLOAT(newFloat, result); |
296 |
RETURN ( newFloat ); |
|
1197 | 297 |
} |
298 |
if (__isShortFloat(aNumber)) { |
|
3158 | 299 |
result = __shortFloatVal(self) - __shortFloatVal(aNumber); |
300 |
goto retResult; |
|
1197 | 301 |
} |
302 |
if (__isFloatLike(aNumber)) { |
|
3158 | 303 |
dResult = (double) __shortFloatVal(self) - __floatVal(aNumber); |
304 |
__qMKFLOAT(newFloat, dResult); |
|
305 |
RETURN ( newFloat ); |
|
1197 | 306 |
|
307 |
} |
|
308 |
%}. |
|
309 |
^ aNumber differenceFromShortFloat:self |
|
310 |
! |
|
311 |
||
312 |
/ aNumber |
|
313 |
"return the quotient of the receiver and the argument, aNumber" |
|
314 |
||
315 |
%{ /* NOCONTEXT */ |
|
316 |
||
317 |
OBJ newFloat; |
|
318 |
float result, val; |
|
319 |
double dResult, dVal; |
|
320 |
||
321 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 322 |
if (aNumber != __MKSMALLINT(0)) { |
323 |
result = __shortFloatVal(self) / (float)(__intVal(aNumber)); |
|
1197 | 324 |
retResult: |
3158 | 325 |
__qMKSFLOAT(newFloat, result); |
326 |
RETURN ( newFloat ); |
|
327 |
} |
|
1197 | 328 |
} |
329 |
if (__isShortFloat(aNumber)) { |
|
3158 | 330 |
val = __shortFloatVal(aNumber); |
331 |
if (val != 0.0) { |
|
332 |
result = __shortFloatVal(self) / val; |
|
333 |
goto retResult; |
|
334 |
} |
|
1197 | 335 |
} |
336 |
if (__isFloatLike(aNumber)) { |
|
3158 | 337 |
dVal = __floatVal(aNumber); |
338 |
if (dVal != 0.0) { |
|
339 |
dResult = (double) __shortFloatVal(self) / dVal; |
|
340 |
__qMKFLOAT(newFloat, dResult); |
|
341 |
} |
|
342 |
RETURN ( newFloat ); |
|
1197 | 343 |
|
344 |
} |
|
345 |
%}. |
|
346 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
3158 | 347 |
" |
348 |
No, you shalt not divide by zero |
|
349 |
" |
|
350 |
^ DivisionByZeroSignal raise. |
|
1197 | 351 |
]. |
352 |
^ aNumber quotientFromFloat:self |
|
353 |
||
354 |
! |
|
355 |
||
356 |
negated |
|
357 |
"return myself negated" |
|
358 |
||
359 |
%{ /* NOCONTEXT */ |
|
360 |
OBJ newFloat; |
|
361 |
float rslt = - __shortFloatVal(self); |
|
362 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
363 |
__qMKSFLOAT(newFloat, rslt); |
1197 | 364 |
RETURN ( newFloat ); |
365 |
%} |
|
366 |
||
3147 | 367 |
! |
368 |
||
369 |
uncheckedDivide:aNumber |
|
370 |
"return the quotient of the receiver and the argument, aNumber |
|
371 |
Do not check for divide by zero (return NaN or infinity)" |
|
372 |
||
373 |
%{ /* NOCONTEXT */ |
|
374 |
||
375 |
OBJ newFloat; |
|
376 |
float result, val; |
|
377 |
double dResult, dVal; |
|
378 |
||
379 |
if (__isSmallInteger(aNumber)) { |
|
380 |
result = __shortFloatVal(self) / (float)(__intVal(aNumber)); |
|
381 |
retResult: |
|
382 |
__qMKSFLOAT(newFloat, result); |
|
383 |
RETURN ( newFloat ); |
|
384 |
} |
|
385 |
if (__isShortFloat(aNumber)) { |
|
386 |
val = __shortFloatVal(aNumber); |
|
387 |
result = __shortFloatVal(self) / val; |
|
388 |
goto retResult; |
|
389 |
} |
|
390 |
if (__isFloatLike(aNumber)) { |
|
391 |
dVal = __floatVal(aNumber); |
|
392 |
dResult = (double) __shortFloatVal(self) / dVal; |
|
393 |
__qMKFLOAT(newFloat, dResult); |
|
394 |
RETURN ( newFloat ); |
|
395 |
} |
|
396 |
%}. |
|
397 |
^ aNumber quotientFromFloat:self |
|
398 |
||
399 |
" |
|
400 |
0.0 asShortFloat uncheckedDivide:0 |
|
401 |
1.0 asShortFloat uncheckedDivide:0.0 |
|
402 |
" |
|
403 |
||
1197 | 404 |
! ! |
405 |
||
406 |
!ShortFloat methodsFor:'coercion and converting'! |
|
407 |
||
3014 | 408 |
asDouble |
409 |
"ST80 compatibility - return a Float with same value as the receiver" |
|
410 |
||
411 |
^ self asFloat |
|
412 |
! |
|
413 |
||
1197 | 414 |
asFloat |
415 |
"return a Float with same value as the receiver" |
|
416 |
||
417 |
%{ /* NOCONTEXT */ |
|
418 |
||
419 |
OBJ newFloat; |
|
420 |
double dVal = (double)__shortFloatVal(self); |
|
421 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
422 |
__qMKFLOAT(newFloat, dVal); |
1197 | 423 |
RETURN ( newFloat ); |
424 |
%} |
|
425 |
||
426 |
" |
|
1583 | 427 |
1.0 asShortFloat asFloat |
1197 | 428 |
" |
429 |
! |
|
430 |
||
431 |
asInteger |
|
432 |
"return an integer with same value - might truncate" |
|
433 |
||
434 |
%{ /* NOCONTEXT */ |
|
1670 | 435 |
float fVal; |
1197 | 436 |
|
1670 | 437 |
fVal = __shortFloatVal(self); |
438 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
|
3158 | 439 |
RETURN ( __MKSMALLINT( (INT)fVal) ); |
1197 | 440 |
} |
441 |
%}. |
|
442 |
^ super asInteger |
|
443 |
||
444 |
" |
|
445 |
12345.0 asShortFloat asInteger |
|
446 |
1e15 asShortFloat asInteger |
|
447 |
" |
|
448 |
! |
|
449 |
||
450 |
asShortFloat |
|
451 |
"return a ShortFloat with same value as the receiver - thats me" |
|
452 |
||
453 |
^ self |
|
1200 | 454 |
! |
455 |
||
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
456 |
exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
457 |
"extract a normalized floats exponent. |
3473 | 458 |
The returned value depends on the float-representation of |
459 |
the underlying machine and is therefore highly unportable. |
|
460 |
This is not for general use. |
|
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
461 |
This assumes that the mantissa is normalized to |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
462 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
463 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
464 |
%{ /* NOCONTEXT */ |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
465 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
466 |
double frexp(); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
467 |
double frac; |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
468 |
INT pwr; |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
469 |
|
3471 | 470 |
errno = 0; |
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
471 |
frac = frexp( (double)(__shortFloatVal(self)), &pwr); |
3471 | 472 |
if (errno == 0) { |
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
473 |
if (pwr == 0) { |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
474 |
RETURN (__MKSMALLINT(0)); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
475 |
} |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
476 |
RETURN (__MKSMALLINT(pwr-1)); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
477 |
} |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
478 |
%}. |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
479 |
^ self primitiveFailed |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
480 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
481 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
482 |
1.0 asShortFloat exponent |
3473 | 483 |
1.0 asShortFloat exponent |
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
484 |
0.5 asShortFloat exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
485 |
0.25 asShortFloat exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
486 |
0.00000011111 asShortFloat exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
487 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
488 |
! |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
489 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
490 |
fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
491 |
"extract a normalized floats mantissa. |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
492 |
This assumes that the mantissa is normalized to |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
493 |
0.5 .. 1.0 and the floats value is man * 2^exp" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
494 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
495 |
%{ /* NOCONTEXT */ |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
496 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
497 |
double modf(); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
498 |
double frac, trunc; |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
499 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
500 |
errno = 0; |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
501 |
frac = modf((double)(__shortFloatVal(self)), &trunc); |
3471 | 502 |
if (errno == 0) { |
503 |
RETURN (__MKSFLOAT(frac)); |
|
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
504 |
} |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
505 |
%}. |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
506 |
^ self primitiveFailed |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
507 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
508 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
509 |
1.0 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
510 |
0.5 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
511 |
0.25 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
512 |
3.14159 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
513 |
12345673.14159 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
514 |
123456731231231231.14159 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
515 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
516 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
517 |
! |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
518 |
|
1200 | 519 |
generality |
520 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
521 |
||
522 |
^ 70 |
|
523 |
||
524 |
||
1197 | 525 |
! ! |
526 |
||
527 |
!ShortFloat methodsFor:'comparing'! |
|
528 |
||
529 |
< aNumber |
|
530 |
"return true, if the argument is greater" |
|
531 |
||
532 |
%{ /* NOCONTEXT */ |
|
533 |
||
534 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 535 |
RETURN ( (__shortFloatVal(self) < (float)(__intVal(aNumber))) ? true : false ); |
1197 | 536 |
} |
537 |
if (__isFloatLike(aNumber)) { |
|
3158 | 538 |
RETURN ( (double)(__shortFloatVal(self) < __floatVal(aNumber)) ? true : false ); |
1197 | 539 |
} |
540 |
if (__isShortFloat(aNumber)) { |
|
3158 | 541 |
RETURN ( (__shortFloatVal(self) < __shortFloatVal(aNumber)) ? true : false ); |
1197 | 542 |
} |
543 |
%}. |
|
544 |
^ aNumber lessFromShortFloat:self |
|
545 |
||
1200 | 546 |
" |
547 |
1.0 asShortFloat > (1/3) |
|
548 |
" |
|
1197 | 549 |
! |
550 |
||
551 |
<= aNumber |
|
552 |
"return true, if the argument is greater or equal" |
|
553 |
||
554 |
%{ /* NOCONTEXT */ |
|
555 |
||
556 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 557 |
RETURN ( (__shortFloatVal(self) <= (float)(__intVal(aNumber))) ? true : false ); |
1197 | 558 |
} |
559 |
if (__isFloatLike(aNumber)) { |
|
3158 | 560 |
RETURN ( (double)(__shortFloatVal(self) <= __floatVal(aNumber)) ? true : false ); |
1197 | 561 |
} |
562 |
if (__isShortFloat(aNumber)) { |
|
3158 | 563 |
RETURN ( (__shortFloatVal(self) <= __shortFloatVal(aNumber)) ? true : false ); |
1197 | 564 |
} |
565 |
%}. |
|
566 |
^ self retry:#<= coercing:aNumber |
|
567 |
||
568 |
! |
|
569 |
||
570 |
= aNumber |
|
571 |
"return true, if the arguments value are equal by value" |
|
572 |
||
573 |
%{ /* NOCONTEXT */ |
|
574 |
||
575 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 576 |
RETURN ( (__shortFloatVal(self) == (float)(__intVal(aNumber))) ? true : false ); |
1197 | 577 |
} |
578 |
if (__isFloatLike(aNumber)) { |
|
3158 | 579 |
RETURN ( (double)(__shortFloatVal(self) == __floatVal(aNumber)) ? true : false ); |
1197 | 580 |
} |
581 |
if (__isShortFloat(aNumber)) { |
|
3158 | 582 |
RETURN ( (__shortFloatVal(self) == __shortFloatVal(aNumber)) ? true : false ); |
1197 | 583 |
} |
584 |
%}. |
|
585 |
^ self retry:#= coercing:aNumber |
|
586 |
||
587 |
! |
|
588 |
||
589 |
> aNumber |
|
590 |
"return true, if the argument is less" |
|
591 |
||
592 |
%{ /* NOCONTEXT */ |
|
593 |
||
594 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 595 |
RETURN ( (__shortFloatVal(self) > (float)(__intVal(aNumber))) ? true : false ); |
1197 | 596 |
} |
597 |
if (__isFloatLike(aNumber)) { |
|
3158 | 598 |
RETURN ( (double)(__shortFloatVal(self) > __floatVal(aNumber)) ? true : false ); |
1197 | 599 |
} |
600 |
if (__isShortFloat(aNumber)) { |
|
3158 | 601 |
RETURN ( (__shortFloatVal(self) > __shortFloatVal(aNumber)) ? true : false ); |
1197 | 602 |
} |
603 |
%}. |
|
604 |
^ self retry:#> coercing:aNumber |
|
605 |
! |
|
606 |
||
607 |
>= aNumber |
|
608 |
"return true, if the argument is less or equal" |
|
609 |
||
610 |
%{ /* NOCONTEXT */ |
|
611 |
||
612 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 613 |
RETURN ( (__shortFloatVal(self) >= (float)(__intVal(aNumber))) ? true : false ); |
1197 | 614 |
} |
615 |
if (__isFloatLike(aNumber)) { |
|
3158 | 616 |
RETURN ( (double)(__shortFloatVal(self) >= __floatVal(aNumber)) ? true : false ); |
1197 | 617 |
} |
618 |
if (__isShortFloat(aNumber)) { |
|
3158 | 619 |
RETURN ( (__shortFloatVal(self) >= __shortFloatVal(aNumber)) ? true : false ); |
1197 | 620 |
} |
621 |
%}. |
|
622 |
^ self retry:#>= coercing:aNumber |
|
623 |
! |
|
624 |
||
625 |
hash |
|
626 |
"return a number for hashing; redefined, since floats compare |
|
627 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
628 |
as 3 hash." |
|
629 |
||
630 |
|i| |
|
631 |
||
632 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
3158 | 633 |
i := self asInteger. |
634 |
self = i ifTrue:[ |
|
635 |
^ i hash |
|
636 |
]. |
|
1197 | 637 |
]. |
638 |
||
639 |
" |
|
640 |
mhmh take some of my value-bits to hash on |
|
641 |
" |
|
642 |
^ (((self basicAt:4) bitAnd:16r3F) bitShift:24) + |
|
643 |
((self basicAt:3) bitShift:16) + |
|
644 |
((self basicAt:2) bitShift:8) + |
|
645 |
(self basicAt:1) |
|
646 |
||
647 |
" |
|
648 |
1.2345 hash |
|
649 |
1.2345 asShortFloat hash |
|
650 |
1.0 hash |
|
651 |
1.0 asShortFloat hash |
|
652 |
" |
|
653 |
! |
|
654 |
||
655 |
~= aNumber |
|
656 |
"return true, if the arguments value are not equal" |
|
657 |
||
658 |
%{ /* NOCONTEXT */ |
|
659 |
||
660 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 661 |
RETURN ( (__shortFloatVal(self) != (float)(__intVal(aNumber))) ? true : false ); |
1197 | 662 |
} |
663 |
if (__isFloatLike(aNumber)) { |
|
3158 | 664 |
RETURN ( (double)(__shortFloatVal(self) != __floatVal(aNumber)) ? true : false ); |
1197 | 665 |
} |
666 |
if (__isShortFloat(aNumber)) { |
|
3158 | 667 |
RETURN ( (__shortFloatVal(self) != __shortFloatVal(aNumber)) ? true : false ); |
1197 | 668 |
} |
669 |
%}. |
|
670 |
^ self retry:#~= coercing:aNumber |
|
671 |
||
672 |
! ! |
|
673 |
||
674 |
!ShortFloat methodsFor:'printing & storing'! |
|
675 |
||
676 |
printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
677 |
"return a printed representation of the receiver |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
678 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
679 |
#printOn: as basic print mechanism." |
1197 | 680 |
|
681 |
%{ /* NOCONTEXT */ |
|
682 |
||
683 |
char buffer[64]; |
|
684 |
REGISTER char *cp; |
|
685 |
OBJ s; |
|
686 |
||
687 |
/* |
|
688 |
* actually only needed on sparc: since thisContext is |
|
689 |
* in a global register, which gets destroyed by printf, |
|
690 |
* manually save it here - very stupid ... |
|
691 |
*/ |
|
692 |
__BEGIN_PROTECT_REGISTERS__ |
|
693 |
||
694 |
#ifdef SYSV |
|
695 |
sprintf(buffer, "%.6lg", (double)__shortFloatVal(self)); |
|
696 |
#else |
|
697 |
sprintf(buffer, "%.6G", (double)__shortFloatVal(self)); |
|
698 |
#endif |
|
699 |
||
700 |
__END_PROTECT_REGISTERS__ |
|
701 |
||
702 |
/* |
|
703 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
704 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
705 |
*/ |
|
706 |
for (cp = buffer; *cp; cp++) { |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
707 |
if ((*cp == '.') || (*cp == 'e')) break; |
1197 | 708 |
} |
709 |
if (! *cp) { |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
710 |
*cp++ = '.'; |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
711 |
*cp++ = '0'; |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
712 |
*cp = '\0'; |
1197 | 713 |
} |
714 |
||
715 |
s = __MKSTRING(buffer COMMA_SND); |
|
716 |
if (s != nil) { |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
717 |
RETURN (s); |
1197 | 718 |
} |
719 |
%}. |
|
720 |
" |
|
721 |
memory allocation (for the new string) failed. |
|
722 |
When we arrive here, there was no memory, even after a garbage collect. |
|
723 |
This means, that the VM wanted to get some more memory from the |
|
724 |
OS, which was not kind enough to give it. |
|
725 |
Bad luck - you should increase the swap space on your machine. |
|
726 |
" |
|
727 |
^ ObjectMemory allocationFailureSignal raise. |
|
728 |
! ! |
|
729 |
||
730 |
!ShortFloat methodsFor:'testing'! |
|
731 |
||
3147 | 732 |
isFinite |
733 |
"return true, if the receiver is a finite float |
|
734 |
i.e. not NaN and not infinite." |
|
735 |
||
736 |
%{ /* NOCONTEXT */ |
|
737 |
||
738 |
double dV = (double) __shortFloatVal(self); |
|
739 |
||
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
740 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
741 |
* notice: on machines which do not provide |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
742 |
* a finite() macro or function (WIN32), |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
743 |
* this may always return true here ... |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
744 |
*/ |
3147 | 745 |
if (finite(dV)) { RETURN (true); } |
746 |
%}. |
|
747 |
^false |
|
748 |
||
749 |
" |
|
750 |
1.0 asShortFloat isFinite |
|
751 |
(0.0 asShortFloat uncheckedDivide: 0.0) isFinite |
|
752 |
(1.0 asShortFloat uncheckedDivide: 0.0) isFinite |
|
753 |
" |
|
754 |
! |
|
755 |
||
2387 | 756 |
isNaN |
757 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
758 |
These are not created by ST/X float operations (they raise an exception); |
|
759 |
however, inline C-code could produce them ..." |
|
760 |
||
761 |
%{ /* NOCONTEXT */ |
|
762 |
||
3139 | 763 |
double dV = (double)(__shortFloatVal(self)); |
764 |
||
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
765 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
766 |
* notice: on machines which do not provide |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
767 |
* a finite() macro or function (WIN32), |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
768 |
* this may always return false here ... |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
769 |
*/ |
3147 | 770 |
if (isnan(dV)) { RETURN (true); } |
771 |
||
772 |
#if 0 /* Currently all our systems support isnan() |
|
773 |
* If not, you have to fix librun/jinterpret.c also. |
|
774 |
*/ |
|
775 |
||
2395 | 776 |
/* |
777 |
* sigh - every vendor is playing its own game here ... |
|
778 |
* Q: what are standards worth, anyway ? |
|
779 |
*/ |
|
3139 | 780 |
#ifdef IS_NAN |
781 |
if (IS_NAN(dV)) { RETURN (true); } |
|
782 |
RETURN (false); |
|
783 |
#endif |
|
784 |
||
2393 | 785 |
#ifdef IS_QNAN |
3139 | 786 |
if (IS_QNAN(dV)) { RETURN (true); } |
787 |
RETURN (false); |
|
2393 | 788 |
#endif |
2392 | 789 |
|
2393 | 790 |
#ifdef FLT_SNAN |
3139 | 791 |
if (dV == FLT_SNAN) { RETURN (true); } |
792 |
RETURN (false); |
|
2393 | 793 |
#endif |
3139 | 794 |
|
2393 | 795 |
#ifdef FLT_QNAN |
3139 | 796 |
if (dV == FLT_QNAN) { RETURN (true); } |
797 |
RETURN (false); |
|
2393 | 798 |
#endif |
799 |
||
800 |
#ifdef _SNANF |
|
3139 | 801 |
if (dV == _SNAN) { RETURN (true); } |
802 |
RETURN (false); |
|
2393 | 803 |
#endif |
3139 | 804 |
|
2393 | 805 |
#ifdef _QNANF |
3139 | 806 |
if (dV == _QNAN) { RETURN (true); } |
807 |
RETURN (false); |
|
2393 | 808 |
#endif |
2392 | 809 |
|
2395 | 810 |
#ifdef IsPosNAN |
3139 | 811 |
if IsPosNAN(dV) { RETURN (true); } |
812 |
RETURN (false); |
|
2395 | 813 |
#endif |
3139 | 814 |
|
2395 | 815 |
#ifdef IsNegNAN |
3139 | 816 |
if IsNegNAN(dV) { RETURN (true); } |
817 |
RETURN (false); |
|
2395 | 818 |
#endif |
819 |
||
2393 | 820 |
#ifdef NAN |
3139 | 821 |
if (dV == NAN) { RETURN (true); } |
822 |
RETURN (false); |
|
2400 | 823 |
#endif |
2389 | 824 |
|
3139 | 825 |
#ifdef NaN |
826 |
if (NaN(dV)) { RETURN (true); } |
|
827 |
RETURN (false); |
|
828 |
#endif |
|
3147 | 829 |
|
830 |
#endif /* 0 */ |
|
2392 | 831 |
%}. |
832 |
^ false |
|
2387 | 833 |
|
3147 | 834 |
" |
835 |
1.0 asShortFloat isNaN |
|
836 |
(0.0 asShortFloat uncheckedDivide: 0.0) isNaN |
|
837 |
" |
|
2387 | 838 |
! |
839 |
||
1197 | 840 |
negative |
841 |
"return true if the receiver is less than zero" |
|
842 |
||
843 |
%{ /* NOCONTEXT */ |
|
844 |
||
845 |
RETURN ( (__shortFloatVal(self) < 0.0) ? true : false ); |
|
846 |
%} |
|
847 |
! |
|
848 |
||
849 |
positive |
|
850 |
"return true if the receiver is greater or equal to zero" |
|
851 |
||
852 |
%{ /* NOCONTEXT */ |
|
853 |
||
854 |
RETURN ( (__shortFloatVal(self) >= 0.0) ? true : false ); |
|
855 |
%} |
|
1880 | 856 |
! |
857 |
||
858 |
strictlyPositive |
|
859 |
"return true if the receiver is greater than zero" |
|
860 |
||
861 |
%{ /* NOCONTEXT */ |
|
862 |
||
863 |
RETURN ( (__shortFloatVal(self) > 0.0) ? true : false ); |
|
864 |
%} |
|
1197 | 865 |
! ! |
866 |
||
1880 | 867 |
!ShortFloat class methodsFor:'documentation'! |
1197 | 868 |
|
869 |
version |
|
3473 | 870 |
^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.35 1998-05-21 11:48:46 cg Exp $' |
1197 | 871 |
! ! |