author | Claus Gittinger <cg@exept.de> |
Tue, 09 Jun 1998 13:29:19 +0200 | |
changeset 3529 | ec66f4fc9893 |
parent 3528 | bc45c489b1b2 |
child 3531 | 809c8e5745fe |
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)) { |
|
3528
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
322 |
if (aNumber != __MKSMALLINT(0)) { |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
323 |
result = __shortFloatVal(self) / (float)(__intVal(aNumber)); |
1197 | 324 |
retResult: |
3528
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
325 |
__qMKSFLOAT(newFloat, result); |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
326 |
RETURN ( newFloat ); |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
327 |
} |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
328 |
} else if (__isShortFloat(aNumber)) { |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
329 |
val = __shortFloatVal(aNumber); |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
330 |
if (val != 0.0) { |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
331 |
result = __shortFloatVal(self) / val; |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
332 |
goto retResult; |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
333 |
} |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
334 |
} else if (__isFloatLike(aNumber)) { |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
335 |
dVal = __floatVal(aNumber); |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
336 |
if (dVal != 0.0) { |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
337 |
dResult = (double) __shortFloatVal(self) / dVal; |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
338 |
__qMKFLOAT(newFloat, dResult); |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
339 |
RETURN ( newFloat ); |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
340 |
} |
1197 | 341 |
} |
342 |
%}. |
|
343 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
3528
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
344 |
" |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
345 |
No, you shalt not divide by zero |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
346 |
" |
bc45c489b1b2
oops - division by zero was not handled correctly
Claus Gittinger <cg@exept.de>
parents:
3473
diff
changeset
|
347 |
^ DivisionByZeroSignal raise. |
1197 | 348 |
]. |
349 |
^ aNumber quotientFromFloat:self |
|
350 |
||
351 |
! |
|
352 |
||
353 |
negated |
|
354 |
"return myself negated" |
|
355 |
||
356 |
%{ /* NOCONTEXT */ |
|
357 |
OBJ newFloat; |
|
358 |
float rslt = - __shortFloatVal(self); |
|
359 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
360 |
__qMKSFLOAT(newFloat, rslt); |
1197 | 361 |
RETURN ( newFloat ); |
362 |
%} |
|
363 |
||
3147 | 364 |
! |
365 |
||
366 |
uncheckedDivide:aNumber |
|
367 |
"return the quotient of the receiver and the argument, aNumber |
|
368 |
Do not check for divide by zero (return NaN or infinity)" |
|
369 |
||
370 |
%{ /* NOCONTEXT */ |
|
371 |
||
372 |
OBJ newFloat; |
|
373 |
float result, val; |
|
374 |
double dResult, dVal; |
|
375 |
||
376 |
if (__isSmallInteger(aNumber)) { |
|
377 |
result = __shortFloatVal(self) / (float)(__intVal(aNumber)); |
|
378 |
retResult: |
|
379 |
__qMKSFLOAT(newFloat, result); |
|
380 |
RETURN ( newFloat ); |
|
3529 | 381 |
} else if (__isShortFloat(aNumber)) { |
3147 | 382 |
val = __shortFloatVal(aNumber); |
383 |
result = __shortFloatVal(self) / val; |
|
384 |
goto retResult; |
|
3529 | 385 |
} else if (__isFloatLike(aNumber)) { |
3147 | 386 |
dVal = __floatVal(aNumber); |
387 |
dResult = (double) __shortFloatVal(self) / dVal; |
|
388 |
__qMKFLOAT(newFloat, dResult); |
|
389 |
RETURN ( newFloat ); |
|
390 |
} |
|
391 |
%}. |
|
392 |
^ aNumber quotientFromFloat:self |
|
393 |
||
394 |
" |
|
395 |
0.0 asShortFloat uncheckedDivide:0 |
|
396 |
1.0 asShortFloat uncheckedDivide:0.0 |
|
397 |
" |
|
398 |
||
1197 | 399 |
! ! |
400 |
||
401 |
!ShortFloat methodsFor:'coercion and converting'! |
|
402 |
||
3014 | 403 |
asDouble |
404 |
"ST80 compatibility - return a Float with same value as the receiver" |
|
405 |
||
406 |
^ self asFloat |
|
407 |
! |
|
408 |
||
1197 | 409 |
asFloat |
410 |
"return a Float with same value as the receiver" |
|
411 |
||
412 |
%{ /* NOCONTEXT */ |
|
413 |
||
414 |
OBJ newFloat; |
|
415 |
double dVal = (double)__shortFloatVal(self); |
|
416 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
417 |
__qMKFLOAT(newFloat, dVal); |
1197 | 418 |
RETURN ( newFloat ); |
419 |
%} |
|
420 |
||
421 |
" |
|
1583 | 422 |
1.0 asShortFloat asFloat |
1197 | 423 |
" |
424 |
! |
|
425 |
||
426 |
asInteger |
|
427 |
"return an integer with same value - might truncate" |
|
428 |
||
429 |
%{ /* NOCONTEXT */ |
|
1670 | 430 |
float fVal; |
1197 | 431 |
|
1670 | 432 |
fVal = __shortFloatVal(self); |
433 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
|
3158 | 434 |
RETURN ( __MKSMALLINT( (INT)fVal) ); |
1197 | 435 |
} |
436 |
%}. |
|
437 |
^ super asInteger |
|
438 |
||
439 |
" |
|
440 |
12345.0 asShortFloat asInteger |
|
441 |
1e15 asShortFloat asInteger |
|
442 |
" |
|
443 |
! |
|
444 |
||
445 |
asShortFloat |
|
446 |
"return a ShortFloat with same value as the receiver - thats me" |
|
447 |
||
448 |
^ self |
|
1200 | 449 |
! |
450 |
||
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
451 |
exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
452 |
"extract a normalized floats exponent. |
3473 | 453 |
The returned value depends on the float-representation of |
454 |
the underlying machine and is therefore highly unportable. |
|
455 |
This is not for general use. |
|
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
456 |
This assumes that the mantissa is normalized to |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
457 |
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
|
458 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
459 |
%{ /* NOCONTEXT */ |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
460 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
461 |
double frexp(); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
462 |
double frac; |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
463 |
INT pwr; |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
464 |
|
3471 | 465 |
errno = 0; |
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
466 |
frac = frexp( (double)(__shortFloatVal(self)), &pwr); |
3471 | 467 |
if (errno == 0) { |
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
468 |
if (pwr == 0) { |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
469 |
RETURN (__MKSMALLINT(0)); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
470 |
} |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
471 |
RETURN (__MKSMALLINT(pwr-1)); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
472 |
} |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
473 |
%}. |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
474 |
^ self primitiveFailed |
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 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
477 |
1.0 asShortFloat exponent |
3473 | 478 |
1.0 asShortFloat exponent |
3470
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
479 |
0.5 asShortFloat exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
480 |
0.25 asShortFloat exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
481 |
0.00000011111 asShortFloat exponent |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
482 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
483 |
! |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
484 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
485 |
fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
486 |
"extract a normalized floats mantissa. |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
487 |
This assumes that the mantissa is normalized to |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
488 |
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
|
489 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
490 |
%{ /* NOCONTEXT */ |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
491 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
492 |
double modf(); |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
493 |
double frac, trunc; |
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 |
errno = 0; |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
496 |
frac = modf((double)(__shortFloatVal(self)), &trunc); |
3471 | 497 |
if (errno == 0) { |
498 |
RETURN (__MKSFLOAT(frac)); |
|
3470
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 |
%}. |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
501 |
^ self primitiveFailed |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
502 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
503 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
504 |
1.0 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
505 |
0.5 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
506 |
0.25 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
507 |
3.14159 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
508 |
12345673.14159 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
509 |
123456731231231231.14159 asShortFloat fractionalPart |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
510 |
" |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
511 |
|
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
512 |
! |
fa7cda7fb45e
added exponent & fractionalPart
Claus Gittinger <cg@exept.de>
parents:
3429
diff
changeset
|
513 |
|
1200 | 514 |
generality |
515 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
516 |
||
517 |
^ 70 |
|
518 |
||
519 |
||
1197 | 520 |
! ! |
521 |
||
522 |
!ShortFloat methodsFor:'comparing'! |
|
523 |
||
524 |
< aNumber |
|
525 |
"return true, if the argument is greater" |
|
526 |
||
527 |
%{ /* NOCONTEXT */ |
|
528 |
||
529 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 530 |
RETURN ( (__shortFloatVal(self) < (float)(__intVal(aNumber))) ? true : false ); |
1197 | 531 |
} |
532 |
if (__isFloatLike(aNumber)) { |
|
3158 | 533 |
RETURN ( (double)(__shortFloatVal(self) < __floatVal(aNumber)) ? true : false ); |
1197 | 534 |
} |
535 |
if (__isShortFloat(aNumber)) { |
|
3158 | 536 |
RETURN ( (__shortFloatVal(self) < __shortFloatVal(aNumber)) ? true : false ); |
1197 | 537 |
} |
538 |
%}. |
|
539 |
^ aNumber lessFromShortFloat:self |
|
540 |
||
1200 | 541 |
" |
542 |
1.0 asShortFloat > (1/3) |
|
543 |
" |
|
1197 | 544 |
! |
545 |
||
546 |
<= aNumber |
|
547 |
"return true, if the argument is greater or equal" |
|
548 |
||
549 |
%{ /* NOCONTEXT */ |
|
550 |
||
551 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 552 |
RETURN ( (__shortFloatVal(self) <= (float)(__intVal(aNumber))) ? true : false ); |
1197 | 553 |
} |
554 |
if (__isFloatLike(aNumber)) { |
|
3158 | 555 |
RETURN ( (double)(__shortFloatVal(self) <= __floatVal(aNumber)) ? true : false ); |
1197 | 556 |
} |
557 |
if (__isShortFloat(aNumber)) { |
|
3158 | 558 |
RETURN ( (__shortFloatVal(self) <= __shortFloatVal(aNumber)) ? true : false ); |
1197 | 559 |
} |
560 |
%}. |
|
561 |
^ self retry:#<= coercing:aNumber |
|
562 |
||
563 |
! |
|
564 |
||
565 |
= aNumber |
|
566 |
"return true, if the arguments value are equal by value" |
|
567 |
||
568 |
%{ /* NOCONTEXT */ |
|
569 |
||
570 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 571 |
RETURN ( (__shortFloatVal(self) == (float)(__intVal(aNumber))) ? true : false ); |
1197 | 572 |
} |
573 |
if (__isFloatLike(aNumber)) { |
|
3158 | 574 |
RETURN ( (double)(__shortFloatVal(self) == __floatVal(aNumber)) ? true : false ); |
1197 | 575 |
} |
576 |
if (__isShortFloat(aNumber)) { |
|
3158 | 577 |
RETURN ( (__shortFloatVal(self) == __shortFloatVal(aNumber)) ? true : false ); |
1197 | 578 |
} |
579 |
%}. |
|
580 |
^ self retry:#= coercing:aNumber |
|
581 |
||
582 |
! |
|
583 |
||
584 |
> aNumber |
|
585 |
"return true, if the argument is less" |
|
586 |
||
587 |
%{ /* NOCONTEXT */ |
|
588 |
||
589 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 590 |
RETURN ( (__shortFloatVal(self) > (float)(__intVal(aNumber))) ? true : false ); |
1197 | 591 |
} |
592 |
if (__isFloatLike(aNumber)) { |
|
3158 | 593 |
RETURN ( (double)(__shortFloatVal(self) > __floatVal(aNumber)) ? true : false ); |
1197 | 594 |
} |
595 |
if (__isShortFloat(aNumber)) { |
|
3158 | 596 |
RETURN ( (__shortFloatVal(self) > __shortFloatVal(aNumber)) ? true : false ); |
1197 | 597 |
} |
598 |
%}. |
|
599 |
^ self retry:#> coercing:aNumber |
|
600 |
! |
|
601 |
||
602 |
>= aNumber |
|
603 |
"return true, if the argument is less or equal" |
|
604 |
||
605 |
%{ /* NOCONTEXT */ |
|
606 |
||
607 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 608 |
RETURN ( (__shortFloatVal(self) >= (float)(__intVal(aNumber))) ? true : false ); |
1197 | 609 |
} |
610 |
if (__isFloatLike(aNumber)) { |
|
3158 | 611 |
RETURN ( (double)(__shortFloatVal(self) >= __floatVal(aNumber)) ? true : false ); |
1197 | 612 |
} |
613 |
if (__isShortFloat(aNumber)) { |
|
3158 | 614 |
RETURN ( (__shortFloatVal(self) >= __shortFloatVal(aNumber)) ? true : false ); |
1197 | 615 |
} |
616 |
%}. |
|
617 |
^ self retry:#>= coercing:aNumber |
|
618 |
! |
|
619 |
||
620 |
hash |
|
621 |
"return a number for hashing; redefined, since floats compare |
|
622 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
623 |
as 3 hash." |
|
624 |
||
625 |
|i| |
|
626 |
||
627 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
3158 | 628 |
i := self asInteger. |
629 |
self = i ifTrue:[ |
|
630 |
^ i hash |
|
631 |
]. |
|
1197 | 632 |
]. |
633 |
||
634 |
" |
|
635 |
mhmh take some of my value-bits to hash on |
|
636 |
" |
|
637 |
^ (((self basicAt:4) bitAnd:16r3F) bitShift:24) + |
|
638 |
((self basicAt:3) bitShift:16) + |
|
639 |
((self basicAt:2) bitShift:8) + |
|
640 |
(self basicAt:1) |
|
641 |
||
642 |
" |
|
643 |
1.2345 hash |
|
644 |
1.2345 asShortFloat hash |
|
645 |
1.0 hash |
|
646 |
1.0 asShortFloat hash |
|
647 |
" |
|
648 |
! |
|
649 |
||
650 |
~= aNumber |
|
651 |
"return true, if the arguments value are not equal" |
|
652 |
||
653 |
%{ /* NOCONTEXT */ |
|
654 |
||
655 |
if (__isSmallInteger(aNumber)) { |
|
3158 | 656 |
RETURN ( (__shortFloatVal(self) != (float)(__intVal(aNumber))) ? true : false ); |
1197 | 657 |
} |
658 |
if (__isFloatLike(aNumber)) { |
|
3158 | 659 |
RETURN ( (double)(__shortFloatVal(self) != __floatVal(aNumber)) ? true : false ); |
1197 | 660 |
} |
661 |
if (__isShortFloat(aNumber)) { |
|
3158 | 662 |
RETURN ( (__shortFloatVal(self) != __shortFloatVal(aNumber)) ? true : false ); |
1197 | 663 |
} |
664 |
%}. |
|
665 |
^ self retry:#~= coercing:aNumber |
|
666 |
||
667 |
! ! |
|
668 |
||
669 |
!ShortFloat methodsFor:'printing & storing'! |
|
670 |
||
671 |
printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
672 |
"return a printed representation of the receiver |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
673 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
674 |
#printOn: as basic print mechanism." |
1197 | 675 |
|
676 |
%{ /* NOCONTEXT */ |
|
677 |
||
678 |
char buffer[64]; |
|
679 |
REGISTER char *cp; |
|
680 |
OBJ s; |
|
681 |
||
682 |
/* |
|
683 |
* actually only needed on sparc: since thisContext is |
|
684 |
* in a global register, which gets destroyed by printf, |
|
685 |
* manually save it here - very stupid ... |
|
686 |
*/ |
|
687 |
__BEGIN_PROTECT_REGISTERS__ |
|
688 |
||
689 |
#ifdef SYSV |
|
690 |
sprintf(buffer, "%.6lg", (double)__shortFloatVal(self)); |
|
691 |
#else |
|
692 |
sprintf(buffer, "%.6G", (double)__shortFloatVal(self)); |
|
693 |
#endif |
|
694 |
||
695 |
__END_PROTECT_REGISTERS__ |
|
696 |
||
697 |
/* |
|
698 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
|
699 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
|
700 |
*/ |
|
701 |
for (cp = buffer; *cp; cp++) { |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
702 |
if ((*cp == '.') || (*cp == 'e')) break; |
1197 | 703 |
} |
704 |
if (! *cp) { |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
705 |
*cp++ = '.'; |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
706 |
*cp++ = '0'; |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
707 |
*cp = '\0'; |
1197 | 708 |
} |
709 |
||
710 |
s = __MKSTRING(buffer COMMA_SND); |
|
711 |
if (s != nil) { |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
712 |
RETURN (s); |
1197 | 713 |
} |
714 |
%}. |
|
715 |
" |
|
716 |
memory allocation (for the new string) failed. |
|
717 |
When we arrive here, there was no memory, even after a garbage collect. |
|
718 |
This means, that the VM wanted to get some more memory from the |
|
719 |
OS, which was not kind enough to give it. |
|
720 |
Bad luck - you should increase the swap space on your machine. |
|
721 |
" |
|
722 |
^ ObjectMemory allocationFailureSignal raise. |
|
723 |
! ! |
|
724 |
||
725 |
!ShortFloat methodsFor:'testing'! |
|
726 |
||
3147 | 727 |
isFinite |
728 |
"return true, if the receiver is a finite float |
|
729 |
i.e. not NaN and not infinite." |
|
730 |
||
731 |
%{ /* NOCONTEXT */ |
|
732 |
||
733 |
double dV = (double) __shortFloatVal(self); |
|
734 |
||
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
735 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
736 |
* 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
|
737 |
* 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
|
738 |
* 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
|
739 |
*/ |
3147 | 740 |
if (finite(dV)) { RETURN (true); } |
741 |
%}. |
|
742 |
^false |
|
743 |
||
744 |
" |
|
745 |
1.0 asShortFloat isFinite |
|
746 |
(0.0 asShortFloat uncheckedDivide: 0.0) isFinite |
|
747 |
(1.0 asShortFloat uncheckedDivide: 0.0) isFinite |
|
748 |
" |
|
749 |
! |
|
750 |
||
2387 | 751 |
isNaN |
752 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
753 |
These are not created by ST/X float operations (they raise an exception); |
|
754 |
however, inline C-code could produce them ..." |
|
755 |
||
756 |
%{ /* NOCONTEXT */ |
|
757 |
||
3139 | 758 |
double dV = (double)(__shortFloatVal(self)); |
759 |
||
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
760 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
761 |
* 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
|
762 |
* 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
|
763 |
* 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
|
764 |
*/ |
3147 | 765 |
if (isnan(dV)) { RETURN (true); } |
766 |
||
767 |
#if 0 /* Currently all our systems support isnan() |
|
768 |
* If not, you have to fix librun/jinterpret.c also. |
|
769 |
*/ |
|
770 |
||
2395 | 771 |
/* |
772 |
* sigh - every vendor is playing its own game here ... |
|
773 |
* Q: what are standards worth, anyway ? |
|
774 |
*/ |
|
3139 | 775 |
#ifdef IS_NAN |
776 |
if (IS_NAN(dV)) { RETURN (true); } |
|
777 |
RETURN (false); |
|
778 |
#endif |
|
779 |
||
2393 | 780 |
#ifdef IS_QNAN |
3139 | 781 |
if (IS_QNAN(dV)) { RETURN (true); } |
782 |
RETURN (false); |
|
2393 | 783 |
#endif |
2392 | 784 |
|
2393 | 785 |
#ifdef FLT_SNAN |
3139 | 786 |
if (dV == FLT_SNAN) { RETURN (true); } |
787 |
RETURN (false); |
|
2393 | 788 |
#endif |
3139 | 789 |
|
2393 | 790 |
#ifdef FLT_QNAN |
3139 | 791 |
if (dV == FLT_QNAN) { RETURN (true); } |
792 |
RETURN (false); |
|
2393 | 793 |
#endif |
794 |
||
795 |
#ifdef _SNANF |
|
3139 | 796 |
if (dV == _SNAN) { RETURN (true); } |
797 |
RETURN (false); |
|
2393 | 798 |
#endif |
3139 | 799 |
|
2393 | 800 |
#ifdef _QNANF |
3139 | 801 |
if (dV == _QNAN) { RETURN (true); } |
802 |
RETURN (false); |
|
2393 | 803 |
#endif |
2392 | 804 |
|
2395 | 805 |
#ifdef IsPosNAN |
3139 | 806 |
if IsPosNAN(dV) { RETURN (true); } |
807 |
RETURN (false); |
|
2395 | 808 |
#endif |
3139 | 809 |
|
2395 | 810 |
#ifdef IsNegNAN |
3139 | 811 |
if IsNegNAN(dV) { RETURN (true); } |
812 |
RETURN (false); |
|
2395 | 813 |
#endif |
814 |
||
2393 | 815 |
#ifdef NAN |
3139 | 816 |
if (dV == NAN) { RETURN (true); } |
817 |
RETURN (false); |
|
2400 | 818 |
#endif |
2389 | 819 |
|
3139 | 820 |
#ifdef NaN |
821 |
if (NaN(dV)) { RETURN (true); } |
|
822 |
RETURN (false); |
|
823 |
#endif |
|
3147 | 824 |
|
825 |
#endif /* 0 */ |
|
2392 | 826 |
%}. |
827 |
^ false |
|
2387 | 828 |
|
3147 | 829 |
" |
830 |
1.0 asShortFloat isNaN |
|
831 |
(0.0 asShortFloat uncheckedDivide: 0.0) isNaN |
|
832 |
" |
|
2387 | 833 |
! |
834 |
||
1197 | 835 |
negative |
836 |
"return true if the receiver is less than zero" |
|
837 |
||
838 |
%{ /* NOCONTEXT */ |
|
839 |
||
840 |
RETURN ( (__shortFloatVal(self) < 0.0) ? true : false ); |
|
841 |
%} |
|
842 |
! |
|
843 |
||
844 |
positive |
|
845 |
"return true if the receiver is greater or equal to zero" |
|
846 |
||
847 |
%{ /* NOCONTEXT */ |
|
848 |
||
849 |
RETURN ( (__shortFloatVal(self) >= 0.0) ? true : false ); |
|
850 |
%} |
|
1880 | 851 |
! |
852 |
||
853 |
strictlyPositive |
|
854 |
"return true if the receiver is greater than zero" |
|
855 |
||
856 |
%{ /* NOCONTEXT */ |
|
857 |
||
858 |
RETURN ( (__shortFloatVal(self) > 0.0) ? true : false ); |
|
859 |
%} |
|
1197 | 860 |
! ! |
861 |
||
1880 | 862 |
!ShortFloat class methodsFor:'documentation'! |
1197 | 863 |
|
864 |
version |
|
3529 | 865 |
^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.37 1998-06-09 11:29:19 cg Exp $' |
1197 | 866 |
! ! |