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