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