author | Claus Gittinger <cg@exept.de> |
Fri, 17 Feb 2006 12:47:44 +0100 | |
changeset 9121 | 561e28aa22f9 |
parent 8984 | ddf3bff73452 |
child 9149 | 3fb15c4d83d8 |
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 |
||
5411 | 15 |
"{ Package: 'stx:libbasic' }" |
16 |
||
1197 | 17 |
LimitedPrecisionReal variableByteSubclass:#ShortFloat |
18 |
instanceVariableNames:'' |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
19 |
classVariableNames:'' |
1197 | 20 |
poolDictionaries:'' |
21 |
category:'Magnitude-Numbers' |
|
22 |
! |
|
23 |
||
2394 | 24 |
!ShortFloat primitiveDefinitions! |
25 |
%{ |
|
26 |
||
3471 | 27 |
#include <errno.h> |
28 |
||
29 |
#ifndef __OPTIMIZE__ |
|
30 |
# define __OPTIMIZE__ |
|
31 |
#endif |
|
4825 | 32 |
|
33 |
#define __USE_ISOC9X 1 |
|
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
34 |
#define __USE_ISOC99 1 |
3471 | 35 |
#include <math.h> |
36 |
||
37 |
/* |
|
38 |
* on some systems errno is a macro ... check for it here |
|
39 |
*/ |
|
40 |
#ifndef errno |
|
41 |
extern errno; |
|
42 |
#endif |
|
43 |
||
2394 | 44 |
#if defined (_AIX) |
45 |
# include <float.h> |
|
46 |
#endif |
|
4825 | 47 |
|
2395 | 48 |
#if defined(IRIX) |
49 |
# include <nan.h> |
|
50 |
#endif |
|
4825 | 51 |
|
2397 | 52 |
#if defined(LINUX) |
4825 | 53 |
# ifndef NAN |
5822
4e56f8aadda5
Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents:
5718
diff
changeset
|
54 |
# include <bits/nan.h> |
4825 | 55 |
# endif |
2397 | 56 |
#endif |
4825 | 57 |
|
2400 | 58 |
#if defined(solaris) || defined(sunos) |
2398 | 59 |
# include <nan.h> |
60 |
#endif |
|
2394 | 61 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
62 |
#ifdef WIN32 |
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 |
* no finite(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
65 |
* no isnan(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
66 |
*/ |
7419 | 67 |
# ifndef isnan |
68 |
# define isnan(x) \ |
|
69 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
70 |
(((unsigned int *)(&x))[1] == 0xFFF80000)) |
|
71 |
# endif |
|
72 |
||
73 |
# ifndef isPositiveInfinity |
|
74 |
# define isPositiveInfinity(x) \ |
|
75 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
76 |
(((unsigned int *)(&x))[1] == 0x7FF00000)) |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
77 |
# endif |
7419 | 78 |
|
79 |
# ifndef isNegativeInfinity |
|
80 |
# define isPositiveInfinity(x) \ |
|
81 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
82 |
(((unsigned int *)(&x))[1] == 0xFFF00000)) |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
83 |
# endif |
7419 | 84 |
|
85 |
# ifndef isinf |
|
86 |
# define isinf(x) \ |
|
87 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
88 |
((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000)) |
|
89 |
# endif |
|
90 |
||
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
91 |
# ifndef isfinite |
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
92 |
# define isfinite(x) (!isinf(x) && !isnan(x)) |
7419 | 93 |
# endif |
94 |
||
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
95 |
# ifndef isnanf |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
96 |
# define isnanf(x) \ |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
97 |
(((unsigned int *)(&x))[0] == 0xFFC00000) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
98 |
# endif |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
99 |
|
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
100 |
# ifndef isPositiveInfinityf |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
101 |
# define isPositiveInfinityf(x) \ |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
102 |
(((unsigned int *)(&x))[0] == 0x7F800000) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
103 |
# endif |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
104 |
|
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
105 |
# ifndef isNegativeInfinityf |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
106 |
# define isNegativeInfinityf(x) \ |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
107 |
(((unsigned int *)(&x))[0] == 0xFF800000) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
108 |
# endif |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
109 |
|
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
110 |
# ifndef isinff |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
111 |
# define isinff(x) \ |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
112 |
((((unsigned int *)(&x))[0] & 0x7FFFFFFF) == 0x7F800000) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
113 |
# endif |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
114 |
|
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
115 |
# ifndef isfinitef |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
116 |
# define isfinitef(x) (!isinff(x) && !isnanf(x)) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
117 |
# endif |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
118 |
|
7419 | 119 |
# define NO_ASINH |
120 |
# define NO_ACOSH |
|
121 |
# define NO_ATANH |
|
8706 | 122 |
#endif /* WIN32 */ |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
123 |
|
8984 | 124 |
#ifdef solaris |
125 |
# ifndef isfinite |
|
126 |
# define isfinite(f) finite((double)(f)) |
|
127 |
# endif |
|
128 |
#endif |
|
129 |
||
3414 | 130 |
#ifdef realIX |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
131 |
# ifndef isfinite |
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
132 |
# define isfinite(x) 1 |
3414 | 133 |
# endif |
8706 | 134 |
#endif /* realIX */ |
135 |
||
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
136 |
#ifndef isfinitef(x) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
137 |
# define isfinitef(x) isfinite(x) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
138 |
#endif |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
139 |
#ifndef isnanf(x) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
140 |
# define isnanf(x) isnan(x) |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
141 |
#endif |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
142 |
|
2394 | 143 |
%} |
144 |
! ! |
|
145 |
||
1880 | 146 |
!ShortFloat class methodsFor:'documentation'! |
1197 | 147 |
|
148 |
copyright |
|
149 |
" |
|
150 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3158 | 151 |
All Rights Reserved |
1197 | 152 |
|
153 |
This software is furnished under a license and may be used |
|
154 |
only in accordance with the terms of that license and with the |
|
155 |
inclusion of the above copyright notice. This software may not |
|
156 |
be provided or otherwise made available to, or used by, any |
|
157 |
other person. No title to or ownership of the software is |
|
158 |
hereby transferred. |
|
159 |
" |
|
160 |
||
161 |
||
162 |
! |
|
163 |
||
164 |
documentation |
|
165 |
" |
|
7380 | 166 |
ShortFloats represent rational numbers with limited precision. |
167 |
They use the C-compilers 'float' format, which is usually the IEE single float format. |
|
168 |
||
169 |
In contrast to Floats (which use the C-compilers 64bit 'double' format), |
|
170 |
ShortFloats give you 32 bit floats. |
|
1197 | 171 |
|
172 |
Notice, that ST/X Floats are what Doubles are in ST-80 and ShortFloats are |
|
173 |
ST-80's Floats respectively. |
|
174 |
This may change in one of the next versions (at least on machines, which |
|
175 |
provide different float and double types in their C-compiler. |
|
176 |
||
177 |
WARNING: |
|
7380 | 178 |
The layout of shortFloat instances is known by the runtime system and the compiler; |
179 |
you may not add instance variables here. |
|
180 |
Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats, |
|
181 |
and does some of its float-checks by an identity compare with the ShortFloat-class. |
|
182 |
(i.e. your subclasses instances may not be recognized as float-like objects, |
|
183 |
thus mixed mode arithmetic will always coerce them, effectively slowing things down). |
|
184 |
This may be changed, to use a flag bit in the class. |
|
1197 | 185 |
|
7380 | 186 |
Mixed mode arithmetic: |
187 |
shortFloat op shortFloat -> shortFloat |
|
188 |
shortFloat op fix -> shortFloat |
|
189 |
shortFloat op fraction -> shortFloat |
|
190 |
shortFloat op integer -> shortFloat |
|
191 |
shortFloat op longFloat -> longFloat |
|
192 |
shortFloat op float -> float |
|
193 |
shortFloat op complex -> complex |
|
1295 | 194 |
|
7405 | 195 |
Representation: |
196 |
32bit single precision IEE floats |
|
197 |
23 bit mantissa, |
|
198 |
8 bit exponent, |
|
199 |
6 decimal digits (approx) |
|
200 |
||
201 |
Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation |
|
202 |
||
1295 | 203 |
[author:] |
7380 | 204 |
Claus Gittinger |
1556 | 205 |
|
206 |
[see also:] |
|
7380 | 207 |
Number |
208 |
Float LongFloat Fraction FixedPoint Integer Complex |
|
209 |
FloatArray DoubleArray |
|
1197 | 210 |
" |
211 |
! ! |
|
212 |
||
1880 | 213 |
!ShortFloat class methodsFor:'instance creation'! |
1207 | 214 |
|
215 |
basicNew |
|
216 |
"return a new shortFloat - here we return 0.0 |
|
217 |
- shortFloats are usually NOT created this way ... |
|
218 |
Its implemented here to allow things like binary store & load |
|
219 |
of shortFloats. (but even this support will go away eventually, its not |
|
220 |
a good idea to store the bits of a float - the reader might have a |
|
221 |
totally different representation - so floats will eventually be |
|
222 |
binary stored in a device independent format." |
|
223 |
||
224 |
%{ /* NOCONTEXT */ |
|
225 |
OBJ newFloat; |
|
226 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
227 |
__qMKSFLOAT(newFloat, 0.0); |
1207 | 228 |
RETURN (newFloat); |
229 |
%} |
|
3158 | 230 |
! |
231 |
||
4297 | 232 |
fastFromString:aString at:startIndex |
233 |
"return the next ShortFloat from the string starting at startIndex. |
|
234 |
No spaces are skipped. |
|
235 |
||
236 |
This is a specially tuned entry (using a low-level C-call), which |
|
237 |
returns garbage if the argument string is not a valid float number. |
|
238 |
It has been added to allow higher speed string decomposition into |
|
239 |
numbers." |
|
240 |
%{ |
|
241 |
if (__isString(aString) && __isSmallInteger(startIndex)) { |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
242 |
char *cp = (char *)(__stringVal(aString)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
243 |
int idx = __intVal(startIndex) - 1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
244 |
double atof(); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
245 |
double val; |
4297 | 246 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
247 |
if ((unsigned)idx < __stringSize(aString)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
248 |
val = atof(cp + idx); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
249 |
RETURN (__MKSFLOAT(val)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
250 |
} |
4297 | 251 |
} |
252 |
%}. |
|
253 |
self primitiveFailed. |
|
254 |
||
255 |
" |
|
256 |
ShortFloat fastFromString:'123.45' at:1 |
|
257 |
ShortFloat fastFromString:'123.45' at:2 |
|
258 |
ShortFloat fastFromString:'123.45E4' at:1 |
|
259 |
ShortFloat fastFromString:'hello123.45E4' at:6 |
|
260 |
ShortFloat fastFromString:'12345' at:1 |
|
261 |
ShortFloat fastFromString:'12345' at:2 |
|
262 |
ShortFloat fastFromString:'12345' at:3 |
|
263 |
ShortFloat fastFromString:'12345' at:4 |
|
264 |
ShortFloat fastFromString:'12345' at:5 |
|
265 |
ShortFloat fastFromString:'12345' at:6 |
|
266 |
ShortFloat fastFromString:'12345' at:0 |
|
267 |
ShortFloat fastFromString:'hello123.45E4' at:1 |
|
268 |
||
269 |
Time millisecondsToRun:[ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
270 |
100000 timesRepeat:[ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
271 |
ShortFloat readFrom:'123.45' |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
272 |
] |
4297 | 273 |
] |
274 |
" |
|
275 |
||
276 |
" |
|
277 |
Time millisecondsToRun:[ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
278 |
100000 timesRepeat:[ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
279 |
ShortFloat fastFromString:'123.45' at:1 |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
280 |
] |
4297 | 281 |
] |
282 |
" |
|
283 |
||
284 |
||
285 |
||
286 |
! |
|
287 |
||
4637
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
288 |
readFrom:aStringOrStream |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
289 |
"read a shortFloat from a string" |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
290 |
|
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
291 |
|num| |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
292 |
|
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
293 |
num := super readFrom:aStringOrStream onError:[self error:'conversion error for: ' , self name]. |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
294 |
num notNil ifTrue:[ |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
295 |
num := num asShortFloat |
4637
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
296 |
]. |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
297 |
^ num |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
298 |
|
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
299 |
" |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
300 |
ShortFloat readFrom:'0.1' |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
301 |
ShortFloat readFrom:'0' |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
302 |
ShortFloat readFrom:'.123' |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
303 |
ShortFloat readFrom:'-.123' |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
304 |
ShortFloat readFrom:'1e4' |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
305 |
" |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
306 |
|
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
307 |
"Modified: / 7.1.1998 / 16:17:59 / cg" |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
308 |
! |
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
309 |
|
3158 | 310 |
readFrom:aStringOrStream onError:exceptionBlock |
311 |
"read a shortFloat from a string" |
|
312 |
||
313 |
|num| |
|
314 |
||
315 |
num := super readFrom:aStringOrStream onError:nil. |
|
316 |
num isNil ifTrue:[ |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
317 |
^ exceptionBlock value |
3158 | 318 |
]. |
319 |
^ num asShortFloat |
|
320 |
||
321 |
" |
|
322 |
ShortFloat readFrom:'0.1' |
|
323 |
ShortFloat readFrom:'0' |
|
4637
814b3d8e3f72
allow for degenerate float to be read
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
324 |
ShortFloat readFrom:'.123' |
3158 | 325 |
" |
326 |
||
327 |
"Modified: / 7.1.1998 / 16:17:59 / cg" |
|
1207 | 328 |
! ! |
329 |
||
7356 | 330 |
!ShortFloat class methodsFor:'binary storage'! |
331 |
||
332 |
readBinaryIEEESingleFrom:aStream |
|
333 |
"read a float value from the binary stream, aStream, |
|
334 |
interpreting the next bytes as an IEEE formatted 4-byte float" |
|
1197 | 335 |
|
7356 | 336 |
|f| |
1197 | 337 |
|
7356 | 338 |
f := ShortFloat basicNew. |
339 |
self readBinaryIEEESingleFrom:aStream into:f. |
|
340 |
^ f |
|
1197 | 341 |
|
7356 | 342 |
"Created: 16.4.1996 / 21:00:35 / cg" |
1197 | 343 |
! |
344 |
||
7356 | 345 |
readBinaryIEEESingleFrom:aStream into:aFloat |
346 |
"read a float value from the binary stream, aStream, |
|
347 |
interpreting the next bytes as an IEEE formatted 4-byte float" |
|
348 |
||
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
349 |
aFloat class == self ifFalse:[self error:'no a ShortFloat']. |
6574 | 350 |
|
7356 | 351 |
" |
352 |
this implementation is wrong: does not work on non-IEEE machines |
|
353 |
(to date all machines where ST/X is running on use |
|
354 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
355 |
" |
|
356 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
|
357 |
||
358 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
359 |
"swap the bytes" |
|
360 |
8 to:4 by:-1 do:[:i | |
|
361 |
aFloat basicAt:i put:(aStream next) |
|
362 |
]. |
|
363 |
^ self |
|
364 |
]. |
|
365 |
1 to:4 do:[:i | |
|
366 |
aFloat basicAt:i put:aStream next |
|
367 |
] |
|
6574 | 368 |
! |
369 |
||
7356 | 370 |
storeBinaryIEEESingle:aFloat on:aStream |
371 |
"store aFloat as an IEEE formatted 4-byte float |
|
372 |
onto the binary stream, aStream" |
|
373 |
||
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
374 |
|float| |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
375 |
|
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
376 |
float := aFloat asShortFloat. |
7356 | 377 |
|
378 |
" |
|
379 |
this implementation is wrong: does not work on non-IEEE machines |
|
380 |
(to date all machines where ST/X is running on use |
|
381 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
382 |
" |
|
383 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
|
6574 | 384 |
|
7356 | 385 |
UninterpretedBytes isBigEndian ifFalse:[ |
386 |
"swap the bytes" |
|
387 |
8 to:4 by:-1 do:[:i | |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
388 |
aStream nextPut:(float basicAt:i). |
7356 | 389 |
]. |
390 |
^ self |
|
391 |
]. |
|
392 |
1 to:4 do:[:i | |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
393 |
aStream nextPut:(float basicAt:i). |
7356 | 394 |
] |
395 |
! ! |
|
396 |
||
397 |
!ShortFloat class methodsFor:'constants'! |
|
6574 | 398 |
|
7392 | 399 |
e |
400 |
"return the constant e as ShortFloat" |
|
401 |
||
402 |
^ Float e asShortFloat |
|
403 |
! |
|
404 |
||
405 |
pi |
|
406 |
"return the constant pi as ShortFloat" |
|
407 |
||
408 |
^ Float pi asShortFloat |
|
409 |
! |
|
410 |
||
1197 | 411 |
unity |
1260 | 412 |
"return the neutral element for multiplication (1.0) as ShortFloat" |
1197 | 413 |
|
414 |
^ 1.0 asShortFloat |
|
415 |
||
1260 | 416 |
"Modified: 23.4.1996 / 09:26:51 / cg" |
1197 | 417 |
! |
418 |
||
419 |
zero |
|
1260 | 420 |
"return the neutral element for addition (0.0) as ShortFloat" |
1197 | 421 |
|
422 |
^ 0.0 asShortFloat |
|
423 |
||
1260 | 424 |
"Modified: 23.4.1996 / 09:26:45 / cg" |
1197 | 425 |
! ! |
426 |
||
1880 | 427 |
!ShortFloat class methodsFor:'queries'! |
1197 | 428 |
|
6898 | 429 |
exponentCharacter |
430 |
^ $e |
|
431 |
! |
|
432 |
||
1197 | 433 |
isBuiltInClass |
1264 | 434 |
"return true if this class is known by the run-time-system. |
435 |
Here, true is returned for myself, false for subclasses." |
|
1197 | 436 |
|
437 |
^ self == ShortFloat |
|
438 |
||
1264 | 439 |
"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
|
440 |
! |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
441 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
442 |
isIEEEFormat |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
443 |
"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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
machine). |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
448 |
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
|
449 |
(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
|
450 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
451 |
^ true "/ this may be a lie |
7356 | 452 |
! |
453 |
||
454 |
numBitsInExponent |
|
455 |
"answer the number of bits in the exponent |
|
456 |
This is an IEEE float, where 8 bits are available: |
|
457 |
seeeeeee emmmmmmm mmmmmmmm mmmmmmmm |
|
458 |
" |
|
459 |
||
460 |
^ 8 |
|
461 |
! |
|
462 |
||
463 |
numBitsInMantissa |
|
464 |
"answer the number of bits in the mantissa. |
|
465 |
This is an IEEE float, where 23 bits (the hidden one is not counted here) are available: |
|
466 |
seeeeeee emmmmmmm mmmmmmmm mmmmmmmm |
|
467 |
" |
|
468 |
||
469 |
^ 23 |
|
470 |
! |
|
471 |
||
472 |
precision |
|
473 |
"answer the precision of a ShortFloat (in bits) |
|
474 |
This is an IEEE float, only the fraction from the normalized mantissa is stored |
|
475 |
and so there is a hidden bit and the mantissa is actually represented by 24 binary digits" |
|
476 |
||
477 |
^ 24 |
|
478 |
! |
|
479 |
||
480 |
radix |
|
481 |
"answer the radix of a ShortFloats exponent |
|
482 |
This is an IEEE float, which is represented as binary" |
|
483 |
||
8635 | 484 |
^ 2 "must be careful here, whenever ST/X is used on VAX or a 370" |
1197 | 485 |
! ! |
486 |
||
487 |
!ShortFloat methodsFor:'arithmetic'! |
|
488 |
||
489 |
* aNumber |
|
490 |
"return the product of the receiver and the argument, aNumber" |
|
491 |
||
492 |
%{ /* NOCONTEXT */ |
|
493 |
||
494 |
OBJ newFloat; |
|
495 |
float result; |
|
496 |
double dResult; |
|
497 |
||
498 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 499 |
result = __shortFloatVal(self) * (float)(__intVal(aNumber)); |
1197 | 500 |
retResult: |
7356 | 501 |
__qMKSFLOAT(newFloat, result); |
502 |
RETURN ( newFloat ); |
|
503 |
} |
|
504 |
if (__isShortFloat(aNumber)) { |
|
505 |
result = __shortFloatVal(self) * __shortFloatVal(aNumber); |
|
506 |
goto retResult; |
|
507 |
} |
|
508 |
if (__isFloatLike(aNumber)) { |
|
509 |
dResult = (double) __shortFloatVal(self)* __floatVal(aNumber); |
|
510 |
__qMKFLOAT(newFloat, dResult); |
|
511 |
RETURN ( newFloat ); |
|
1197 | 512 |
} |
513 |
%}. |
|
514 |
^ aNumber productFromShortFloat:self |
|
515 |
! |
|
516 |
||
517 |
+ aNumber |
|
518 |
"return the sum of the receiver and the argument, aNumber" |
|
519 |
||
520 |
%{ /* NOCONTEXT */ |
|
521 |
||
522 |
OBJ newFloat; |
|
523 |
float result; |
|
524 |
double dResult; |
|
525 |
||
526 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 527 |
result = __shortFloatVal(self) + (float)(__intVal(aNumber)); |
1197 | 528 |
retResult: |
7356 | 529 |
__qMKSFLOAT(newFloat, result); |
530 |
RETURN ( newFloat ); |
|
531 |
} |
|
532 |
if (__isShortFloat(aNumber)) { |
|
533 |
result = __shortFloatVal(self) + __shortFloatVal(aNumber); |
|
534 |
goto retResult; |
|
535 |
} |
|
536 |
if (__isFloatLike(aNumber)) { |
|
537 |
dResult = (double) __shortFloatVal(self) + __floatVal(aNumber); |
|
538 |
__qMKFLOAT(newFloat, dResult); |
|
539 |
RETURN ( newFloat ); |
|
1197 | 540 |
} |
541 |
%}. |
|
542 |
^ aNumber sumFromShortFloat:self |
|
543 |
! |
|
544 |
||
545 |
- aNumber |
|
546 |
"return the difference of the receiver and the argument, aNumber" |
|
547 |
||
548 |
%{ /* NOCONTEXT */ |
|
549 |
||
550 |
OBJ newFloat; |
|
551 |
float result; |
|
552 |
double dResult; |
|
553 |
||
554 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 555 |
result = __shortFloatVal(self) - (float)(__intVal(aNumber)); |
1197 | 556 |
retResult: |
7356 | 557 |
__qMKSFLOAT(newFloat, result); |
558 |
RETURN ( newFloat ); |
|
559 |
} |
|
560 |
if (__isShortFloat(aNumber)) { |
|
561 |
result = __shortFloatVal(self) - __shortFloatVal(aNumber); |
|
562 |
goto retResult; |
|
563 |
} |
|
564 |
if (__isFloatLike(aNumber)) { |
|
565 |
dResult = (double) __shortFloatVal(self) - __floatVal(aNumber); |
|
566 |
__qMKFLOAT(newFloat, dResult); |
|
567 |
RETURN ( newFloat ); |
|
1197 | 568 |
} |
569 |
%}. |
|
570 |
^ aNumber differenceFromShortFloat:self |
|
571 |
! |
|
572 |
||
573 |
/ aNumber |
|
574 |
"return the quotient of the receiver and the argument, aNumber" |
|
575 |
||
576 |
%{ /* NOCONTEXT */ |
|
577 |
||
578 |
OBJ newFloat; |
|
579 |
float result, val; |
|
580 |
double dResult, dVal; |
|
581 |
||
582 |
if (__isSmallInteger(aNumber)) { |
|
8913 | 583 |
if (aNumber != __mkSmallInteger(0)) { |
5954 | 584 |
result = __shortFloatVal(self) / (float)(__intVal(aNumber)); |
1197 | 585 |
retResult: |
5954 | 586 |
__qMKSFLOAT(newFloat, result); |
587 |
RETURN ( newFloat ); |
|
588 |
} |
|
7356 | 589 |
} |
590 |
if (__isShortFloat(aNumber)) { |
|
5954 | 591 |
val = __shortFloatVal(aNumber); |
592 |
if (val != 0.0) { |
|
593 |
result = __shortFloatVal(self) / val; |
|
594 |
goto retResult; |
|
595 |
} |
|
7356 | 596 |
} |
597 |
if (__isFloatLike(aNumber)) { |
|
5954 | 598 |
dVal = __floatVal(aNumber); |
599 |
if (dVal != 0.0) { |
|
600 |
dResult = (double) __shortFloatVal(self) / dVal; |
|
601 |
__qMKFLOAT(newFloat, dResult); |
|
602 |
RETURN ( newFloat ); |
|
603 |
} |
|
1197 | 604 |
} |
605 |
%}. |
|
606 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
5954 | 607 |
" |
608 |
No, you shalt not divide by zero |
|
609 |
" |
|
7141
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
610 |
^ ZeroDivide raiseRequestWith:thisContext. |
1197 | 611 |
]. |
4166
5730ad6b744b
oops - from coercion in quotient / uncheckedQuotient
Claus Gittinger <cg@exept.de>
parents:
4100
diff
changeset
|
612 |
^ aNumber quotientFromShortFloat:self |
1197 | 613 |
! |
614 |
||
7725 | 615 |
abs |
616 |
"return the absolute value of the receiver |
|
617 |
reimplemented here for speed" |
|
618 |
||
619 |
%{ /* NOCONTEXT */ |
|
620 |
||
621 |
OBJ newFloat; |
|
622 |
float val = __shortFloatVal(self); |
|
623 |
||
624 |
if (val < 0.0) { |
|
625 |
__qMKSFLOAT(newFloat, -val); |
|
626 |
RETURN ( newFloat ); |
|
627 |
} |
|
628 |
RETURN (self); |
|
629 |
%}. |
|
630 |
||
631 |
" |
|
632 |
3.0 asShortFloat abs |
|
633 |
-3.0 asShortFloat abs |
|
634 |
" |
|
635 |
! |
|
636 |
||
1197 | 637 |
negated |
638 |
"return myself negated" |
|
639 |
||
640 |
%{ /* NOCONTEXT */ |
|
641 |
OBJ newFloat; |
|
642 |
float rslt = - __shortFloatVal(self); |
|
643 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
644 |
__qMKSFLOAT(newFloat, rslt); |
1197 | 645 |
RETURN ( newFloat ); |
5411 | 646 |
%}. |
647 |
^ 0.0 - self |
|
1197 | 648 |
|
3147 | 649 |
! |
650 |
||
651 |
uncheckedDivide:aNumber |
|
7356 | 652 |
"return the quotient of the receiver and the argument, aNumber. |
7471 | 653 |
Do not check for divide by zero (return NaN or Infinity). |
7356 | 654 |
This operation is provided for emulators of other languages/semantics, |
655 |
where no exception is raised for these results (i.e. Java). |
|
656 |
Its only defined if the arguments type is the same as the receivers." |
|
3147 | 657 |
|
658 |
%{ /* NOCONTEXT */ |
|
659 |
||
660 |
OBJ newFloat; |
|
661 |
float result, val; |
|
662 |
double dResult, dVal; |
|
663 |
||
664 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 665 |
result = __shortFloatVal(self) / (float)(__intVal(aNumber)); |
3147 | 666 |
retResult: |
7356 | 667 |
__qMKSFLOAT(newFloat, result); |
668 |
RETURN ( newFloat ); |
|
669 |
} |
|
670 |
if (__isShortFloat(aNumber)) { |
|
671 |
val = __shortFloatVal(aNumber); |
|
672 |
result = __shortFloatVal(self) / val; |
|
673 |
goto retResult; |
|
674 |
} |
|
675 |
if (__isFloatLike(aNumber)) { |
|
676 |
dVal = __floatVal(aNumber); |
|
677 |
dResult = (double) __shortFloatVal(self) / dVal; |
|
678 |
__qMKFLOAT(newFloat, dResult); |
|
679 |
RETURN ( newFloat ); |
|
3147 | 680 |
} |
681 |
%}. |
|
4166
5730ad6b744b
oops - from coercion in quotient / uncheckedQuotient
Claus Gittinger <cg@exept.de>
parents:
4100
diff
changeset
|
682 |
^ aNumber quotientFromShortFloat:self |
3147 | 683 |
|
684 |
" |
|
685 |
0.0 asShortFloat uncheckedDivide:0 |
|
686 |
1.0 asShortFloat uncheckedDivide:0.0 |
|
687 |
" |
|
1197 | 688 |
! ! |
689 |
||
5257 | 690 |
!ShortFloat methodsFor:'coercing & converting'! |
1197 | 691 |
|
692 |
asFloat |
|
693 |
"return a Float with same value as the receiver" |
|
694 |
||
695 |
%{ /* NOCONTEXT */ |
|
696 |
||
697 |
OBJ newFloat; |
|
698 |
double dVal = (double)__shortFloatVal(self); |
|
699 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
700 |
__qMKFLOAT(newFloat, dVal); |
1197 | 701 |
RETURN ( newFloat ); |
702 |
%} |
|
703 |
||
704 |
" |
|
1583 | 705 |
1.0 asShortFloat asFloat |
1197 | 706 |
" |
707 |
! |
|
708 |
||
709 |
asInteger |
|
710 |
"return an integer with same value - might truncate" |
|
711 |
||
712 |
%{ /* NOCONTEXT */ |
|
1670 | 713 |
float fVal; |
1197 | 714 |
|
1670 | 715 |
fVal = __shortFloatVal(self); |
7419 | 716 |
#ifdef WIN32 |
717 |
if (! isnanf(fVal)) |
|
718 |
#endif |
|
719 |
{ |
|
720 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
|
8913 | 721 |
RETURN ( __mkSmallInteger( (INT)fVal) ); |
7419 | 722 |
} |
1197 | 723 |
} |
724 |
%}. |
|
725 |
^ super asInteger |
|
726 |
||
727 |
" |
|
728 |
12345.0 asShortFloat asInteger |
|
729 |
1e15 asShortFloat asInteger |
|
730 |
" |
|
731 |
! |
|
732 |
||
7437
834ea4d6cdbc
oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents:
7419
diff
changeset
|
733 |
asLongFloat |
834ea4d6cdbc
oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents:
7419
diff
changeset
|
734 |
^ LongFloat fromShortFloat:self |
834ea4d6cdbc
oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents:
7419
diff
changeset
|
735 |
! |
834ea4d6cdbc
oops - printString of NaN/INF where wrong;
Claus Gittinger <cg@exept.de>
parents:
7419
diff
changeset
|
736 |
|
1197 | 737 |
asShortFloat |
738 |
"return a ShortFloat with same value as the receiver - thats me" |
|
739 |
||
740 |
^ self |
|
1200 | 741 |
! |
742 |
||
7356 | 743 |
coerce:aNumber |
744 |
"return aNumber converted into receivers type" |
|
745 |
||
746 |
^ aNumber asShortFloat |
|
747 |
! |
|
748 |
||
1200 | 749 |
generality |
750 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
751 |
||
752 |
^ 70 |
|
753 |
||
754 |
||
1197 | 755 |
! ! |
756 |
||
757 |
!ShortFloat methodsFor:'comparing'! |
|
758 |
||
759 |
< aNumber |
|
760 |
"return true, if the argument is greater" |
|
761 |
||
762 |
%{ /* NOCONTEXT */ |
|
763 |
||
764 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 765 |
RETURN ( (__shortFloatVal(self) < (float)(__intVal(aNumber))) ? true : false ); |
1197 | 766 |
} |
7356 | 767 |
if (aNumber != nil) { |
768 |
if (__qIsFloatLike(aNumber)) { |
|
769 |
RETURN ( (double)(__shortFloatVal(self) < __floatVal(aNumber)) ? true : false ); |
|
770 |
} |
|
771 |
if (__qIsShortFloat(aNumber)) { |
|
772 |
RETURN ( (__shortFloatVal(self) < __shortFloatVal(aNumber)) ? true : false ); |
|
773 |
} |
|
1197 | 774 |
} |
775 |
%}. |
|
776 |
^ aNumber lessFromShortFloat:self |
|
777 |
||
1200 | 778 |
" |
779 |
1.0 asShortFloat > (1/3) |
|
780 |
" |
|
1197 | 781 |
! |
782 |
||
783 |
<= aNumber |
|
784 |
"return true, if the argument is greater or equal" |
|
785 |
||
786 |
%{ /* NOCONTEXT */ |
|
787 |
||
788 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 789 |
RETURN ( (__shortFloatVal(self) <= (float)(__intVal(aNumber))) ? true : false ); |
1197 | 790 |
} |
7356 | 791 |
if (aNumber != nil) { |
792 |
if (__qIsFloatLike(aNumber)) { |
|
793 |
RETURN ( (double)(__shortFloatVal(self) <= __floatVal(aNumber)) ? true : false ); |
|
794 |
} |
|
795 |
if (__qIsShortFloat(aNumber)) { |
|
796 |
RETURN ( (__shortFloatVal(self) <= __shortFloatVal(aNumber)) ? true : false ); |
|
797 |
} |
|
798 |
} |
|
1197 | 799 |
%}. |
800 |
^ self retry:#<= coercing:aNumber |
|
801 |
! |
|
802 |
||
803 |
= aNumber |
|
7356 | 804 |
"return true, if the argument represents the same numeric value |
805 |
as the receiver, false otherwise" |
|
1197 | 806 |
|
807 |
%{ /* NOCONTEXT */ |
|
808 |
||
809 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 810 |
RETURN ( (__shortFloatVal(self) == (float)(__intVal(aNumber))) ? true : false ); |
811 |
} |
|
812 |
if (aNumber == nil) { |
|
813 |
RETURN (false); |
|
1197 | 814 |
} |
7356 | 815 |
if (__qIsFloatLike(aNumber)) { |
816 |
RETURN ( (double)(__shortFloatVal(self) == __floatVal(aNumber)) ? true : false ); |
|
1197 | 817 |
} |
7356 | 818 |
if (__qIsShortFloat(aNumber)) { |
819 |
RETURN ( (__shortFloatVal(self) == __shortFloatVal(aNumber)) ? true : false ); |
|
1197 | 820 |
} |
821 |
%}. |
|
7356 | 822 |
^ aNumber equalFromShortFloat:self |
1197 | 823 |
! |
824 |
||
825 |
> aNumber |
|
826 |
"return true, if the argument is less" |
|
827 |
||
828 |
%{ /* NOCONTEXT */ |
|
829 |
||
830 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 831 |
RETURN ( (__shortFloatVal(self) > (float)(__intVal(aNumber))) ? true : false ); |
1197 | 832 |
} |
7356 | 833 |
if (aNumber != nil) { |
834 |
if (__qIsFloatLike(aNumber)) { |
|
835 |
RETURN ( (double)(__shortFloatVal(self) > __floatVal(aNumber)) ? true : false ); |
|
836 |
} |
|
837 |
if (__qIsShortFloat(aNumber)) { |
|
838 |
RETURN ( (__shortFloatVal(self) > __shortFloatVal(aNumber)) ? true : false ); |
|
839 |
} |
|
1197 | 840 |
} |
841 |
%}. |
|
842 |
^ self retry:#> coercing:aNumber |
|
843 |
! |
|
844 |
||
845 |
>= aNumber |
|
846 |
"return true, if the argument is less or equal" |
|
847 |
||
848 |
%{ /* NOCONTEXT */ |
|
849 |
||
850 |
if (__isSmallInteger(aNumber)) { |
|
7356 | 851 |
RETURN ( (__shortFloatVal(self) >= (float)(__intVal(aNumber))) ? true : false ); |
1197 | 852 |
} |
7356 | 853 |
if (aNumber != nil) { |
854 |
if (__qIsFloatLike(aNumber)) { |
|
855 |
RETURN ( (double)(__shortFloatVal(self) >= __floatVal(aNumber)) ? true : false ); |
|
856 |
} |
|
857 |
if (__qIsShortFloat(aNumber)) { |
|
858 |
RETURN ( (__shortFloatVal(self) >= __shortFloatVal(aNumber)) ? true : false ); |
|
859 |
} |
|
1197 | 860 |
} |
861 |
%}. |
|
862 |
^ self retry:#>= coercing:aNumber |
|
863 |
! |
|
864 |
||
865 |
hash |
|
866 |
"return a number for hashing; redefined, since floats compare |
|
867 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
868 |
as 3 hash." |
1197 | 869 |
|
870 |
|i| |
|
871 |
||
872 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
873 |
i := self asInteger. |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
874 |
self = i ifTrue:[ |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
875 |
^ i hash |
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
876 |
]. |
1197 | 877 |
]. |
878 |
||
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
879 |
^ self asFloat hash |
1197 | 880 |
|
881 |
" |
|
882 |
1.2345 hash |
|
883 |
1.2345 asShortFloat hash |
|
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
884 |
1.0 hash |
1197 | 885 |
1.0 asShortFloat hash |
4593 | 886 |
0.5 asShortFloat hash |
887 |
0.25 asShortFloat hash |
|
4594
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
888 |
0.5 hash |
eb09f567a3bc
float, shortFloat and fraction all hash alike
Claus Gittinger <cg@exept.de>
parents:
4593
diff
changeset
|
889 |
0.25 hash |
1197 | 890 |
" |
891 |
! |
|
892 |
||
893 |
~= aNumber |
|
894 |
"return true, if the arguments value are not equal" |
|
895 |
||
896 |
%{ /* NOCONTEXT */ |
|
897 |
||
7356 | 898 |
if (aNumber != nil) { |
899 |
if (__isSmallInteger(aNumber)) { |
|
900 |
RETURN ( (__shortFloatVal(self) != (float)(__intVal(aNumber))) ? true : false ); |
|
901 |
} |
|
902 |
if (__qIsFloatLike(aNumber)) { |
|
903 |
RETURN ( (double)(__shortFloatVal(self) != __floatVal(aNumber)) ? true : false ); |
|
904 |
} |
|
905 |
if (__qIsShortFloat(aNumber)) { |
|
906 |
RETURN ( (__shortFloatVal(self) != __shortFloatVal(aNumber)) ? true : false ); |
|
907 |
} |
|
908 |
} else { |
|
909 |
RETURN ( true ); |
|
1197 | 910 |
} |
911 |
%}. |
|
7356 | 912 |
^ super ~= aNumber |
1197 | 913 |
! ! |
914 |
||
915 |
!ShortFloat methodsFor:'printing & storing'! |
|
916 |
||
917 |
printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
918 |
"return a printed representation of the receiver |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
919 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3158
diff
changeset
|
920 |
#printOn: as basic print mechanism." |
1197 | 921 |
|
922 |
%{ /* NOCONTEXT */ |
|
923 |
||
924 |
char buffer[64]; |
|
925 |
REGISTER char *cp; |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
926 |
int len; |
1197 | 927 |
OBJ s; |
928 |
||
929 |
/* |
|
930 |
* actually only needed on sparc: since thisContext is |
|
931 |
* in a global register, which gets destroyed by printf, |
|
932 |
* manually save it here - very stupid ... |
|
933 |
*/ |
|
934 |
__BEGIN_PROTECT_REGISTERS__ |
|
935 |
||
936 |
#ifdef SYSV |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
937 |
len = snprintf(buffer, sizeof(buffer), "%.6lg", (double)__shortFloatVal(self)); |
1197 | 938 |
#else |
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
939 |
len = snprintf(buffer, sizeof(buffer), "%.6G", (double)__shortFloatVal(self)); |
1197 | 940 |
#endif |
941 |
||
942 |
__END_PROTECT_REGISTERS__ |
|
943 |
||
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
944 |
if (len >= 0 && len <= sizeof(buffer)-3) { |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
945 |
/* |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
946 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
947 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
948 |
*/ |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
949 |
for (cp = buffer; *cp; cp++) { |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
950 |
if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
951 |
} |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
952 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
953 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
954 |
*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
955 |
} else { |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
956 |
*cp++ = '.'; |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
957 |
} |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
958 |
*cp++ = '0'; |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
959 |
*cp = '\0'; |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
960 |
} else { |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
961 |
if (cp && (*cp == '.')) { |
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
962 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
963 |
*cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
964 |
} |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
965 |
} |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
966 |
} |
1197 | 967 |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
968 |
s = __MKSTRING(buffer); |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
969 |
if (s != nil) { |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
970 |
RETURN (s); |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
971 |
} |
1197 | 972 |
} |
973 |
%}. |
|
5432 | 974 |
^ self asFloat printString |
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
975 |
|
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
976 |
" |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
977 |
1.234 asShortFloat printString. |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
978 |
1.0 asShortFloat printString. |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
979 |
1e10 asShortFloat printString. |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
980 |
1.2e3 asShortFloat printString. |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
981 |
1.2e30 asShortFloat printString. |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
982 |
(1.0 uncheckedDivide:0) asShortFloat printString. |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
983 |
(0.0 uncheckedDivide:0) asShortFloat printString. |
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
984 |
|
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
985 |
DecimalPointCharacterForPrinting := $,. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
986 |
1.234 asShortFloat printString. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
987 |
1.0 asShortFloat printString. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
988 |
1e10 asShortFloat printString. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
989 |
1.2e3 asShortFloat printString. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
990 |
1.2e30 asShortFloat printString. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
991 |
(1.0 uncheckedDivide:0) asShortFloat printString. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
992 |
(0.0 uncheckedDivide:0) asShortFloat printString. |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
993 |
DecimalPointCharacterForPrinting := $. |
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
994 |
" |
5718 | 995 |
! |
996 |
||
997 |
printfPrintString:formatString |
|
7746 | 998 |
"non-standard: return a printed representation of the receiver |
5718 | 999 |
as specified by formatString, which is defined by printf. |
1000 |
If you use this, be aware, that specifying doubles differs on |
|
1001 |
systems; on SYSV machines you have to give something like %lf, |
|
1002 |
while on BSD systems the format string has to be %F. |
|
1003 |
Also, the resulting string may not be longer than 255 bytes - |
|
1004 |
since thats the (static) size of the buffer. |
|
1005 |
This method is NONSTANDARD and may be removed without notice." |
|
1006 |
||
1007 |
%{ /* STACK: 400 */ |
|
1008 |
char buffer[256]; |
|
1009 |
OBJ s; |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1010 |
int len; |
5718 | 1011 |
|
1012 |
if (__isString(formatString)) { |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1013 |
/* |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1014 |
* actually only needed on sparc: since thisContext is |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1015 |
* in a global register, which gets destroyed by printf, |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1016 |
* manually save it here - very stupid ... |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1017 |
*/ |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1018 |
__BEGIN_PROTECT_REGISTERS__ |
5718 | 1019 |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1020 |
len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __shortFloatVal(self)); |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1021 |
|
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1022 |
__END_PROTECT_REGISTERS__ |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1023 |
|
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1024 |
if (len < 0) goto fail; |
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1025 |
|
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1026 |
s = __MKSTRING_L(buffer, len); |
5718 | 1027 |
if (s != nil) { |
1028 |
RETURN (s); |
|
1029 |
} |
|
1030 |
} |
|
8418
37ccc74bbf9e
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
7746
diff
changeset
|
1031 |
fail: ; |
5718 | 1032 |
%}. |
1033 |
self primitiveFailed |
|
1034 |
||
1035 |
"ShortFloat pi printfPrintString:'%%lg -> %lg'" |
|
1036 |
"ShortFloat pi printfPrintString:'%%lf -> %lf'" |
|
1037 |
"ShortFloat pi printfPrintString:'%%7.5lg -> %7.5lg'" |
|
1038 |
"ShortFloat pi printfPrintString:'%%G -> %G'" |
|
1039 |
"ShortFloat pi printfPrintString:'%%F -> %F'" |
|
1040 |
"ShortFloat pi printfPrintString:'%%7.5G -> %7.5G'" |
|
1041 |
"ShortFloat pi printfPrintString:'%%7.5F -> %7.5F'" |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1042 |
! |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1043 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1044 |
storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1045 |
"return a printed representation of the receiver; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1046 |
all valid digits are printed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1047 |
LimitedPrecisonReal and its subclasses use #storeString instead of |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1048 |
#storeOn: as basic print mechanism." |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1049 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1050 |
%{ /* NOCONTEXT */ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1051 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1052 |
char buffer[64]; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1053 |
REGISTER char *cp; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1054 |
OBJ s; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1055 |
int len; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1056 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1057 |
/* |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1058 |
* build a printf format string |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1059 |
*/ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1060 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1061 |
__BEGIN_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1062 |
#ifdef SYSV |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1063 |
len = snprintf(buffer, sizeof(buffer), "%.6lg", (double)__shortFloatVal(self)); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1064 |
#else |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1065 |
len = snprintf(buffer, sizeof(buffer), "%.6G", (double)__shortFloatVal(self)); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1066 |
#endif |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1067 |
__END_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1068 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1069 |
if (len >= 0 && len < sizeof(buffer)-3) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1070 |
/* |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1071 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1072 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1073 |
*/ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1074 |
for (cp = buffer; *cp; cp++) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1075 |
if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1076 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1077 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1078 |
*cp++ = '.'; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1079 |
*cp++ = '0'; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1080 |
*cp = '\0'; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1081 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1082 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1083 |
s = __MKSTRING(buffer); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1084 |
if (s != nil) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1085 |
RETURN (s); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1086 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1087 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1088 |
%}. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1089 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1090 |
memory allocation (for the new string) failed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1091 |
When we arrive here, there was no memory, even after a garbage collect. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1092 |
This means, that the VM wanted to get some more memory from the |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1093 |
OS, which was not kind enough to give it. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1094 |
Bad luck - you should increase the swap space on your machine. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1095 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1096 |
^ ObjectMemory allocationFailureSignal raise. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1097 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1098 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1099 |
1.0 asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1100 |
1.234 asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1101 |
1e10 asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1102 |
1.2e3 asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1103 |
1.2e30 asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1104 |
Float pi asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1105 |
(1.0 uncheckedDivide:0) asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1106 |
(0.0 uncheckedDivide:0) asShortFloat storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1107 |
|
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1108 |
notice that the storeString is NOT affected by DecimalPointCharacterForPrinting: |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1109 |
|
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1110 |
DecimalPointCharacterForPrinting := $,. |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1111 |
1.234 asShortFloat storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1112 |
1.0 asShortFloat storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1113 |
1e10 asShortFloat storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1114 |
1.2e3 asShortFloat storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1115 |
1.2e30 asShortFloat storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1116 |
(1.0 uncheckedDivide:0) asShortFloat storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1117 |
(0.0 uncheckedDivide:0) asShortFloat storeString. |
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1118 |
DecimalPointCharacterForPrinting := $. |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8418
diff
changeset
|
1119 |
" |
1197 | 1120 |
! ! |
1121 |
||
3897 | 1122 |
!ShortFloat methodsFor:'special access'! |
1123 |
||
1124 |
exponent |
|
1125 |
"extract a normalized floats exponent. |
|
1126 |
The returned value depends on the float-representation of |
|
1127 |
the underlying machine and is therefore highly unportable. |
|
1128 |
This is not for general use. |
|
1129 |
This assumes that the mantissa is normalized to |
|
1130 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1131 |
||
1132 |
%{ /* NOCONTEXT */ |
|
1133 |
||
1134 |
double frexp(); |
|
8913 | 1135 |
int exp; |
3897 | 1136 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1137 |
__threadErrno = 0; |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1138 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1139 |
frexpf( __shortFloatVal(self), &exp); |
1140 |
#else |
|
1141 |
frexp( (double)(__shortFloatVal(self)), &exp); |
|
1142 |
#endif |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1143 |
if (__threadErrno == 0) { |
8913 | 1144 |
RETURN (__mkSmallInteger(exp)); |
3897 | 1145 |
} |
1146 |
%}. |
|
7387 | 1147 |
^ super exponent |
3897 | 1148 |
|
1149 |
" |
|
7356 | 1150 |
4.0 asShortFloat exponent |
1151 |
2.0 asShortFloat exponent |
|
3897 | 1152 |
1.0 asShortFloat exponent |
1153 |
0.5 asShortFloat exponent |
|
1154 |
0.25 asShortFloat exponent |
|
1155 |
0.00000011111 asShortFloat exponent |
|
1156 |
" |
|
1157 |
! |
|
1158 |
||
1159 |
mantissa |
|
1160 |
"extract a normalized floats mantissa. |
|
1161 |
The returned value depends on the float-representation of |
|
1162 |
the underlying machine and is therefore highly unportable. |
|
1163 |
This is not for general use. |
|
1164 |
This assumes that the mantissa is normalized to |
|
1165 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1166 |
||
1167 |
%{ /* NOCONTEXT */ |
|
8913 | 1168 |
int exp; |
3897 | 1169 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1170 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1171 |
float frac; |
1172 |
||
1173 |
__threadErrno = 0; |
|
1174 |
frac = frexpf( (double)__shortFloatVal(self), &exp); |
|
1175 |
if (__threadErrno == 0) { |
|
1176 |
RETURN (__MKSFLOAT(frac)); |
|
1177 |
} |
|
1178 |
#else |
|
3897 | 1179 |
double frexp(); |
1180 |
double frac; |
|
1181 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1182 |
__threadErrno = 0; |
3897 | 1183 |
frac = frexp( (double)(__shortFloatVal(self)), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1184 |
if (__threadErrno == 0) { |
7356 | 1185 |
RETURN (__MKFLOAT(frac)); |
3897 | 1186 |
} |
7356 | 1187 |
#endif |
3897 | 1188 |
%}. |
1189 |
^ self primitiveFailed |
|
1190 |
||
1191 |
" |
|
1192 |
1.0 asShortFloat exponent |
|
1193 |
1.0 asShortFloat mantissa |
|
1194 |
||
1195 |
0.5 asShortFloat exponent |
|
1196 |
0.5 asShortFloat mantissa |
|
1197 |
||
1198 |
0.25 asShortFloat exponent |
|
1199 |
0.25 asShortFloat mantissa |
|
1200 |
||
1201 |
0.00000011111 asShortFloat exponent |
|
1202 |
0.00000011111 asShortFloat mantissa |
|
1203 |
" |
|
1204 |
! ! |
|
1205 |
||
1197 | 1206 |
!ShortFloat methodsFor:'testing'! |
1207 |
||
3147 | 1208 |
isFinite |
1209 |
"return true, if the receiver is a finite float |
|
1210 |
i.e. not NaN and not infinite." |
|
1211 |
||
1212 |
%{ /* NOCONTEXT */ |
|
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1213 |
float fV = __shortFloatVal(self); |
3147 | 1214 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1215 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1216 |
* notice: on machines which do not provide |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1217 |
* a isfinite() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
1218 |
* this may always ret true here ... |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1219 |
*/ |
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1220 |
if (isfinitef(fV)) { RETURN (true); } |
3147 | 1221 |
%}. |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1222 |
^ false |
3147 | 1223 |
|
1224 |
" |
|
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1225 |
1.0 asShortFloat isFinite |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1226 |
(0.0 asShortFloat uncheckedDivide: 0.0) isFinite |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1227 |
(1.0 asShortFloat uncheckedDivide: 0.0) isFinite |
3147 | 1228 |
" |
1229 |
! |
|
1230 |
||
2387 | 1231 |
isNaN |
1232 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
1233 |
These are not created by ST/X float operations (they raise an exception); |
|
1234 |
however, inline C-code could produce them ..." |
|
1235 |
||
1236 |
%{ /* NOCONTEXT */ |
|
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1237 |
float sV = __shortFloatVal(self); |
3139 | 1238 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1239 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1240 |
* notice: on machines which do not provide |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1241 |
* a isnan() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4297
diff
changeset
|
1242 |
* this may always ret false here ... |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1243 |
*/ |
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1244 |
if (isnanf(sV)) { RETURN (true); } |
2392 | 1245 |
%}. |
1246 |
^ false |
|
2387 | 1247 |
|
3147 | 1248 |
" |
7356 | 1249 |
1.0 asShortFloat isNaN |
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1250 |
(0.0 asShortFloat uncheckedDivide: 0.0) isNaN |
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1251 |
(0.0 asShortFloat uncheckedDivide: 0.0 asShortFloat) isNaN |
3147 | 1252 |
" |
2387 | 1253 |
! |
1254 |
||
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1255 |
isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1256 |
"many systems have two float.Pnt zeros" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1257 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1258 |
%{ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1259 |
#if defined(__i386__) && defined(linux) |
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1260 |
RETURN ((__ByteArrayInstPtr(self)->ba_element[sizeof(float)-1] == 128) ? true : false ); |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1261 |
#endif |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1262 |
%}. |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1263 |
^ super isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1264 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1265 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1266 |
0.0 asShortFloat isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1267 |
-0.0 asShortFloat isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1268 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1269 |
! |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6574
diff
changeset
|
1270 |
|
1197 | 1271 |
negative |
1272 |
"return true if the receiver is less than zero" |
|
1273 |
||
1274 |
%{ /* NOCONTEXT */ |
|
1275 |
||
1276 |
RETURN ( (__shortFloatVal(self) < 0.0) ? true : false ); |
|
5411 | 1277 |
%}. |
1197 | 1278 |
! |
1279 |
||
5357 | 1280 |
numberOfBits |
1281 |
"return the size (in bits) of the real; |
|
1282 |
typically, 32 is returned here, |
|
1283 |
but who knows ..." |
|
1284 |
||
1285 |
%{ /* NOCONTEXT */ |
|
1286 |
||
8913 | 1287 |
RETURN (__mkSmallInteger (sizeof(float) * 8)); |
5357 | 1288 |
%} |
1289 |
||
1290 |
" |
|
1291 |
1.2 numberOfBits |
|
1292 |
1.2 asShortFloat numberOfBits |
|
1293 |
" |
|
1294 |
||
1295 |
! |
|
1296 |
||
1197 | 1297 |
positive |
1298 |
"return true if the receiver is greater or equal to zero" |
|
1299 |
||
1300 |
%{ /* NOCONTEXT */ |
|
1301 |
||
1302 |
RETURN ( (__shortFloatVal(self) >= 0.0) ? true : false ); |
|
1303 |
%} |
|
1880 | 1304 |
! |
1305 |
||
1306 |
strictlyPositive |
|
1307 |
"return true if the receiver is greater than zero" |
|
1308 |
||
1309 |
%{ /* NOCONTEXT */ |
|
1310 |
||
1311 |
RETURN ( (__shortFloatVal(self) > 0.0) ? true : false ); |
|
1312 |
%} |
|
1197 | 1313 |
! ! |
1314 |
||
5552 | 1315 |
!ShortFloat methodsFor:'truncation & rounding'! |
3897 | 1316 |
|
7356 | 1317 |
ceiling |
1318 |
"return the smallest integer which is greater or equal to the receiver." |
|
1319 |
||
1320 |
|val| |
|
1321 |
||
1322 |
%{ |
|
1323 |
float fVal; |
|
1324 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1325 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1326 |
fVal = ceilf(__shortFloatVal(self)); |
1327 |
#else |
|
1328 |
fVal = (float)(ceil((double)__shortFloatVal(self))); |
|
1329 |
#endif |
|
1330 |
/* |
|
1331 |
* ST-80 (and X3J20) returns integer. |
|
1332 |
*/ |
|
1333 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
|
8913 | 1334 |
RETURN ( __mkSmallInteger( (INT) fVal ) ); |
7356 | 1335 |
} |
1336 |
__qMKSFLOAT(val, fVal); |
|
1337 |
%}. |
|
1338 |
^ val asInteger |
|
1339 |
||
1340 |
" |
|
1341 |
0.5 asShortFloat ceiling |
|
1342 |
-0.5 asShortFloat ceiling |
|
1343 |
" |
|
1344 |
! |
|
1345 |
||
1346 |
ceilingAsFloat |
|
1347 |
"return the smallest integer-valued float greater or equal to the receiver. |
|
1348 |
This is much like #ceiling, but avoids a (possibly expensive) conversion |
|
1349 |
of the result to an integer. |
|
1350 |
It may be useful, if the result is to be further used in another float-operation." |
|
1351 |
||
1352 |
%{ /* NOCONTEXT */ |
|
1353 |
float fVal; |
|
1354 |
OBJ v; |
|
1355 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1356 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1357 |
fVal = ceilf(__shortFloatVal(self)); |
1358 |
#else |
|
1359 |
fVal = (float) ceil((double)__shortFloatVal(self)); |
|
1360 |
#endif |
|
1361 |
__qMKSFLOAT(v, fVal); |
|
1362 |
RETURN (v); |
|
1363 |
%} |
|
1364 |
" |
|
1365 |
0.5 asShortFloat ceilingAsFloat |
|
1366 |
-0.5 asShortFloat ceilingAsFloat |
|
1367 |
-1.5 asShortFloat ceilingAsFloat |
|
1368 |
" |
|
1369 |
! |
|
1370 |
||
4100
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1371 |
floor |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1372 |
"return the integer nearest the receiver towards negative infinity." |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1373 |
|
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1374 |
|val| |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1375 |
|
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1376 |
%{ |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1377 |
float fVal; |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1378 |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1379 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1380 |
fVal = floorf(__shortFloatVal(self)); |
1381 |
#else |
|
1382 |
fVal = (float)(floor((double)__shortFloatVal(self))); |
|
1383 |
#endif |
|
4100
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1384 |
/* |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1385 |
* ST-80 (and X3J20) returns integer. |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1386 |
*/ |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1387 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
8913 | 1388 |
RETURN ( __mkSmallInteger( (INT) fVal ) ); |
4100
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1389 |
} |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1390 |
__qMKSFLOAT(val, fVal); |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1391 |
%}. |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1392 |
^ val asInteger |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1393 |
|
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1394 |
" |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1395 |
0.5 asShortFloat floor |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1396 |
-0.5 asShortFloat floor |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1397 |
" |
7356 | 1398 |
! |
4100
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1399 |
|
7356 | 1400 |
floorAsFloat |
1401 |
"return the float which represents the next lower |
|
1402 |
integer nearest the receiver towards negative infinity. |
|
1403 |
Much like floor, but returns a float result - useful if the result |
|
1404 |
will be used in another float operation, to avoid costy int-conversion." |
|
4100
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1405 |
|
7356 | 1406 |
%{ /* NOCONTEXT */ |
1407 |
float fVal; |
|
1408 |
OBJ v; |
|
1409 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1410 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1411 |
fVal = floorf(__shortFloatVal(self)); |
1412 |
#else |
|
1413 |
fVal = (float)(floor((double)__shortFloatVal(self))); |
|
1414 |
#endif |
|
1415 |
__qMKSFLOAT(v, fVal); |
|
1416 |
RETURN ( v ); |
|
1417 |
%} |
|
1418 |
||
1419 |
" |
|
1420 |
0.5 asShortFloat floorAsFloat |
|
1421 |
-0.5 asShortFloat floorAsFloat |
|
1422 |
" |
|
4100
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1423 |
! |
a605c54bf9a9
fixed floor (endless recursion)
Claus Gittinger <cg@exept.de>
parents:
3983
diff
changeset
|
1424 |
|
3897 | 1425 |
fractionPart |
1426 |
"extract the after-decimal fraction part. |
|
7356 | 1427 |
such that (self truncated + self fractionPart) = self" |
3897 | 1428 |
|
1429 |
%{ /* NOCONTEXT */ |
|
1430 |
||
1431 |
double modf(); |
|
1432 |
double frac, trunc; |
|
1433 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1434 |
__threadErrno = 0; |
3897 | 1435 |
frac = modf((double)(__shortFloatVal(self)), &trunc); |
7403 | 1436 |
if (! isnan(frac)) { |
1437 |
if (__threadErrno == 0) { |
|
1438 |
RETURN (__MKSFLOAT((float)frac)); |
|
1439 |
} |
|
3897 | 1440 |
} |
1441 |
%}. |
|
7403 | 1442 |
^ self class |
1443 |
raise:#domainErrorSignal |
|
1444 |
receiver:self |
|
1445 |
selector:#fractionPart |
|
1446 |
arguments:#() |
|
1447 |
errorString:'bad receiver in fractionPart' |
|
3897 | 1448 |
|
1449 |
" |
|
7356 | 1450 |
1.6 asShortFloat fractionPart + 1.6 asShortFloat truncated |
1451 |
-1.6 asShortFloat fractionPart + -1.6 asShortFloat truncated |
|
1452 |
||
3897 | 1453 |
1.0 asShortFloat fractionalPart |
1454 |
0.5 asShortFloat fractionalPart |
|
1455 |
0.25 asShortFloat fractionalPart |
|
1456 |
3.14159 asShortFloat fractionalPart |
|
1457 |
12345673.14159 asShortFloat fractionalPart |
|
1458 |
123456731231231231.14159 asShortFloat fractionalPart |
|
1459 |
" |
|
7356 | 1460 |
! |
3897 | 1461 |
|
7356 | 1462 |
rounded |
1463 |
"return the receiver rounded to the nearest integer" |
|
1464 |
||
1465 |
|val| |
|
1466 |
||
1467 |
%{ |
|
1468 |
float fVal; |
|
1469 |
||
1470 |
fVal = __shortFloatVal(self); |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1471 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1472 |
if (fVal < 0.0) { |
1473 |
fVal = ceilf(fVal - (float)0.5); |
|
1474 |
} else { |
|
1475 |
fVal = floorf(fVal + (float)0.5); |
|
1476 |
} |
|
1477 |
#else |
|
1478 |
if (fVal < 0.0) { |
|
1479 |
fVal = (float)ceil((double)fVal - 0.5); |
|
1480 |
} else { |
|
1481 |
fVal = (float)floor((double)fVal + 0.5); |
|
1482 |
} |
|
1483 |
#endif |
|
1484 |
/* |
|
1485 |
* ST-80 (and X3J20) returns integer. |
|
1486 |
*/ |
|
1487 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
|
8913 | 1488 |
RETURN ( __mkSmallInteger( (INT) fVal ) ); |
7356 | 1489 |
} |
1490 |
__qMKSFLOAT(val, fVal); |
|
1491 |
%}. |
|
1492 |
^ val asInteger |
|
1493 |
||
1494 |
" |
|
1495 |
0.4 asShortFloat rounded |
|
1496 |
0.5 asShortFloat rounded |
|
1497 |
0.6 asShortFloat rounded |
|
1498 |
-0.4 asShortFloat rounded |
|
1499 |
-0.5 asShortFloat rounded |
|
1500 |
-0.6 asShortFloat rounded |
|
1501 |
" |
|
1502 |
! |
|
1503 |
||
1504 |
roundedAsFloat |
|
1505 |
"return the receiver rounded to the nearest integer as a float. |
|
1506 |
This is much like #rounded, but avoids a (possibly expensive) conversion |
|
1507 |
of the result to an integer. |
|
1508 |
It may be useful, if the result is to be further used in another float-operation." |
|
1509 |
||
1510 |
%{ /* NOCONTEXT */ |
|
1511 |
float fVal; |
|
1512 |
OBJ v; |
|
1513 |
||
1514 |
fVal = __shortFloatVal(self); |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1515 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1516 |
if (fVal < 0.0) { |
1517 |
fVal = ceilf(fVal - (float)0.5); |
|
1518 |
} else { |
|
1519 |
fVal = floorf(fVal + (float)0.5); |
|
1520 |
} |
|
1521 |
#else |
|
1522 |
if (fVal < 0.0) { |
|
1523 |
fVal = (float)ceil((double)fVal - 0.5); |
|
1524 |
} else { |
|
1525 |
fVal = (float)floor((double)fVal + 0.5); |
|
1526 |
} |
|
1527 |
#endif |
|
1528 |
__qMKSFLOAT(v, fVal); |
|
1529 |
RETURN (v); |
|
1530 |
%} |
|
1531 |
||
1532 |
" |
|
1533 |
0.4 asShortFloat rounded |
|
1534 |
0.5 asShortFloat rounded |
|
1535 |
0.6 asShortFloat rounded |
|
1536 |
-0.4 asShortFloat rounded |
|
1537 |
-0.5 asShortFloat rounded |
|
1538 |
-0.6 asShortFloat rounded |
|
1539 |
||
1540 |
0.4 asShortFloat roundedAsFloat |
|
1541 |
0.5 asShortFloat roundedAsFloat |
|
1542 |
0.6 asShortFloat roundedAsFloat |
|
1543 |
-0.4 asShortFloat roundedAsFloat |
|
1544 |
-0.5 asShortFloat roundedAsFloat |
|
1545 |
-0.6 asShortFloat roundedAsFloat |
|
1546 |
" |
|
1547 |
! |
|
1548 |
||
1549 |
truncated |
|
1550 |
"return the receiver truncated towards zero as an integer" |
|
1551 |
||
1552 |
|val| |
|
1553 |
||
1554 |
%{ |
|
1555 |
float fVal; |
|
1556 |
||
1557 |
fVal = __shortFloatVal(self); |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1558 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1559 |
if (fVal < 0.0) { |
1560 |
fVal = ceilf(fVal); |
|
1561 |
} else { |
|
1562 |
fVal = floorf(fVal); |
|
1563 |
} |
|
1564 |
#else |
|
1565 |
if (fVal < 0.0) { |
|
1566 |
fVal = (float)ceil((double)fVal); |
|
1567 |
} else { |
|
1568 |
fVal = (float)floor((double)fVal); |
|
1569 |
} |
|
1570 |
#endif |
|
1571 |
/* |
|
1572 |
* ST-80 (and X3J20) returns integer. |
|
1573 |
*/ |
|
1574 |
if ((fVal >= (float)_MIN_INT) && (fVal <= (float)_MAX_INT)) { |
|
8913 | 1575 |
RETURN ( __mkSmallInteger( (INT) fVal ) ); |
7356 | 1576 |
} |
1577 |
__qMKSFLOAT(val, fVal); |
|
1578 |
%}. |
|
1579 |
^ val asInteger |
|
1580 |
||
1581 |
" |
|
1582 |
0.5 asShortFloat truncated |
|
1583 |
-0.5 asShortFloat truncated |
|
1584 |
0.5 asShortFloat truncatedAsFloat |
|
1585 |
-0.5 asShortFloat truncatedAsFloat |
|
1586 |
" |
|
1587 |
! |
|
1588 |
||
1589 |
truncatedAsFloat |
|
1590 |
"return the receiver truncated towards zero as a float. |
|
1591 |
This is much like #truncated, but avoids a (possibly expensive) conversion |
|
1592 |
of the result to an integer. |
|
1593 |
It may be useful, if the result is to be further used in another |
|
1594 |
float-operation." |
|
1595 |
||
1596 |
%{ /* NOCONTEXT */ |
|
1597 |
float fVal; |
|
1598 |
OBJ v; |
|
1599 |
||
1600 |
fVal = __shortFloatVal(self); |
|
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8706
diff
changeset
|
1601 |
#if defined(__i386__) && defined(__GNUC__) |
7356 | 1602 |
if (fVal < 0.0) { |
1603 |
fVal = ceilf(fVal); |
|
1604 |
} else { |
|
1605 |
fVal = floorf(fVal); |
|
1606 |
} |
|
1607 |
#else |
|
1608 |
if (fVal < 0.0) { |
|
1609 |
fVal = (float)ceil((double)fVal); |
|
1610 |
} else { |
|
1611 |
fVal = (float)floor((double)fVal); |
|
1612 |
} |
|
1613 |
#endif |
|
1614 |
__qMKSFLOAT(v, fVal); |
|
1615 |
RETURN (v); |
|
1616 |
%} |
|
1617 |
||
1618 |
" |
|
1619 |
0.5 asShortFloat truncated |
|
1620 |
-0.5 asShortFloat truncated |
|
1621 |
0.5 asShortFloat truncatedAsFloat |
|
1622 |
-0.5 asShortFloat truncatedAsFloat |
|
1623 |
" |
|
3897 | 1624 |
! ! |
1625 |
||
1880 | 1626 |
!ShortFloat class methodsFor:'documentation'! |
1197 | 1627 |
|
1628 |
version |
|
9121
561e28aa22f9
fixed: isNaN and isFinite (for WIN32)
Claus Gittinger <cg@exept.de>
parents:
8984
diff
changeset
|
1629 |
^ '$Header: /cvs/stx/stx/libbasic/ShortFloat.st,v 1.92 2006-02-17 11:47:44 cg Exp $' |
1197 | 1630 |
! ! |