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