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