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