author | Claus Gittinger <cg@exept.de> |
Mon, 20 Feb 2006 12:28:56 +0100 | |
changeset 9150 | 550cef1b935a |
parent 9124 | 1bc6bb791bdc |
child 9637 | 3e3866fb16e9 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
175 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5411 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
54 | 15 |
LimitedPrecisionReal variableByteSubclass:#Float |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
16 |
instanceVariableNames:'' |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
17 |
classVariableNames:'DefaultPrintFormat Pi E' |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
18 |
poolDictionaries:'' |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
category:'Magnitude-Numbers' |
1 | 20 |
! |
21 |
||
701 | 22 |
!Float primitiveDefinitions! |
23 |
%{ |
|
24 |
#include <errno.h> |
|
25 |
||
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
26 |
#ifndef __OPTIMIZE__ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
27 |
# define __OPTIMIZE__ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
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 |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
32 |
#include <math.h> |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
33 |
|
701 | 34 |
/* |
35 |
* on some systems errno is a macro ... check for it here |
|
36 |
*/ |
|
37 |
#ifndef errno |
|
38 |
extern errno; |
|
39 |
#endif |
|
40 |
||
2394 | 41 |
#if defined (_AIX) |
42 |
# include <float.h> |
|
43 |
#endif |
|
4825 | 44 |
|
2395 | 45 |
#if defined(IRIX) |
46 |
# include <nan.h> |
|
47 |
#endif |
|
4825 | 48 |
|
2397 | 49 |
#if defined(LINUX) |
4825 | 50 |
# ifndef NAN |
5822
4e56f8aadda5
Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
51 |
# include <bits/nan.h> |
4825 | 52 |
# endif |
2396 | 53 |
#endif |
4825 | 54 |
|
2399 | 55 |
#if defined(solaris) || defined(sunos) |
2398 | 56 |
# include <nan.h> |
57 |
#endif |
|
2394 | 58 |
|
3129 | 59 |
/* |
60 |
* sigh - some systems define that stuff; others dont. |
|
61 |
* (AIX even declares them as macros, so an external decl |
|
62 |
* will not work below ... |
|
63 |
*/ |
|
3240 | 64 |
#if !defined(_AIX) && !defined(NEXT3) |
3129 | 65 |
|
66 |
# ifdef acos |
|
67 |
double acos(); |
|
68 |
# endif |
|
69 |
# ifdef asin |
|
70 |
double asin(); |
|
71 |
# endif |
|
72 |
# ifndef atan |
|
73 |
double atan(); |
|
74 |
# endif |
|
75 |
# ifndef cos |
|
76 |
double cos(); |
|
77 |
# endif |
|
78 |
# ifndef sin |
|
79 |
double sin(); |
|
80 |
# endif |
|
81 |
# ifndef pow |
|
82 |
double pow(); |
|
83 |
# endif |
|
84 |
# ifndef log |
|
85 |
double log(); |
|
86 |
# endif |
|
87 |
# ifndef exp |
|
88 |
double exp(); |
|
89 |
# endif |
|
90 |
# ifndef sqrt |
|
91 |
double sqrt(); |
|
92 |
# endif |
|
93 |
# ifndef tan |
|
94 |
double tan(); |
|
95 |
# endif |
|
96 |
||
97 |
#endif /* not AIX */ |
|
98 |
||
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
99 |
#ifdef WIN32 |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
100 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
101 |
* no finite(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
102 |
* no isnan(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
103 |
*/ |
7420 | 104 |
# ifndef isnan |
105 |
# define isnan(x) \ |
|
106 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
107 |
(((unsigned int *)(&x))[1] == 0xFFF80000)) |
|
108 |
# endif |
|
109 |
||
110 |
# ifndef isPositiveInfinity |
|
111 |
# define isPositiveInfinity(x) \ |
|
112 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
113 |
(((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
|
114 |
# endif |
7420 | 115 |
|
116 |
# ifndef isNegativeInfinity |
|
117 |
# define isPositiveInfinity(x) \ |
|
118 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
119 |
(((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
|
120 |
# endif |
7420 | 121 |
|
122 |
# ifndef isinf |
|
123 |
# define isinf(x) \ |
|
124 |
((((unsigned int *)(&x))[0] == 0x00000000) && \ |
|
125 |
((((unsigned int *)(&x))[1] & 0x7FF00000) == 0x7FF00000)) |
|
126 |
# endif |
|
127 |
||
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
128 |
# ifndef isfinite |
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
129 |
# define isfinite(x) (!isinf(x) && !isnan(x)) |
7420 | 130 |
# endif |
131 |
||
7411 | 132 |
# define NO_ASINH |
133 |
# define NO_ACOSH |
|
134 |
# define NO_ATANH |
|
8984 | 135 |
#endif /* WIN32 */ |
136 |
||
137 |
#ifdef solaris |
|
138 |
# ifndef isfinite |
|
139 |
# define isfinite(f) finite((double)(f)) |
|
140 |
# endif |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
141 |
#endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
142 |
|
3414 | 143 |
#ifdef realIX |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
144 |
# ifndef isfinite |
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
145 |
# define isfinite(x) 1 |
3414 | 146 |
# endif |
147 |
#endif |
|
148 |
||
3241 | 149 |
#ifndef NEXT3 |
150 |
# ifndef ceil |
|
151 |
double ceil(); |
|
152 |
double floor(); |
|
153 |
# endif |
|
154 |
#endif |
|
155 |
||
701 | 156 |
%} |
157 |
! ! |
|
158 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
159 |
!Float class methodsFor:'documentation'! |
68 | 160 |
|
88 | 161 |
copyright |
162 |
" |
|
163 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
175 | 164 |
All Rights Reserved |
88 | 165 |
|
166 |
This software is furnished under a license and may be used |
|
167 |
only in accordance with the terms of that license and with the |
|
168 |
inclusion of the above copyright notice. This software may not |
|
169 |
be provided or otherwise made available to, or used by, any |
|
170 |
other person. No title to or ownership of the software is |
|
171 |
hereby transferred. |
|
172 |
" |
|
173 |
! |
|
174 |
||
68 | 175 |
documentation |
176 |
" |
|
7380 | 177 |
ShortFloats represent rational numbers with limited precision. |
178 |
They use the C-compilers 'double' format, which is usually the 8byte IEE double float format. |
|
179 |
||
180 |
Floats give you 64 bit floats. |
|
181 |
In contrast to ShortFloats and LongFloats. |
|
182 |
||
183 |
WARNING: |
|
184 |
The layout of Float instances is known by the runtime system and the compiler; |
|
185 |
you may not add instance variables here. |
|
186 |
Also, subclassing is complicated by the fact, that the VM creates floats/shortFloats, |
|
187 |
and does some float-checks by an identity compare with the Float-class. |
|
188 |
(i.e. your subclasses instances may not be recognized as float-like objects, |
|
189 |
thus mixed mode arithmetic will always coerce them, effectively slowing things down). |
|
1 | 190 |
|
68 | 191 |
Notice, that Floats are defined as Byte-array to prevent the garbage collector |
192 |
from going into the value ... otherwise I needed a special case in many places. |
|
193 |
||
194 |
Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change |
|
195 |
in one of the next versions (at least on machines, which provide different float |
|
6674 | 196 |
and double types in their C-compiler). |
197 |
The reason for doung this was to be compatible to both Digitalk and ParcPlace smalltalk |
|
198 |
implementations |
|
199 |
(ParcPlace uses a 4-byte Float and an 8-byte Double class, in contrast to |
|
200 |
Digitalk, which has an 8-byte Float class). |
|
7380 | 201 |
Thus, by providing an 8-byte Float class, code would not loose precicion |
202 |
(although some memory is wasted when porting from VW). |
|
6674 | 203 |
As Digitalk is dead now, things could (should) now be made to be compatible with VW. |
204 |
Notice that ST/X provides an alias called Double, and an extra ShortFloat class, which has 4-byte |
|
205 |
instances. |
|
68 | 206 |
|
1892 | 207 |
Mixed mode arithmetic: |
6674 | 208 |
float op float -> float |
209 |
float op fix -> float |
|
7380 | 210 |
float op fraction -> float |
6674 | 211 |
float op integer -> float |
7380 | 212 |
float op shortFloat -> float |
213 |
float op longFloat -> longFloat |
|
214 |
float op complex -> complex |
|
1892 | 215 |
|
7405 | 216 |
Representation: |
217 |
64bit double precision IEE floats |
|
218 |
53 bit mantissa, |
|
219 |
11 bit exponent, |
|
220 |
15 decimal digits (approx) |
|
221 |
||
222 |
Range and Precision of Storage Formats: see LimitedPrecisionReal >> documentation |
|
85 | 223 |
|
7380 | 224 |
[author:] |
225 |
Claus Gittinger |
|
226 |
||
1295 | 227 |
[see also:] |
6674 | 228 |
Number |
7380 | 229 |
ShortFloat LongFloat Fraction FixedPoint Integer Complex |
6674 | 230 |
FloatArray DoubleArray |
68 | 231 |
" |
2215 | 232 |
! |
233 |
||
234 |
errorHandling |
|
235 |
" |
|
236 |
Floating point error handling and signalling depends on the systems |
|
237 |
(actually: the C-runtime systems) ability to handle floating point errors. |
|
238 |
Most systems report errors by raising an OS floatingPoint exception, |
|
239 |
which is mapped to a fpExceptionInterrupt in ST/X. |
|
240 |
However, some systems do return NaN as result. |
|
241 |
||
242 |
Currently, ST/X does not care specially for these systems - it maybe added |
|
243 |
easily, if there is sufficient customer interest, though. |
|
244 |
||
245 |
Try: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
246 |
|f1 f2| |
2215 | 247 |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
248 |
f1 := 1.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
249 |
f2 := 0.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
250 |
f1 / f2 |
2215 | 251 |
|
252 |
or: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
253 |
2 arcSin |
2215 | 254 |
" |
68 | 255 |
! ! |
1 | 256 |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
257 |
!Float class methodsFor:'instance creation'! |
1 | 258 |
|
259 |
basicNew |
|
260 |
"return a new float - here we return 0.0 |
|
261 |
- floats are usually NOT created this way ... |
|
262 |
Its implemented here to allow things like binary store & load |
|
263 |
of floats. (but even this support will go away eventually, its not |
|
264 |
a good idea to store the bits of a float - the reader might have a |
|
13 | 265 |
totally different representation - so floats will eventually be |
266 |
binary stored in a device independent format." |
|
1 | 267 |
|
268 |
%{ /* NOCONTEXT */ |
|
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
269 |
OBJ newFloat; |
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
270 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
271 |
__qMKFLOAT(newFloat, 0.0); |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
272 |
RETURN (newFloat); |
1 | 273 |
%} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
274 |
! |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
275 |
|
4295 | 276 |
fastFromString:aString at:startIndex |
277 |
"return the next Float from the string starting at startIndex. |
|
278 |
No spaces are skipped. |
|
279 |
||
280 |
This is a specially tuned entry (using a low-level C-call), which |
|
281 |
returns garbage if the argument string is not a valid float number. |
|
282 |
It has been added to allow higher speed string decomposition into |
|
283 |
numbers." |
|
284 |
%{ |
|
285 |
if (__isString(aString) && __isSmallInteger(startIndex)) { |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
286 |
char *cp = (char *)(__stringVal(aString)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
287 |
int idx = __intVal(startIndex) - 1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
288 |
double atof(); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
289 |
double val; |
4295 | 290 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
291 |
if ((unsigned)idx < __stringSize(aString)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
292 |
val = atof(cp + idx); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
293 |
RETURN (__MKFLOAT(val)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
294 |
} |
4295 | 295 |
} |
296 |
%}. |
|
297 |
self primitiveFailed. |
|
298 |
||
299 |
" |
|
4296 | 300 |
Float fastFromString:'123.45' at:1 |
301 |
Float fastFromString:'123.45' at:2 |
|
302 |
Float fastFromString:'123.45E4' at:1 |
|
303 |
Float fastFromString:'hello123.45E4' at:6 |
|
4295 | 304 |
Float fastFromString:'12345' at:1 |
305 |
Float fastFromString:'12345' at:2 |
|
306 |
Float fastFromString:'12345' at:3 |
|
307 |
Float fastFromString:'12345' at:4 |
|
308 |
Float fastFromString:'12345' at:5 |
|
309 |
Float fastFromString:'12345' at:6 |
|
310 |
Float fastFromString:'12345' at:0 |
|
4296 | 311 |
Float fastFromString:'hello123.45E4' at:1 |
4295 | 312 |
|
313 |
Time millisecondsToRun:[ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
314 |
100000 timesRepeat:[ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
315 |
Float readFrom:'123.45' |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
316 |
] |
4295 | 317 |
] |
318 |
" |
|
319 |
||
320 |
" |
|
321 |
Time millisecondsToRun:[ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
322 |
100000 timesRepeat:[ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
323 |
Float fastFromString:'123.45' at:1 |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
324 |
] |
4295 | 325 |
] |
326 |
" |
|
327 |
||
328 |
||
329 |
! |
|
330 |
||
3279 | 331 |
fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4 |
332 |
"creates a double, given the four vax float bytes to an ieee double. |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
333 |
For NaNs and Infinity, nil is returned. |
3279 | 334 |
" |
335 |
||
336 |
%{ /* NOCONTEXT */ |
|
337 |
||
338 |
REGISTER union { |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
339 |
unsigned char b[4]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
340 |
unsigned int l; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
341 |
float f; |
3279 | 342 |
} r; |
343 |
||
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8635
diff
changeset
|
344 |
#ifdef __LSBFIRST__ |
3279 | 345 |
r.b[3] = __intVal( b2 ); |
346 |
r.b[2] = __intVal( b1 ); |
|
347 |
r.b[1] = __intVal( b4 ); |
|
348 |
r.b[0] = __intVal( b3 ); |
|
349 |
#else |
|
350 |
r.b[0] = __intVal( b2 ); |
|
351 |
r.b[1] = __intVal( b1 ); |
|
352 |
r.b[2] = __intVal( b4 ); |
|
353 |
r.b[3] = __intVal( b3 ); |
|
354 |
#endif |
|
355 |
if( (r.l & 0xff800000) != 0x80000000 ) |
|
356 |
{ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
357 |
if( (r.l & 0x7f800000) > 0x01000000 ) |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
358 |
r.l -= 0x01000000; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
359 |
else |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
360 |
r.l = 0; |
3279 | 361 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
362 |
RETURN( __MKFLOAT(r.f) ); |
3279 | 363 |
} |
364 |
%}. |
|
365 |
^ nil |
|
366 |
! |
|
367 |
||
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
368 |
readFrom:aStringOrStream onError:exceptionBlock |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
369 |
"read a float from a string" |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
370 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
371 |
|num| |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
372 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
373 |
num := super readFrom:aStringOrStream onError:nil. |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
374 |
num isNil ifTrue:[ |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
375 |
^ exceptionBlock value |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
376 |
]. |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
377 |
^ num asFloat |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
378 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
379 |
" |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
380 |
Float readFrom:'0.1' |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
381 |
Float readFrom:'0' |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
382 |
" |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
383 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
384 |
"Created: / 7.1.1998 / 16:17:19 / cg" |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
385 |
"Modified: / 7.1.1998 / 16:18:33 / cg" |
1 | 386 |
! ! |
387 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
388 |
!Float class methodsFor:'binary storage'! |
701 | 389 |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
390 |
binaryDefinitionFrom:aStream manager: manager |
701 | 391 |
|f| |
392 |
||
393 |
f := self basicNew. |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
394 |
self readBinaryIEEEDoubleFrom:aStream into:f. |
701 | 395 |
^ f |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
396 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
397 |
"Modified: 16.4.1996 / 21:23:38 / cg" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
398 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
399 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
400 |
readBinaryIEEEDoubleFrom:aStream |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
401 |
"read a float from the binary stream, aStream, |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
402 |
interpreting the next bytes as an IEEE formatted 8-byte float" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
403 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
404 |
|f| |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
405 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
406 |
f := self basicNew. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
407 |
self readBinaryIEEEDoubleFrom:aStream into:f. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
408 |
^ f |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
409 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
410 |
"Created: 16.4.1996 / 20:59:59 / cg" |
701 | 411 |
! |
412 |
||
413 |
readBinaryIEEEDoubleFrom:aStream into:aFloat |
|
414 |
"read the receivers value from the binary stream, aStream, |
|
415 |
interpreting the next bytes as an IEEE formatted 8-byte float" |
|
416 |
||
417 |
" |
|
418 |
this implementation is wrong: does not work on non-IEEE machines |
|
419 |
(to date all machines where ST/X is running on use |
|
420 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
421 |
" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
422 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
423 |
|
701 | 424 |
UninterpretedBytes isBigEndian ifFalse:[ |
425 |
"swap the bytes" |
|
426 |
8 to:1 by:-1 do:[:i | |
|
427 |
aFloat basicAt:i put:(aStream next) |
|
428 |
]. |
|
429 |
^ self |
|
430 |
]. |
|
431 |
1 to:8 do:[:i | |
|
432 |
aFloat basicAt:i put:aStream next |
|
433 |
] |
|
434 |
! |
|
435 |
||
436 |
storeBinaryIEEEDouble:aFloat on:aStream |
|
437 |
"store aFloat as an IEEE formatted 8-byte float |
|
438 |
onto the binary stream, aStream" |
|
439 |
||
440 |
" |
|
441 |
this implementation is wrong: does not work on non-IEEE machines |
|
442 |
(to date all machines where ST/X is running on use |
|
443 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
444 |
" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
445 |
self isIEEEFormat ifFalse:[self error:'unsupported operation']. |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
446 |
|
701 | 447 |
UninterpretedBytes isBigEndian ifFalse:[ |
448 |
"swap the bytes" |
|
449 |
8 to:1 by:-1 do:[:i | |
|
450 |
aStream nextPut:(aFloat basicAt:i). |
|
451 |
]. |
|
452 |
^ self |
|
453 |
]. |
|
454 |
1 to:8 do:[:i | |
|
455 |
aStream nextPut:(aFloat basicAt:i). |
|
456 |
]. |
|
457 |
! ! |
|
458 |
||
7441 | 459 |
!Float class methodsFor:'class initialization'! |
460 |
||
461 |
initialize |
|
462 |
DefaultPrintFormat := '.6' "/ 6 valid digits |
|
463 |
||
464 |
" |
|
465 |
DefaultPrintFormat := '.9'. |
|
466 |
Float pi printString. |
|
467 |
||
468 |
DefaultPrintFormat := '.6'. |
|
469 |
Float pi printString. |
|
470 |
" |
|
471 |
! ! |
|
472 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
473 |
!Float class methodsFor:'constants'! |
1 | 474 |
|
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
475 |
NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
476 |
"return the constant NaN (not a Number). |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
477 |
Do not use (yet) - for now, this is only defined for a |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
478 |
few selected architectures." |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
479 |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
480 |
%{ /* NOCONTEXT */ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8635
diff
changeset
|
481 |
#if defined(LINUX) && defined(__i386__) |
3955 | 482 |
# ifdef NAN |
483 |
RETURN (__MKFLOAT(NAN)); |
|
484 |
# else |
|
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
485 |
RETURN (__MKFLOAT(_SNAN)); |
3955 | 486 |
# endif |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
487 |
#endif |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
488 |
%}. |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
489 |
^ super NaN |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
490 |
|
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
491 |
" |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
492 |
Float NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
493 |
Float NaN + 0.0 |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
494 |
Float NaN + Float NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
495 |
0.0 + Float NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
496 |
" |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
497 |
! |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
498 |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
499 |
e |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
500 |
"return the constant e as Float" |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
501 |
|
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
502 |
"/ dont expect this many valid digits on all machines; |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
503 |
"/ The actual precision is very CPU specific. |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
504 |
|
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
505 |
^ 2.7182818284590452353602874713526625 |
6341 | 506 |
! |
507 |
||
701 | 508 |
pi |
1260 | 509 |
"return the constant pi as Float" |
1 | 510 |
|
3244 | 511 |
"/ dont expect this many valid digits on all machines; |
512 |
"/ The actual precision is very CPU specific. |
|
513 |
||
6063 | 514 |
^ 3.14159265358979323846264338327950288419716939937510582097494459 |
1260 | 515 |
|
516 |
"Modified: 23.4.1996 / 09:27:02 / cg" |
|
1 | 517 |
! |
518 |
||
519 |
unity |
|
1260 | 520 |
"return the neutral element for multiplication (1.0) as Float" |
1 | 521 |
|
522 |
^ 1.0 |
|
1260 | 523 |
|
524 |
"Modified: 23.4.1996 / 09:27:09 / cg" |
|
1 | 525 |
! |
526 |
||
701 | 527 |
zero |
1260 | 528 |
"return the neutral element for addition (0.0) as Float" |
1 | 529 |
|
701 | 530 |
^ 0.0 |
1260 | 531 |
|
532 |
"Modified: 23.4.1996 / 09:27:15 / cg" |
|
1 | 533 |
! ! |
534 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
535 |
!Float class methodsFor:'queries'! |
3 | 536 |
|
6898 | 537 |
exponentCharacter |
538 |
^ $d |
|
539 |
! |
|
540 |
||
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
541 |
hasSharedInstances |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
542 |
"return true if this class has shared instances, that is, instances |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
543 |
with the same value are identical. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
544 |
Although not really shared, floats should be treated |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
545 |
so, to be independent of the implementation of the arithmetic methods." |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
546 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
547 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
548 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
549 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
550 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
551 |
|
3 | 552 |
isBuiltInClass |
1264 | 553 |
"return true if this class is known by the run-time-system. |
554 |
Here, true is returned for myself, false for subclasses." |
|
3 | 555 |
|
556 |
^ self == Float |
|
1264 | 557 |
|
558 |
"Modified: 23.4.1996 / 15:59:04 / cg" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
559 |
! |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
560 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
561 |
isIEEEFormat |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
562 |
"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
|
563 |
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
|
564 |
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
|
565 |
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
|
566 |
machine). |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
567 |
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
|
568 |
(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
|
569 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
570 |
^ true "/ this may be a lie |
7355 | 571 |
! |
572 |
||
573 |
numBitsInExponent |
|
574 |
"answer the number of bits in the exponent |
|
575 |
This is an IEEE float, where 11 bits are available: |
|
576 |
seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
577 |
" |
|
578 |
||
579 |
^ 11 |
|
580 |
! |
|
581 |
||
582 |
numBitsInMantissa |
|
583 |
"answer the number of bits in the mantissa. |
|
584 |
This is an IEEE double, where 52 bits (the hidden one is not counted here) are available: |
|
585 |
seeeeeee eeeemmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm mmmmmmmm |
|
586 |
" |
|
587 |
||
588 |
^ 52 |
|
589 |
! |
|
590 |
||
591 |
precision |
|
592 |
"answer the precision of a Float (in bits) |
|
9150 | 593 |
This is an IEEE double, where only the fraction from the normalized mantissa is stored |
7355 | 594 |
and so there is a hidden bit and the mantissa is actually represented |
9150 | 595 |
by 53 binary digits (although only 52 are needed in the binary representation)" |
7355 | 596 |
|
597 |
^ 53 |
|
598 |
! |
|
599 |
||
600 |
radix |
|
601 |
"answer the radix of a Floats exponent |
|
602 |
This is an IEEE float, which is represented as binary" |
|
603 |
||
8635 | 604 |
^ 2 "must be careful here, whenever ST/X is used on VAX or a 370" |
3 | 605 |
! ! |
606 |
||
1 | 607 |
!Float methodsFor:'arithmetic'! |
608 |
||
701 | 609 |
* aNumber |
610 |
"return the product of the receiver and the argument, aNumber" |
|
611 |
||
612 |
%{ /* NOCONTEXT */ |
|
613 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
614 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
615 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
616 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
617 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
618 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
619 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
620 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
621 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
622 |
*/ |
701 | 623 |
OBJ newFloat; |
624 |
double result; |
|
625 |
||
626 |
if (__isSmallInteger(aNumber)) { |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
627 |
result = __floatVal(self) * (double)(__intVal(aNumber)); |
701 | 628 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
629 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
630 |
RETURN ( newFloat ); |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
631 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
632 |
if (__isFloatLike(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
633 |
result = __floatVal(self) * __floatVal(aNumber); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
634 |
goto retResult; |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
635 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
636 |
if (__isShortFloat(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
637 |
result = __floatVal(self) * (double)(__shortFloatVal(aNumber)); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
638 |
goto retResult; |
701 | 639 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
640 |
%}. |
701 | 641 |
^ aNumber productFromFloat:self |
642 |
! |
|
643 |
||
1 | 644 |
+ aNumber |
645 |
"return the sum of the receiver and the argument, aNumber" |
|
646 |
||
647 |
%{ /* NOCONTEXT */ |
|
13 | 648 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
649 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
650 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
651 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
652 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
653 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
654 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
655 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
656 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
657 |
*/ |
1 | 658 |
OBJ newFloat; |
659 |
double result; |
|
660 |
||
250 | 661 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
662 |
result = __floatVal(self) + (double)(__intVal(aNumber)); |
1 | 663 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
664 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
665 |
RETURN ( newFloat ); |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
666 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
667 |
if (__isFloatLike(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
668 |
result = __floatVal(self) + __floatVal(aNumber); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
669 |
goto retResult; |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
670 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
671 |
if (__isShortFloat(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
672 |
result = __floatVal(self) + (double)(__shortFloatVal(aNumber)); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
673 |
goto retResult; |
1 | 674 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
675 |
%}. |
1 | 676 |
^ aNumber sumFromFloat:self |
677 |
! |
|
678 |
||
679 |
- aNumber |
|
680 |
"return the difference of the receiver and the argument, aNumber" |
|
681 |
||
682 |
%{ /* NOCONTEXT */ |
|
13 | 683 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
684 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
685 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
686 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
687 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
688 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
689 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
690 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
691 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
692 |
*/ |
1 | 693 |
OBJ newFloat; |
694 |
double result; |
|
695 |
||
250 | 696 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
697 |
result = __floatVal(self) - (double)(__intVal(aNumber)); |
1 | 698 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
699 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
700 |
RETURN ( newFloat ); |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
701 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
702 |
if (__isFloatLike(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
703 |
result = __floatVal(self) - __floatVal(aNumber); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
704 |
goto retResult; |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
705 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
706 |
if (__isShortFloat(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
707 |
result = __floatVal(self) - (double)(__shortFloatVal(aNumber)); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
708 |
goto retResult; |
1 | 709 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
710 |
%}. |
1 | 711 |
^ aNumber differenceFromFloat:self |
712 |
! |
|
713 |
||
714 |
/ aNumber |
|
715 |
"return the quotient of the receiver and the argument, aNumber" |
|
716 |
||
717 |
%{ /* NOCONTEXT */ |
|
718 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
719 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
720 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
721 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
722 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
723 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
724 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
725 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
726 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
727 |
*/ |
1 | 728 |
OBJ newFloat; |
729 |
double result, val; |
|
730 |
||
250 | 731 |
if (__isSmallInteger(aNumber)) { |
8913 | 732 |
if (aNumber != __mkSmallInteger(0)) { |
7141
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
733 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
1 | 734 |
retResult: |
7141
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
735 |
__qMKFLOAT(newFloat, result); |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
736 |
RETURN ( newFloat ); |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
737 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
738 |
} else if (__isFloatLike(aNumber)) { |
7141
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
739 |
val = __floatVal(aNumber); |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
740 |
if (val != 0.0) { |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
741 |
result = __floatVal(self) / val; |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
742 |
goto retResult; |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
743 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
744 |
} else if (__isShortFloat(aNumber)) { |
7141
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
745 |
val = (double)(__shortFloatVal(aNumber)); |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
746 |
if (val != 0.0) { |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
747 |
result = __floatVal(self) / val; |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
748 |
goto retResult; |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
749 |
} |
1 | 750 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
751 |
%}. |
1 | 752 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
7141
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
753 |
" |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
754 |
No, you shalt not divide by zero |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
755 |
" |
033f2c26d8e6
replaced refs to DivisionByZeroSignal with ZeroDivide
Claus Gittinger <cg@exept.de>
parents:
6898
diff
changeset
|
756 |
^ ZeroDivide raiseRequestWith:thisContext. |
1 | 757 |
]. |
758 |
^ aNumber quotientFromFloat:self |
|
759 |
! |
|
760 |
||
5411 | 761 |
abs |
762 |
"return the absolute value of the receiver |
|
763 |
reimplemented here for speed" |
|
764 |
||
765 |
%{ /* NOCONTEXT */ |
|
766 |
||
767 |
OBJ newFloat; |
|
768 |
double val =__floatVal(self); |
|
769 |
||
770 |
if (val < 0.0) { |
|
7724 | 771 |
__qMKFLOAT(newFloat, -val); |
7355 | 772 |
RETURN ( newFloat ); |
5411 | 773 |
} |
774 |
RETURN (self); |
|
775 |
%}. |
|
776 |
||
777 |
" |
|
778 |
3.0 abs |
|
779 |
-3.0 abs |
|
780 |
" |
|
781 |
! |
|
782 |
||
1 | 783 |
negated |
784 |
"return myself negated" |
|
785 |
||
786 |
%{ /* NOCONTEXT */ |
|
3 | 787 |
OBJ newFloat; |
1133 | 788 |
double rslt = - __floatVal(self); |
3 | 789 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
790 |
__qMKFLOAT(newFloat, rslt); |
3 | 791 |
RETURN ( newFloat ); |
5411 | 792 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
793 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
794 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
795 |
uncheckedDivide:aNumber |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
796 |
"return the quotient of the receiver and the argument, aNumber. |
7471 | 797 |
Do not check for divide by zero (return NaN or Infinity). |
7355 | 798 |
This operation is provided for emulators of other languages/semantics, |
799 |
where no exception is raised for these results (i.e. Java). |
|
800 |
Its only defined if the arguments type is the same as the receivers." |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
801 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
802 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
803 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
804 |
OBJ newFloat; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
805 |
double result, val; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
806 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
807 |
if (__isSmallInteger(aNumber)) { |
7355 | 808 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
809 |
retResult: |
7355 | 810 |
__qMKFLOAT(newFloat, result); |
811 |
RETURN ( newFloat ); |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
812 |
} |
7355 | 813 |
if (__isFloatLike(aNumber)) { |
814 |
val = __floatVal(aNumber); |
|
815 |
result = __floatVal(self) / val; |
|
816 |
goto retResult; |
|
817 |
} |
|
818 |
if (__isShortFloat(aNumber)) { |
|
819 |
val = (double)(__shortFloatVal(aNumber)); |
|
820 |
result = __floatVal(self) / val; |
|
821 |
goto retResult; |
|
822 |
} |
|
823 |
%}. |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
824 |
^ aNumber quotientFromFloat:self |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
825 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
826 |
" |
7355 | 827 |
0.0 uncheckedDivide:0.0 |
828 |
1.0 uncheckedDivide:0.0 |
|
829 |
-1.0 uncheckedDivide:0.0 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
830 |
" |
1 | 831 |
! ! |
832 |
||
701 | 833 |
!Float methodsFor:'binary storage'! |
834 |
||
835 |
storeBinaryDefinitionOn:stream manager:manager |
|
1260 | 836 |
"store the receiver in a binary format on stream. |
837 |
This is an internal interface for binary storage mechanism." |
|
838 |
||
701 | 839 |
manager putIdOfClass:(self class) on:stream. |
840 |
Float storeBinaryIEEEDouble:self on:stream. |
|
1260 | 841 |
|
842 |
"Modified: 23.4.1996 / 09:29:48 / cg" |
|
701 | 843 |
! ! |
844 |
||
5238 | 845 |
!Float methodsFor:'coercing & converting'! |
1 | 846 |
|
3014 | 847 |
asDouble |
7429 | 848 |
"ST80 compatibility: return a double with receivers value. |
849 |
our floats are the identical to ST80 doubles" |
|
3014 | 850 |
|
851 |
^ self |
|
852 |
! |
|
853 |
||
701 | 854 |
asFloat |
855 |
"return a float with same value - thats me" |
|
856 |
||
857 |
^ self |
|
858 |
! |
|
859 |
||
860 |
asInteger |
|
861 |
"return an integer with same value - might truncate" |
|
862 |
||
1 | 863 |
%{ /* NOCONTEXT */ |
1670 | 864 |
double dVal; |
13 | 865 |
|
1670 | 866 |
dVal = __floatVal(self); |
7420 | 867 |
#ifdef WIN32 |
868 |
if (! isnan(dVal)) |
|
869 |
#endif |
|
870 |
{ |
|
871 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
8913 | 872 |
RETURN ( __mkSmallInteger( (INT)dVal) ); |
7420 | 873 |
} |
701 | 874 |
} |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
875 |
%}. |
701 | 876 |
^ super asInteger |
877 |
||
878 |
"12345.0 asInteger" |
|
879 |
"1e15 asInteger" |
|
1 | 880 |
! |
881 |
||
5986 | 882 |
asLongFloat |
883 |
"return a longFloat with same value as receiver" |
|
884 |
||
7355 | 885 |
^ LongFloat fromFloat:self |
5986 | 886 |
|
887 |
" |
|
888 |
123 asFloat asLongFloat |
|
889 |
" |
|
890 |
||
891 |
"Created: / 7.9.2001 / 13:43:04 / cg" |
|
892 |
"Modified: / 7.9.2001 / 13:43:16 / cg" |
|
893 |
! |
|
894 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
895 |
asShortFloat |
7355 | 896 |
"return a shortFloat with same value as receiver. |
897 |
CAVEAT: should raise an error if the receiver exceeds the float range." |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
898 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
899 |
%{ /* NOCONTEXT */ |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
900 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
901 |
OBJ dummy = @global(ShortFloat); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
902 |
OBJ newFloat; |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
903 |
float fVal = (float)__floatVal(self); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
904 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
905 |
__qMKSFLOAT(newFloat, fVal); |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
906 |
RETURN ( newFloat ); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
907 |
%} |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
908 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
909 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
910 |
asTrueFraction |
7355 | 911 |
"Answer a fraction or integer that EXACTLY represents self, |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
912 |
a double precision IEEE floating point number. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
913 |
Floats are stored in the same form on all platforms. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
914 |
(Does not handle gradual underflow or NANs.) |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
915 |
By David N. Smith with significant performance |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
916 |
improvements by Luciano Esteban Notarfrancesco. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
917 |
(Version of 11April97)" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
918 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
919 |
|shifty sign expPart exp fraction fractionPart result zeroBitsCount| |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
920 |
|
6344 | 921 |
self isFinite ifFalse:[ |
7441 | 922 |
^ self asMetaNumber |
923 |
"/ ^ self class |
|
924 |
"/ raise:#domainErrorSignal |
|
925 |
"/ receiver:self |
|
926 |
"/ selector:#asTrueFraction |
|
927 |
"/ arguments:#() |
|
928 |
"/ errorString:'Cannot represent non-finite float as a fraction'. |
|
6341 | 929 |
]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
930 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
931 |
"Extract the bits of an IEEE double float " |
6341 | 932 |
shifty := LargeInteger basicNew numberOfDigits:8. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
933 |
UninterpretedBytes isBigEndian ifTrue:[ |
7355 | 934 |
"/ shifty := ((self longWordAt: 1) bitShift: 32) + (self longWordAt: 2). |
6341 | 935 |
1 to:8 do:[:i | shifty digitAt:(9-i) put:(self basicAt:i)]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
936 |
] ifFalse:[ |
6341 | 937 |
1 to:8 do:[:i | shifty digitAt:i put:(self basicAt:i)]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
938 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
939 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
940 |
" Extract the sign and the biased exponent " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
941 |
sign := (shifty bitShift: -63) = 0 ifTrue: [1] ifFalse: [-1]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
942 |
expPart := (shifty bitShift: -52) bitAnd: 16r7FF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
943 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
944 |
" Extract fractional part; answer 0 if this is a true 0.0 value " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
945 |
fractionPart := shifty bitAnd: 16r000FFFFFFFFFFFFF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
946 |
( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0 ]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
947 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
948 |
" Replace omitted leading 1 in fraction " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
949 |
fraction := fractionPart bitOr: 16r0010000000000000. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
950 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
951 |
"Unbias exponent: 16r3FF is bias; 52 is fraction width" |
7480 | 952 |
exp := 16r3FF - expPart + 52. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
953 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
954 |
" Form the result. When exp>52, the exponent is adjusted by |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
955 |
the number of trailing zero bits in the fraction to minimize |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
956 |
the (huge) time otherwise spent in #gcd:. " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
957 |
exp negative ifTrue: [ |
7480 | 958 |
result := sign * (fraction bitShift: exp negated) |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
959 |
] ifFalse:[ |
6341 | 960 |
zeroBitsCount := fraction lowBit - 1. |
961 |
exp := exp - zeroBitsCount. |
|
962 |
exp <= 0 ifTrue: [ |
|
963 |
zeroBitsCount := zeroBitsCount + exp. |
|
964 |
"exp := 0." " Not needed; exp not refernced again " |
|
7480 | 965 |
result := sign * (fraction bitShift:zeroBitsCount negated) |
6341 | 966 |
] ifFalse: [ |
967 |
result := Fraction |
|
7480 | 968 |
numerator: (sign * (fraction bitShift: zeroBitsCount negated)) |
6341 | 969 |
denominator: (1 bitShift:exp) |
970 |
] |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
971 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
972 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
973 |
"Low cost validation omitted after extensive testing" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
974 |
"(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']." |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
975 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
976 |
^ result |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
977 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
978 |
" |
7480 | 979 |
0.3 asTrueFraction |
980 |
1.25 asTrueFraction |
|
981 |
0.25 asTrueFraction |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
982 |
-0.25 asTrueFraction |
7480 | 983 |
3e37 asTrueFraction |
6341 | 984 |
Float NaN asTrueFraction |
6344 | 985 |
Float infinity asTrueFraction |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
986 |
" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
987 |
! |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
988 |
|
701 | 989 |
coerce:aNumber |
990 |
"return aNumber converted into receivers type" |
|
1 | 991 |
|
701 | 992 |
^ aNumber asFloat |
993 |
! |
|
13 | 994 |
|
701 | 995 |
generality |
996 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
997 |
||
998 |
^ 80 |
|
1 | 999 |
! ! |
1000 |
||
1001 |
!Float methodsFor:'comparing'! |
|
1002 |
||
1003 |
< aNumber |
|
1004 |
"return true, if the argument is greater" |
|
1005 |
||
1006 |
%{ /* NOCONTEXT */ |
|
13 | 1007 |
|
7355 | 1008 |
if (__isSmallInteger(aNumber)) { |
1009 |
RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false ); |
|
1010 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1011 |
if (aNumber != nil) { |
7355 | 1012 |
if (__qIsFloatLike(aNumber)) { |
1013 |
RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false ); |
|
1014 |
} |
|
1015 |
if (__qIsShortFloat(aNumber)) { |
|
1016 |
RETURN ( (__floatVal(self) < (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1017 |
} |
|
1 | 1018 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1019 |
%}. |
1 | 1020 |
^ aNumber lessFromFloat:self |
1021 |
! |
|
1022 |
||
1023 |
<= aNumber |
|
1024 |
"return true, if the argument is greater or equal" |
|
1025 |
||
1026 |
%{ /* NOCONTEXT */ |
|
13 | 1027 |
|
7355 | 1028 |
if (__isSmallInteger(aNumber)) { |
1029 |
RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false ); |
|
1030 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1031 |
if (aNumber != nil) { |
7355 | 1032 |
if (__qIsFloatLike(aNumber)) { |
1033 |
RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false ); |
|
1034 |
} |
|
1035 |
if (__qIsShortFloat(aNumber)) { |
|
1036 |
RETURN ( (__floatVal(self) <= (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1037 |
} |
|
1 | 1038 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1039 |
%}. |
1 | 1040 |
^ self retry:#<= coercing:aNumber |
1041 |
! |
|
1042 |
||
1043 |
= aNumber |
|
7355 | 1044 |
"return true, if the argument represents the same numeric value |
1045 |
as the receiver, false otherwise" |
|
1 | 1046 |
|
1047 |
%{ /* NOCONTEXT */ |
|
13 | 1048 |
|
7355 | 1049 |
if (__isSmallInteger(aNumber)) { |
1050 |
RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false ); |
|
1051 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1052 |
if (aNumber != nil) { |
7355 | 1053 |
if (__qIsFloatLike(aNumber)) { |
1054 |
RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false ); |
|
1055 |
} |
|
1056 |
if (__qIsShortFloat(aNumber)) { |
|
1057 |
RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1058 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1059 |
} else { |
7355 | 1060 |
RETURN (false); |
1 | 1061 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1062 |
%}. |
7355 | 1063 |
^ aNumber equalFromFloat:self |
1 | 1064 |
! |
1065 |
||
701 | 1066 |
> aNumber |
1067 |
"return true, if the argument is less" |
|
1 | 1068 |
|
1069 |
%{ /* NOCONTEXT */ |
|
13 | 1070 |
|
7355 | 1071 |
if (__isSmallInteger(aNumber)) { |
1072 |
RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false ); |
|
1073 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1074 |
if (aNumber != nil) { |
7355 | 1075 |
if (__qIsFloatLike(aNumber)) { |
1076 |
RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false ); |
|
1077 |
} |
|
1078 |
if (__qIsShortFloat(aNumber)) { |
|
1079 |
RETURN ( (__floatVal(self) > (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1080 |
} |
|
1 | 1081 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1082 |
%}. |
701 | 1083 |
^ self retry:#> coercing:aNumber |
1084 |
! |
|
1085 |
||
1086 |
>= aNumber |
|
1087 |
"return true, if the argument is less or equal" |
|
1088 |
||
1089 |
%{ /* NOCONTEXT */ |
|
1090 |
||
7355 | 1091 |
if (__isSmallInteger(aNumber)) { |
1092 |
RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false ); |
|
1093 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1094 |
if (aNumber != nil) { |
7355 | 1095 |
if (__qIsFloatLike(aNumber)) { |
1096 |
RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false ); |
|
1097 |
} |
|
1098 |
if (__qIsShortFloat(aNumber)) { |
|
1099 |
RETURN ( (__floatVal(self) >= (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1100 |
} |
|
701 | 1101 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1102 |
%}. |
701 | 1103 |
^ self retry:#>= coercing:aNumber |
92 | 1104 |
! |
1105 |
||
1106 |
hash |
|
1107 |
"return a number for hashing; redefined, since floats compare |
|
1108 |
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
|
1109 |
as 3 hash." |
92 | 1110 |
|
305 | 1111 |
|i| |
92 | 1112 |
|
1113 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1114 |
i := self asInteger. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1115 |
self = i ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1116 |
^ i hash |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1117 |
]. |
92 | 1118 |
]. |
1119 |
||
1120 |
" |
|
305 | 1121 |
mhmh take some of my value-bits to hash on |
92 | 1122 |
" |
4590 | 1123 |
^ (((self basicAt:8) bitAnd:16r1F) bitShift:24) + |
305 | 1124 |
((self basicAt:7) bitShift:16) + |
1125 |
((self basicAt:6) bitShift:8) + |
|
4592 | 1126 |
(((self basicAt:5) + (self basicAt:1) + (self basicAt:2)) bitAnd:16rFF) |
92 | 1127 |
|
1128 |
" |
|
1129 |
3 hash |
|
1130 |
3.0 hash |
|
1131 |
3.1 hash |
|
1132 |
3.14159 hash |
|
1133 |
31.4159 hash |
|
1134 |
3.141591 hash |
|
1135 |
1.234567890123456 hash |
|
1136 |
1.234567890123457 hash |
|
1137 |
Set withAll:#(3 3.0 99 99.0 3.1415) |
|
1138 |
" |
|
1 | 1139 |
! |
1140 |
||
701 | 1141 |
~= aNumber |
1142 |
"return true, if the arguments value are not equal" |
|
1 | 1143 |
|
1144 |
%{ /* NOCONTEXT */ |
|
1145 |
||
7355 | 1146 |
if (__isSmallInteger(aNumber)) { |
1147 |
RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false ); |
|
1148 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1149 |
if (aNumber != nil) { |
7355 | 1150 |
if (__qIsFloatLike(aNumber)) { |
1151 |
RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false ); |
|
1152 |
} |
|
1153 |
if (__qIsShortFloat(aNumber)) { |
|
1154 |
RETURN ( (__floatVal(self) != (double)(__shortFloatVal(aNumber))) ? true : false ); |
|
1155 |
} |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1156 |
} else { |
7355 | 1157 |
RETURN ( true ); |
1 | 1158 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1159 |
%}. |
7355 | 1160 |
^ super ~= aNumber |
1 | 1161 |
! ! |
1162 |
||
1163 |
!Float methodsFor:'mathematical functions'! |
|
1164 |
||
701 | 1165 |
exp |
1166 |
"return e raised to the power of the receiver" |
|
1167 |
||
1168 |
%{ /* NOCONTEXT */ |
|
1169 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1170 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1171 |
OBJ newFloat; |
701 | 1172 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1173 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1174 |
rslt = exp(__floatVal(self)); |
7393 | 1175 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
1176 |
{ |
|
1177 |
if (__threadErrno == 0) { |
|
1178 |
__qMKFLOAT(newFloat, rslt); |
|
1179 |
RETURN ( newFloat ); |
|
1180 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1181 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1182 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1183 |
^ self class |
6195 | 1184 |
raise:#domainErrorSignal |
1185 |
receiver:self |
|
1186 |
selector:#exp |
|
1187 |
arguments:#() |
|
1188 |
errorString:'bad receiver in exp' |
|
1189 |
||
1190 |
"Modified: / 16.11.2001 / 14:14:29 / cg" |
|
701 | 1191 |
! |
1192 |
||
1 | 1193 |
ln |
6193 | 1194 |
"return the natural logarithm of myself. |
1195 |
Raises an exception, if the receiver is less or equal to zero." |
|
1 | 1196 |
|
1197 |
%{ /* NOCONTEXT */ |
|
1198 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1199 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1200 |
OBJ newFloat; |
1 | 1201 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1202 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1203 |
|
6193 | 1204 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1205 |
if (val > 0.0) |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1206 |
#endif |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1207 |
{ |
6193 | 1208 |
__threadErrno = 0; |
1209 |
rslt = log(val); |
|
7393 | 1210 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
6193 | 1211 |
{ |
1212 |
if (__threadErrno == 0) { |
|
1213 |
__qMKFLOAT(newFloat, rslt); |
|
1214 |
RETURN ( newFloat ); |
|
1215 |
} |
|
1216 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1217 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1218 |
%}. |
142 | 1219 |
" |
1220 |
an invalid value for logarithm |
|
1221 |
" |
|
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1222 |
^ self class |
6193 | 1223 |
raise:#domainErrorSignal |
1224 |
receiver:self |
|
1225 |
selector:#ln |
|
6195 | 1226 |
arguments:#() |
6193 | 1227 |
errorString:'bad receiver in ln' |
1228 |
||
6195 | 1229 |
"Modified: / 16.11.2001 / 14:14:33 / cg" |
1 | 1230 |
! |
1231 |
||
7373 | 1232 |
log10 |
1233 |
"return the bavse-10 logarithm of myself. |
|
1234 |
Raises an exception, if the receiver is less or equal to zero." |
|
1235 |
||
1236 |
%{ /* NOCONTEXT */ |
|
1237 |
||
1238 |
double val, rslt; |
|
1239 |
OBJ newFloat; |
|
1240 |
||
1241 |
val = __floatVal(self); |
|
1242 |
||
1243 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
|
1244 |
if (val > 0.0) |
|
1245 |
#endif |
|
1246 |
{ |
|
1247 |
__threadErrno = 0; |
|
1248 |
rslt = log10(val); |
|
7393 | 1249 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7373 | 1250 |
{ |
1251 |
if (__threadErrno == 0) { |
|
1252 |
__qMKFLOAT(newFloat, rslt); |
|
1253 |
RETURN ( newFloat ); |
|
1254 |
} |
|
1255 |
} |
|
1256 |
} |
|
1257 |
%}. |
|
1258 |
" |
|
1259 |
an invalid value for logarithm |
|
1260 |
" |
|
1261 |
^ self class |
|
1262 |
raise:#domainErrorSignal |
|
1263 |
receiver:self |
|
1264 |
selector:#log10 |
|
1265 |
arguments:#() |
|
1266 |
errorString:'bad receiver in log10' |
|
1267 |
||
1268 |
"Modified: / 16.11.2001 / 14:14:33 / cg" |
|
1269 |
! |
|
1270 |
||
1 | 1271 |
raisedTo:aNumber |
1272 |
"return self raised to the power of aNumber" |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1273 |
|
1 | 1274 |
|n| |
1275 |
||
1276 |
n := aNumber asFloat. |
|
1277 |
%{ |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1278 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1279 |
OBJ newFloat; |
1 | 1280 |
|
283 | 1281 |
if (__isFloatLike(n)) { |
6195 | 1282 |
__threadErrno = 0; |
1283 |
rslt = pow(__floatVal(self), __floatVal(n)); |
|
7393 | 1284 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
1285 |
{ |
|
1286 |
if (__threadErrno == 0) { |
|
1287 |
__qMKFLOAT(newFloat, rslt); |
|
1288 |
RETURN ( newFloat ); |
|
1289 |
} |
|
6195 | 1290 |
} |
1 | 1291 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1292 |
%}. |
142 | 1293 |
" |
1294 |
an invalid argument (not convertable to float ?) |
|
1295 |
" |
|
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1296 |
^ self class |
6195 | 1297 |
raise:#domainErrorSignal |
1298 |
receiver:self |
|
1299 |
selector:#raisedTo: |
|
1300 |
arguments:(Array with:aNumber) |
|
1301 |
errorString:'bad receiver/arg in raisedTo:' |
|
1302 |
||
1303 |
"Modified: / 16.11.2001 / 14:16:51 / cg" |
|
1 | 1304 |
! |
1305 |
||
1306 |
sqrt |
|
6193 | 1307 |
"return the square root of myself. |
1308 |
Raises an exception, if the receiver is less than zero." |
|
1 | 1309 |
|
1310 |
%{ /* NOCONTEXT */ |
|
1311 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1312 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1313 |
OBJ newFloat; |
1 | 1314 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1315 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1316 |
|
6193 | 1317 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1318 |
if (val >= 0.0) |
3889
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1319 |
#endif |
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1320 |
{ |
6193 | 1321 |
__threadErrno = 0; |
1322 |
rslt = sqrt(val); |
|
7393 | 1323 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
6193 | 1324 |
{ |
1325 |
if (__threadErrno == 0) { |
|
1326 |
__qMKFLOAT(newFloat, rslt); |
|
1327 |
RETURN ( newFloat ); |
|
1328 |
} |
|
1329 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1330 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1331 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1332 |
^ self class |
7403 | 1333 |
raise:#imaginaryResultSignal |
6193 | 1334 |
receiver:self |
1335 |
selector:#sqrt |
|
6195 | 1336 |
arguments:#() |
7403 | 1337 |
errorString:'bad (negative) receiver in sqrt' |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1338 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1339 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1340 |
10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1341 |
-10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1342 |
" |
6193 | 1343 |
|
6195 | 1344 |
"Modified: / 16.11.2001 / 14:14:43 / cg" |
13 | 1345 |
! ! |
1346 |
||
92 | 1347 |
!Float methodsFor:'printing & storing'! |
1 | 1348 |
|
1349 |
printString |
|
2358 | 1350 |
"return a printed representation of the receiver; |
1351 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1352 |
6 valid digits are printed. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1353 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1354 |
#printOn: as basic print mechanism." |
1 | 1355 |
|
1356 |
%{ /* NOCONTEXT */ |
|
1357 |
||
13 | 1358 |
char buffer[64]; |
1 | 1359 |
REGISTER char *cp; |
314 | 1360 |
OBJ s; |
2358 | 1361 |
char *fmt; |
1362 |
char fmtBuffer[20]; |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1363 |
int len; |
2358 | 1364 |
|
1365 |
if (__isString(@global(DefaultPrintFormat))) { |
|
7441 | 1366 |
fmt = (char *) __stringVal(@global(DefaultPrintFormat)); |
2358 | 1367 |
} else { |
7441 | 1368 |
/* |
1369 |
* in case we get called before #initialize ... |
|
1370 |
*/ |
|
1371 |
fmt = ".6"; |
|
2358 | 1372 |
} |
1373 |
||
1374 |
/* |
|
1375 |
* build a printf format string |
|
1376 |
*/ |
|
1377 |
fmtBuffer[0] = '%'; |
|
1378 |
strncpy(fmtBuffer+1, fmt, 10); |
|
1379 |
#ifdef SYSV |
|
1380 |
strcat(fmtBuffer, "lg"); |
|
1381 |
#else |
|
1382 |
strcat(fmtBuffer, "G"); |
|
1383 |
#endif |
|
314 | 1384 |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1385 |
__BEGIN_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1386 |
len = snprintf(buffer, sizeof(buffer), fmtBuffer, __floatVal(self)); |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1387 |
__END_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1388 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1389 |
if (len >= 0 && len < sizeof(buffer)-3) { |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1390 |
/* |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1391 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1392 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1393 |
*/ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1394 |
for (cp = buffer; *cp; cp++) { |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1395 |
if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1396 |
} |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1397 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
9124 | 1398 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
1399 |
*cp++ = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1400 |
} else { |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1401 |
*cp++ = '.'; |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1402 |
} |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1403 |
*cp++ = '0'; |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1404 |
*cp = '\0'; |
8302 | 1405 |
} else { |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1406 |
if (cp && (*cp == '.')) { |
9124 | 1407 |
if (__isCharacter(@global(DecimalPointCharacterForPrinting))) { |
1408 |
*cp = __intVal(__characterVal(@global(DecimalPointCharacterForPrinting))); |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1409 |
} |
8302 | 1410 |
} |
1411 |
} |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1412 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1413 |
s = __MKSTRING(buffer); |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1414 |
if (s != nil) { |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1415 |
RETURN (s); |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1416 |
} |
314 | 1417 |
} |
1418 |
%}. |
|
1419 |
" |
|
1420 |
memory allocation (for the new string) failed. |
|
1421 |
When we arrive here, there was no memory, even after a garbage collect. |
|
1422 |
This means, that the VM wanted to get some more memory from the |
|
1423 |
OS, which was not kind enough to give it. |
|
1424 |
Bad luck - you should increase the swap space on your machine. |
|
1425 |
" |
|
1426 |
^ ObjectMemory allocationFailureSignal raise. |
|
1427 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1428 |
" |
7441 | 1429 |
1.0 printString |
1430 |
1.234 printString |
|
1431 |
1e10 printString |
|
1432 |
1.2e3 printString |
|
1433 |
1.2e30 printString |
|
1434 |
(1.0 uncheckedDivide:0) printString |
|
1435 |
(0.0 uncheckedDivide:0) printString |
|
8302 | 1436 |
|
1437 |
DecimalPointCharacter := $,. |
|
1438 |
1.234 printString. |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1439 |
1.0 printString. |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1440 |
1e10 printString. |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1441 |
1.2e3 printString. |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1442 |
1.2e30 printString. |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1443 |
(1.0 uncheckedDivide:0) printString. |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1444 |
(0.0 uncheckedDivide:0) printString. |
8302 | 1445 |
DecimalPointCharacter := $. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1446 |
" |
1 | 1447 |
! |
1448 |
||
1449 |
printfPrintString:formatString |
|
7746 | 1450 |
"non-standard: return a printed representation of the receiver |
1 | 1451 |
as specified by formatString, which is defined by printf. |
31 | 1452 |
If you use this, be aware, that specifying doubles differs on |
1 | 1453 |
systems; on SYSV machines you have to give something like %lf, |
13 | 1454 |
while on BSD systems the format string has to be %F. |
31 | 1455 |
Also, the resulting string may not be longer than 255 bytes - |
54 | 1456 |
since thats the (static) size of the buffer. |
1457 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 1458 |
|
13 | 1459 |
%{ /* STACK: 400 */ |
1 | 1460 |
char buffer[256]; |
314 | 1461 |
OBJ s; |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1462 |
int len; |
1 | 1463 |
|
54 | 1464 |
if (__isString(formatString)) { |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1465 |
/* |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1466 |
* actually only needed on sparc: since thisContext is |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1467 |
* in a global register, which gets destroyed by printf, |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1468 |
* manually save it here - very stupid ... |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1469 |
*/ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1470 |
__BEGIN_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1471 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1472 |
len = snprintf(buffer, sizeof(buffer), __stringVal(formatString), __floatVal(self)); |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1473 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1474 |
__END_PROTECT_REGISTERS__ |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1475 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1476 |
if (len < 0) goto fail; |
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1477 |
|
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1478 |
s = __MKSTRING_L(buffer, len); |
7355 | 1479 |
if (s != nil) { |
1480 |
RETURN (s); |
|
1481 |
} |
|
1 | 1482 |
} |
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1483 |
fail: ; |
314 | 1484 |
%}. |
1 | 1485 |
self primitiveFailed |
1486 |
||
7355 | 1487 |
" |
1488 |
Float pi printfPrintString:'%%lg -> %lg' |
|
1489 |
Float pi printfPrintString:'%%lf -> %lf' |
|
8417
dcba76518224
Security: use snprintf() instead of sprintf() to avoid overwrites.
Stefan Vogel <sv@exept.de>
parents:
8302
diff
changeset
|
1490 |
Float pi printfPrintString:'%%7.15lg -> %7.15lg' |
7355 | 1491 |
Float pi printfPrintString:'%%7.5lf -> %7.5lf' |
1492 |
Float pi printfPrintString:'%%G -> %G' |
|
1493 |
Float pi printfPrintString:'%%F -> %F' |
|
1494 |
Float pi printfPrintString:'%%7.5G -> %7.5G' |
|
1495 |
Float pi printfPrintString:'%%7.5F -> %7.5F' |
|
1496 |
" |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1497 |
! |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1498 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1499 |
storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1500 |
"return a printed representation of the receiver; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1501 |
all valid digits are printed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1502 |
LimitedPrecisonReal and its subclasses use #storeString instead of |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1503 |
#storeOn: as basic print mechanism." |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1504 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1505 |
%{ /* NOCONTEXT */ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1506 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1507 |
char buffer[64]; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1508 |
REGISTER char *cp; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1509 |
OBJ s; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1510 |
int len; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1511 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1512 |
__BEGIN_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1513 |
#ifdef SYSV |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1514 |
len = snprintf(buffer, sizeof(buffer), "%.14lg", __floatVal(self)); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1515 |
#else |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1516 |
len = snprintf(buffer, sizeof(buffer), "%.14G", __floatVal(self)); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1517 |
#endif |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1518 |
__END_PROTECT_REGISTERS__ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1519 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1520 |
if (len >= 0 && len < sizeof(buffer)-3) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1521 |
/* |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1522 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1523 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1524 |
*/ |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1525 |
for (cp = buffer; *cp; cp++) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1526 |
if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1527 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1528 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1529 |
*cp++ = '.'; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1530 |
*cp++ = '0'; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1531 |
*cp = '\0'; |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1532 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1533 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1534 |
s = __MKSTRING(buffer); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1535 |
if (s != nil) { |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1536 |
RETURN (s); |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1537 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1538 |
} |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1539 |
%}. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1540 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1541 |
memory allocation (for the new string) failed. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1542 |
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:
8417
diff
changeset
|
1543 |
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:
8417
diff
changeset
|
1544 |
OS, which was not kind enough to give it. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1545 |
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:
8417
diff
changeset
|
1546 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1547 |
^ ObjectMemory allocationFailureSignal raise. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1548 |
|
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1549 |
" |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1550 |
1.0 storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1551 |
1.234 storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1552 |
1e10 storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1553 |
1.2e3 storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1554 |
1.2e30 storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1555 |
Float pi storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1556 |
(1.0 uncheckedDivide:0) storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1557 |
(0.0 uncheckedDivide:0) storeString |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1558 |
|
9124 | 1559 |
notice that the storeString is NOT affected by DecimalPointCharacterForPrinting: |
1560 |
||
1561 |
DecimalPointCharacterForPrinting := $,. |
|
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1562 |
1.234 storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1563 |
1.0 storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1564 |
1e10 storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1565 |
1.2e3 storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1566 |
1.2e30 storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1567 |
(1.0 uncheckedDivide:0) storeString. |
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1568 |
(0.0 uncheckedDivide:0) storeString. |
9124 | 1569 |
DecimalPointCharacterForPrinting := $. |
8422
c206b4711b6e
Define #storeString to not use DecimalPointCharacter and to
Stefan Vogel <sv@exept.de>
parents:
8417
diff
changeset
|
1570 |
" |
1 | 1571 |
! ! |
701 | 1572 |
|
7258 | 1573 |
!Float methodsFor:'private-accessing'! |
701 | 1574 |
|
1575 |
basicAt:index |
|
1576 |
"return an internal byte of the float. |
|
1577 |
The value returned here depends on byte order, float representation etc. |
|
1578 |
Therefore, this method should be used strictly private. |
|
1579 |
||
1580 |
Notice: |
|
7217 | 1581 |
the need to redefine this method here is due to the |
1582 |
inability of many machines to store floats in non-double aligned memory. |
|
1583 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
1584 |
and the actual float is stored at index 5 .. 12. |
|
1585 |
To hide this at one place, this method knows about that, and returns |
|
1586 |
values as if this filler wasnt present." |
|
701 | 1587 |
|
1588 |
%{ /* NOCONTEXT */ |
|
1589 |
||
1590 |
register int indx; |
|
1591 |
unsigned char *cp; |
|
1592 |
||
1593 |
/* |
|
1594 |
* notice the missing test for self being a nonNilObject - |
|
1595 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1596 |
* and SmallInteger |
|
1597 |
*/ |
|
1598 |
if (__isSmallInteger(index)) { |
|
7217 | 1599 |
indx = __intVal(index) - 1; |
1600 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
1601 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
8913 | 1602 |
RETURN ( __mkSmallInteger(cp[indx] & 0xFF) ); |
7217 | 1603 |
} |
701 | 1604 |
} |
1605 |
%}. |
|
7217 | 1606 |
^ self indexNotIntegerOrOutOfBounds:index |
701 | 1607 |
! |
1608 |
||
1609 |
basicAt:index put:value |
|
1610 |
"set an internal byte of the float. |
|
1611 |
The value to be stored here depends on byte order, float representation etc. |
|
1612 |
Therefore, this method should be used strictly private. |
|
1613 |
||
1614 |
Notice: |
|
7217 | 1615 |
the need to redefine this method here is due to the |
1616 |
inability of many machines to store floats in non-double aligned memory. |
|
1617 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
1618 |
and the actual float is stored at index 5 .. 12. |
|
1619 |
To hide this at one place, this method knows about that, and returns |
|
1620 |
values as if this filler wasnt present." |
|
701 | 1621 |
|
1622 |
%{ /* NOCONTEXT */ |
|
1623 |
register int indx, val; |
|
1624 |
unsigned char *cp; |
|
1625 |
||
1626 |
/* |
|
1627 |
* notice the missing test for self being a nonNilObject - |
|
1628 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1629 |
* and SmallInteger |
|
1630 |
*/ |
|
1631 |
if (__bothSmallInteger(index, value)) { |
|
7217 | 1632 |
val = __intVal(value); |
1633 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1634 |
indx = __intVal(index) - 1; |
|
1635 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
1636 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
1637 |
cp[indx] = val; |
|
1638 |
RETURN ( value ); |
|
1639 |
} |
|
1640 |
} |
|
701 | 1641 |
} |
1642 |
%}. |
|
1643 |
value isInteger ifFalse:[ |
|
7217 | 1644 |
" |
1645 |
the object to store should be an integer number |
|
1646 |
" |
|
1647 |
^ self elementNotInteger |
|
701 | 1648 |
]. |
1649 |
(value between:0 and:255) ifFalse:[ |
|
7217 | 1650 |
" |
1651 |
the object to store must be a bytes value |
|
1652 |
" |
|
1653 |
^ self elementBoundsError:value |
|
701 | 1654 |
]. |
7217 | 1655 |
^ self indexNotIntegerOrOutOfBounds:index |
5557 | 1656 |
! ! |
1657 |
||
1658 |
!Float methodsFor:'queries'! |
|
4592 | 1659 |
|
1660 |
basicSize |
|
1661 |
"return the size in bytes of the float. |
|
1662 |
||
1663 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1664 |
the need to redefine this method here is due to the |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1665 |
inability of many machines to store floats in non-double aligned memory. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1666 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1667 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1668 |
To hide this at one place, this method knows about that, and returns |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1669 |
values as if this filler wasnt present." |
4592 | 1670 |
|
1671 |
%{ /* NOCONTEXT */ |
|
1672 |
||
8913 | 1673 |
RETURN (__mkSmallInteger(sizeof(double))); |
4592 | 1674 |
%}. |
701 | 1675 |
! ! |
1676 |
||
3896 | 1677 |
!Float methodsFor:'special access'! |
1678 |
||
1679 |
exponent |
|
1680 |
"extract a normalized floats exponent. |
|
1681 |
The returned value depends on the float-representation of |
|
1682 |
the underlying machine and is therefore highly unportable. |
|
1683 |
This is not for general use. |
|
1684 |
This assumes that the mantissa is normalized to |
|
1685 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1686 |
||
1687 |
%{ /* NOCONTEXT */ |
|
1688 |
||
1689 |
double frexp(); |
|
1690 |
double frac; |
|
8913 | 1691 |
int exp; |
3896 | 1692 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1693 |
__threadErrno = 0; |
3896 | 1694 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1695 |
if (__threadErrno == 0) { |
8913 | 1696 |
RETURN (__mkSmallInteger(exp)); |
3896 | 1697 |
} |
1698 |
%}. |
|
1699 |
^ self primitiveFailed |
|
1700 |
||
1701 |
" |
|
1702 |
1.0 exponent |
|
1703 |
2.0 exponent |
|
1704 |
3.0 exponent |
|
1705 |
4.0 exponent |
|
1706 |
0.5 exponent |
|
1707 |
0.4 exponent |
|
1708 |
0.25 exponent |
|
1709 |
0.00000011111 exponent |
|
1710 |
" |
|
1711 |
! |
|
1712 |
||
1713 |
mantissa |
|
1714 |
"extract a normalized floats mantissa. |
|
1715 |
The returned value depends on the float-representation of |
|
1716 |
the underlying machine and is therefore highly unportable. |
|
1717 |
This is not for general use. |
|
1718 |
This assumes that the mantissa is normalized to |
|
1719 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1720 |
||
1721 |
%{ /* NOCONTEXT */ |
|
1722 |
||
1723 |
double frexp(); |
|
1724 |
double frac; |
|
8913 | 1725 |
int exp; |
3896 | 1726 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1727 |
__threadErrno = 0; |
3896 | 1728 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1729 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1730 |
RETURN (__MKFLOAT(frac)); |
3896 | 1731 |
} |
1732 |
%}. |
|
1733 |
^ self primitiveFailed |
|
1734 |
||
1735 |
" |
|
1736 |
1.0 exponent |
|
1737 |
1.0 mantissa |
|
1738 |
||
1739 |
0.25 exponent |
|
1740 |
0.25 mantissa |
|
1741 |
||
1742 |
0.00000011111 exponent |
|
1743 |
0.00000011111 mantissa |
|
1744 |
" |
|
1745 |
! ! |
|
1746 |
||
701 | 1747 |
!Float methodsFor:'testing'! |
1748 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1749 |
isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1750 |
"return true, if the receiver is a finite float |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1751 |
i.e. not NaN and not infinite." |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1752 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1753 |
%{ /* NOCONTEXT */ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1754 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1755 |
double dV = __floatVal(self); |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1756 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1757 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1758 |
* notice: on machines which do not provide |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1759 |
* a finite() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1760 |
* 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
|
1761 |
*/ |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1762 |
if (isfinite(dV)) { |
6344 | 1763 |
RETURN (true); |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1764 |
} |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1765 |
%}. |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1766 |
^ false |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1767 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1768 |
" |
6344 | 1769 |
1.0 isFinite |
1770 |
Float NaN isFinite |
|
1771 |
Float infinity isFinite |
|
1772 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
1773 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1774 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1775 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1776 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1777 |
isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1778 |
"return true, if the receiver is an infinite float (Inf). |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1779 |
These are not created by ST/X float operations (they raise an exception); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1780 |
however, inline C-code could produce them ... |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1781 |
Redefined here for speed" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1782 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1783 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1784 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1785 |
double dV = __floatVal(self); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1786 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1787 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1788 |
* notice: on machines which do not provide |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1789 |
* finite() & isnan() macros or functions (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1790 |
* 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
|
1791 |
*/ |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1792 |
#if defined(isinf) |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1793 |
if (isinf(dV)) { RETURN (true); } |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1794 |
#else |
8980
abee9fcb0385
cleanup isfinite() and isnan() - usage (HPUX)
Stefan Vogel <sv@exept.de>
parents:
8913
diff
changeset
|
1795 |
if (!isfinite(dV) && !isnan(dV)) { RETURN (true); } |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1796 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1797 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1798 |
^ false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1799 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1800 |
" |
7420 | 1801 |
1.0 isInfinite |
1802 |
(0.0 uncheckedDivide: 0.0) isInfinite |
|
1803 |
(1.0 uncheckedDivide: 0.0) isInfinite |
|
1804 |
(-1.0 uncheckedDivide: 0.0) isInfinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1805 |
" |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1806 |
! |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1807 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1808 |
isLiteral |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1809 |
"return true, if the receiver can be used as a literal constant in ST syntax |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1810 |
(i.e. can be used in constant arrays)" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1811 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1812 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1813 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1814 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1815 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1816 |
|
2387 | 1817 |
isNaN |
1818 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
1819 |
These are not created by ST/X float operations (they raise an exception); |
|
1820 |
however, inline C-code could produce them ..." |
|
1821 |
||
1822 |
%{ /* NOCONTEXT */ |
|
1823 |
||
3139 | 1824 |
double dV = (__floatVal(self)); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1825 |
|
7420 | 1826 |
if (isnan(dV)) { |
1827 |
RETURN (true); |
|
1828 |
} |
|
2392 | 1829 |
%}. |
1830 |
^ false |
|
3139 | 1831 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1832 |
" |
7420 | 1833 |
1.0 isNaN |
1834 |
(0.0 uncheckedDivide: 0.0) isNaN |
|
1835 |
(1.0 uncheckedDivide: 0.0) isNaN |
|
1836 |
(-1.0 uncheckedDivide: 0.0) isNaN |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1837 |
" |
2387 | 1838 |
! |
1839 |
||
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1840 |
isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1841 |
"many systems have two float.Pnt zeros" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1842 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1843 |
%{ |
8901
824a89d0b5c7
alpha64 vs. POINTER_SIZE cleanup
Claus Gittinger <cg@exept.de>
parents:
8635
diff
changeset
|
1844 |
#if defined(__i386__) && defined(LINUX) |
7441 | 1845 |
unsigned int biasedExponent; |
1846 |
||
1847 |
biasedExponent = ((short *)(__ByteArrayInstPtr(self)->ba_element))[3] & 0xFF70; |
|
1848 |
RETURN ((biasedExponent == 0x8000) ? true : false ); |
|
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1849 |
#endif |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1850 |
%}. |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1851 |
^ super isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1852 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1853 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1854 |
0.0 isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1855 |
-0.0 isNegativeZero |
7441 | 1856 |
-1.0 isNegativeZero |
1857 |
1.0 isNegativeZero |
|
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1858 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1859 |
! |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1860 |
|
701 | 1861 |
negative |
1862 |
"return true if the receiver is less than zero" |
|
1863 |
||
1864 |
%{ /* NOCONTEXT */ |
|
1865 |
||
1133 | 1866 |
RETURN ( (__floatVal(self) < 0.0) ? true : false ); |
5411 | 1867 |
%}. |
701 | 1868 |
! |
1869 |
||
5357 | 1870 |
numberOfBits |
1871 |
"return the size (in bits) of the real; |
|
1872 |
typically, 64 is returned here, |
|
1873 |
but who knows ..." |
|
1874 |
||
1875 |
%{ /* NOCONTEXT */ |
|
1876 |
||
8913 | 1877 |
RETURN (__mkSmallInteger (sizeof(double) * 8)); |
5357 | 1878 |
%} |
1879 |
||
1880 |
" |
|
1881 |
1.2 numberOfBits |
|
1882 |
1.2 asShortFloat numberOfBits |
|
1883 |
" |
|
1884 |
! |
|
1885 |
||
701 | 1886 |
positive |
1887 |
"return true if the receiver is greater or equal to zero" |
|
1888 |
||
1889 |
%{ /* NOCONTEXT */ |
|
1890 |
||
1133 | 1891 |
RETURN ( (__floatVal(self) >= 0.0) ? true : false ); |
701 | 1892 |
%} |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1893 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1894 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1895 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1896 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1897 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1898 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1899 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1900 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1901 |
%} |
701 | 1902 |
! ! |
1903 |
||
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1904 |
!Float methodsFor:'tracing'! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1905 |
|
4682 | 1906 |
traceInto:aRequestor level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1907 |
"double dispatch into tracer, passing my type implicitely in the selector" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1908 |
|
4682 | 1909 |
^ aRequestor traceFloat:self level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1910 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1911 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1912 |
! ! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1913 |
|
7385 | 1914 |
!Float methodsFor:'trigonometric'! |
1915 |
||
1916 |
arcCos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1917 |
"return the arccosine of the receiver (as radians). |
7385 | 1918 |
Raises an exception, if the receiver is not in -1..1" |
1919 |
||
1920 |
%{ /* NOCONTEXT */ |
|
1921 |
||
1922 |
double val, rslt; |
|
1923 |
OBJ newFloat; |
|
1924 |
||
1925 |
val = __floatVal(self); |
|
1926 |
||
1927 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
|
1928 |
if ((val >= -1.0) && (val <= 1.0)) |
|
1929 |
#endif |
|
1930 |
{ |
|
1931 |
__threadErrno = 0; |
|
1932 |
rslt = acos(val); |
|
7393 | 1933 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 1934 |
{ |
1935 |
if (__threadErrno == 0) { |
|
1936 |
__qMKFLOAT(newFloat, rslt); |
|
1937 |
RETURN ( newFloat ); |
|
1938 |
} |
|
1939 |
} |
|
1940 |
} |
|
1941 |
%}. |
|
1942 |
^ self class |
|
1943 |
raise:#domainErrorSignal |
|
1944 |
receiver:self |
|
1945 |
selector:#arcCos |
|
1946 |
arguments:#() |
|
1947 |
errorString:'bad receiver in arcCos' |
|
1948 |
||
1949 |
" |
|
1950 |
-10 arcCos |
|
1951 |
1 arcCos |
|
1952 |
" |
|
1953 |
||
1954 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
1955 |
! |
|
1956 |
||
1957 |
arcCosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1958 |
"return the hyperbolic arccosine of the receiver." |
7385 | 1959 |
|
7410 | 1960 |
|useFallBack| |
1961 |
||
1962 |
%{ |
|
1963 |
#ifdef NO_ACOSH |
|
1964 |
useFallBack = true; |
|
1965 |
#else |
|
7385 | 1966 |
double val, rslt; |
1967 |
OBJ newFloat; |
|
1968 |
||
1969 |
val = __floatVal(self); |
|
1970 |
||
7410 | 1971 |
# ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1972 |
if (val >= 1.0) |
7410 | 1973 |
# endif |
7385 | 1974 |
{ |
1975 |
__threadErrno = 0; |
|
1976 |
rslt = acosh(val); |
|
7393 | 1977 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 1978 |
{ |
1979 |
if (__threadErrno == 0) { |
|
1980 |
__qMKFLOAT(newFloat, rslt); |
|
1981 |
RETURN ( newFloat ); |
|
1982 |
} |
|
1983 |
} |
|
1984 |
} |
|
7410 | 1985 |
#endif |
7385 | 1986 |
%}. |
7410 | 1987 |
useFallBack notNil ifTrue:[ |
1988 |
^ super arcCosh |
|
1989 |
]. |
|
1990 |
||
7385 | 1991 |
^ self class |
1992 |
raise:#domainErrorSignal |
|
1993 |
receiver:self |
|
1994 |
selector:#arcCosh |
|
1995 |
arguments:#() |
|
1996 |
errorString:'bad receiver in arcCosh' |
|
1997 |
||
1998 |
" |
|
1999 |
-10.0 arcCosh |
|
2000 |
1.0 arcCosh |
|
2001 |
" |
|
2002 |
||
2003 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
2004 |
! |
|
2005 |
||
2006 |
arcSin |
|
2007 |
"return the arcsine of myself (I am interpreted as radians). |
|
2008 |
Raises an exception, if the receiver is not in -1..1" |
|
2009 |
||
2010 |
%{ /* NOCONTEXT */ |
|
2011 |
||
2012 |
double val, rslt; |
|
2013 |
OBJ newFloat; |
|
2014 |
||
2015 |
val = __floatVal(self); |
|
2016 |
||
2017 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
|
2018 |
if ((val >= -1.0) && (val <= 1.0)) |
|
2019 |
#endif |
|
2020 |
{ |
|
2021 |
__threadErrno = 0; |
|
2022 |
rslt = asin(val); |
|
7393 | 2023 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 2024 |
{ |
2025 |
if (__threadErrno == 0) { |
|
2026 |
__qMKFLOAT(newFloat, rslt); |
|
2027 |
RETURN ( newFloat ); |
|
2028 |
} |
|
2029 |
} |
|
2030 |
} |
|
2031 |
%}. |
|
2032 |
^ self class |
|
2033 |
raise:#domainErrorSignal |
|
2034 |
receiver:self |
|
2035 |
selector:#arcSin |
|
2036 |
arguments:#() |
|
2037 |
errorString:'bad receiver in arcSin' |
|
2038 |
||
2039 |
" |
|
2040 |
-10 arcSin |
|
2041 |
1 arcSin |
|
2042 |
" |
|
2043 |
||
2044 |
"Modified: / 16.11.2001 / 14:14:18 / cg" |
|
2045 |
! |
|
2046 |
||
2047 |
arcSinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2048 |
"return the hyperbolic arcsine of the receiver." |
7385 | 2049 |
|
7410 | 2050 |
|useFallBack| |
2051 |
%{ |
|
2052 |
#ifdef NO_ASINH |
|
2053 |
useFallBack = true; |
|
2054 |
#else |
|
7385 | 2055 |
double val, rslt; |
2056 |
OBJ newFloat; |
|
2057 |
||
2058 |
val = __floatVal(self); |
|
2059 |
||
7410 | 2060 |
# ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2061 |
if (val >= 1.0) |
7410 | 2062 |
# endif |
7385 | 2063 |
{ |
2064 |
__threadErrno = 0; |
|
2065 |
rslt = asinh(val); |
|
7393 | 2066 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 2067 |
{ |
2068 |
if (__threadErrno == 0) { |
|
2069 |
__qMKFLOAT(newFloat, rslt); |
|
2070 |
RETURN ( newFloat ); |
|
2071 |
} |
|
2072 |
} |
|
2073 |
} |
|
7410 | 2074 |
#endif |
7385 | 2075 |
%}. |
7410 | 2076 |
useFallBack notNil ifTrue:[ |
2077 |
^ super arcSinh |
|
2078 |
]. |
|
7385 | 2079 |
^ self class |
2080 |
raise:#domainErrorSignal |
|
2081 |
receiver:self |
|
2082 |
selector:#arcSinh |
|
2083 |
arguments:#() |
|
2084 |
errorString:'bad receiver in arcSinh' |
|
2085 |
||
2086 |
" |
|
2087 |
-10.0 arcSinh |
|
2088 |
1.0 arcSinh |
|
2089 |
" |
|
2090 |
! |
|
2091 |
||
2092 |
arcTan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2093 |
"return the arctangent of the receiver (as radians)" |
7385 | 2094 |
|
2095 |
%{ /* NOCONTEXT */ |
|
2096 |
||
2097 |
double rslt; |
|
2098 |
OBJ newFloat; |
|
2099 |
||
2100 |
__threadErrno = 0; |
|
2101 |
rslt = atan(__floatVal(self)); |
|
7393 | 2102 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2103 |
{ |
|
2104 |
if (__threadErrno == 0) { |
|
2105 |
__qMKFLOAT(newFloat, rslt); |
|
2106 |
RETURN ( newFloat ); |
|
2107 |
} |
|
7385 | 2108 |
} |
2109 |
%}. |
|
2110 |
^ self class |
|
2111 |
raise:#domainErrorSignal |
|
2112 |
receiver:self |
|
2113 |
selector:#arcTan |
|
2114 |
arguments:#() |
|
2115 |
errorString:'bad receiver in arcTan' |
|
2116 |
||
2117 |
"Modified: / 16.11.2001 / 14:14:22 / cg" |
|
2118 |
! |
|
2119 |
||
2120 |
arcTanh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2121 |
"return the hyperbolic arctangent of the receiver." |
7385 | 2122 |
|
7410 | 2123 |
|useFallBack| |
2124 |
%{ |
|
2125 |
#ifdef NO_ATANH |
|
2126 |
useFallBack = true; |
|
2127 |
#else |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2128 |
double val, rslt; |
7385 | 2129 |
OBJ newFloat; |
2130 |
||
2131 |
__threadErrno = 0; |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2132 |
val = __floatVal(self); |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2133 |
# ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2134 |
if ((val >= -1.0) && (val <= 1.0)) |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2135 |
# endif |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2136 |
{ |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2137 |
rslt = atanh(__floatVal(self)); |
7393 | 2138 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2139 |
{ |
|
2140 |
if (__threadErrno == 0) { |
|
2141 |
__qMKFLOAT(newFloat, rslt); |
|
2142 |
RETURN ( newFloat ); |
|
2143 |
} |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2144 |
} |
7385 | 2145 |
} |
7410 | 2146 |
#endif |
7385 | 2147 |
%}. |
7410 | 2148 |
useFallBack notNil ifTrue:[ |
2149 |
^ super arcTanh |
|
2150 |
]. |
|
7385 | 2151 |
^ self class |
2152 |
raise:#domainErrorSignal |
|
2153 |
receiver:self |
|
2154 |
selector:#arcTanh |
|
2155 |
arguments:#() |
|
2156 |
errorString:'bad receiver in arcTanh' |
|
2157 |
! |
|
2158 |
||
2159 |
cos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2160 |
"return the cosine of the receiver (interpreted as radians)" |
7385 | 2161 |
|
2162 |
%{ /* NOCONTEXT */ |
|
2163 |
||
2164 |
double rslt; |
|
2165 |
OBJ newFloat; |
|
2166 |
||
2167 |
__threadErrno = 0; |
|
2168 |
rslt = cos(__floatVal(self)); |
|
7393 | 2169 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2170 |
{ |
|
2171 |
if (__threadErrno == 0) { |
|
2172 |
__qMKFLOAT(newFloat, rslt); |
|
2173 |
RETURN ( newFloat ); |
|
2174 |
} |
|
7385 | 2175 |
} |
2176 |
%}. |
|
2177 |
^ self class |
|
2178 |
raise:#domainErrorSignal |
|
2179 |
receiver:self |
|
2180 |
selector:#cos |
|
2181 |
arguments:#() |
|
2182 |
errorString:'bad receiver in cos' |
|
2183 |
||
2184 |
"Modified: / 16.11.2001 / 14:14:26 / cg" |
|
2185 |
! |
|
2186 |
||
2187 |
cosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2188 |
"return the hyperbolic cosine of the receiver" |
7385 | 2189 |
|
2190 |
%{ /* NOCONTEXT */ |
|
2191 |
||
2192 |
double rslt; |
|
2193 |
OBJ newFloat; |
|
2194 |
||
2195 |
__threadErrno = 0; |
|
2196 |
rslt = cosh(__floatVal(self)); |
|
7393 | 2197 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2198 |
{ |
|
2199 |
if (__threadErrno == 0) { |
|
2200 |
__qMKFLOAT(newFloat, rslt); |
|
2201 |
RETURN ( newFloat ); |
|
2202 |
} |
|
7385 | 2203 |
} |
2204 |
%}. |
|
2205 |
^ self class |
|
2206 |
raise:#domainErrorSignal |
|
2207 |
receiver:self |
|
2208 |
selector:#cosh |
|
2209 |
arguments:#() |
|
2210 |
errorString:'bad receiver in cosh' |
|
2211 |
! |
|
2212 |
||
2213 |
sin |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2214 |
"return the sine of the receiver (interpreted as radians)" |
7385 | 2215 |
|
2216 |
%{ /* NOCONTEXT */ |
|
2217 |
||
2218 |
double rslt; |
|
2219 |
OBJ newFloat; |
|
2220 |
||
2221 |
__threadErrno = 0; |
|
2222 |
rslt = sin(__floatVal(self)); |
|
7393 | 2223 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2224 |
{ |
|
2225 |
if (__threadErrno == 0) { |
|
2226 |
__qMKFLOAT(newFloat, rslt); |
|
2227 |
RETURN ( newFloat ); |
|
2228 |
} |
|
7385 | 2229 |
} |
2230 |
%}. |
|
2231 |
^ self class |
|
2232 |
raise:#domainErrorSignal |
|
2233 |
receiver:self |
|
2234 |
selector:#sin |
|
2235 |
arguments:#() |
|
2236 |
errorString:'bad receiver in sin' |
|
2237 |
||
2238 |
"Modified: / 16.11.2001 / 14:14:37 / cg" |
|
2239 |
! |
|
2240 |
||
2241 |
sinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2242 |
"return the hyperbolic sine of the receiver" |
7385 | 2243 |
|
2244 |
%{ /* NOCONTEXT */ |
|
2245 |
||
2246 |
double rslt; |
|
2247 |
OBJ newFloat; |
|
2248 |
||
2249 |
__threadErrno = 0; |
|
2250 |
rslt = sinh(__floatVal(self)); |
|
7393 | 2251 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2252 |
{ |
|
2253 |
if (__threadErrno == 0) { |
|
2254 |
__qMKFLOAT(newFloat, rslt); |
|
2255 |
RETURN ( newFloat ); |
|
2256 |
} |
|
7385 | 2257 |
} |
2258 |
%}. |
|
2259 |
^ self class |
|
2260 |
raise:#domainErrorSignal |
|
2261 |
receiver:self |
|
2262 |
selector:#sinh |
|
2263 |
arguments:#() |
|
2264 |
errorString:'bad receiver in sinh' |
|
2265 |
! |
|
2266 |
||
2267 |
tan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2268 |
"return the tangens of the receiver (interpreted as radians)" |
7385 | 2269 |
|
2270 |
%{ /* NOCONTEXT */ |
|
2271 |
||
2272 |
double rslt; |
|
2273 |
OBJ newFloat; |
|
2274 |
||
2275 |
__threadErrno = 0; |
|
2276 |
rslt = tan(__floatVal(self)); |
|
7393 | 2277 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2278 |
{ |
|
2279 |
if (__threadErrno == 0) { |
|
2280 |
__qMKFLOAT(newFloat, rslt); |
|
2281 |
RETURN ( newFloat ); |
|
2282 |
} |
|
7385 | 2283 |
} |
2284 |
%}. |
|
2285 |
^ self class |
|
2286 |
raise:#domainErrorSignal |
|
2287 |
receiver:self |
|
2288 |
selector:#tan |
|
2289 |
arguments:#() |
|
2290 |
errorString:'bad receiver in tan' |
|
2291 |
||
2292 |
"Modified: / 16.11.2001 / 14:14:49 / cg" |
|
2293 |
! |
|
2294 |
||
2295 |
tanh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2296 |
"return the hyperbolic tangens of the receiver" |
7385 | 2297 |
|
2298 |
%{ /* NOCONTEXT */ |
|
2299 |
||
2300 |
double rslt; |
|
2301 |
OBJ newFloat; |
|
2302 |
||
2303 |
__threadErrno = 0; |
|
2304 |
rslt = tanh(__floatVal(self)); |
|
7393 | 2305 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2306 |
{ |
|
2307 |
if (__threadErrno == 0) { |
|
2308 |
__qMKFLOAT(newFloat, rslt); |
|
2309 |
RETURN ( newFloat ); |
|
2310 |
} |
|
7385 | 2311 |
} |
2312 |
%}. |
|
2313 |
^ self class |
|
2314 |
raise:#domainErrorSignal |
|
2315 |
receiver:self |
|
2316 |
selector:#tanh |
|
2317 |
arguments:#() |
|
2318 |
errorString:'bad receiver in tanh' |
|
2319 |
! ! |
|
2320 |
||
5552 | 2321 |
!Float methodsFor:'truncation & rounding'! |
701 | 2322 |
|
2323 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2324 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 2325 |
|
2326 |
|val| |
|
2327 |
||
2328 |
%{ |
|
2329 |
double dVal; |
|
2330 |
||
7355 | 2331 |
dVal = ceil(__floatVal(self)); |
701 | 2332 |
/* |
2333 |
* ST-80 (and X3J20) returns integer. |
|
2334 |
*/ |
|
2335 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
8913 | 2336 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 2337 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2338 |
__qMKFLOAT(val, dVal); |
701 | 2339 |
%}. |
2340 |
^ val asInteger |
|
2341 |
! |
|
2342 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2343 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2344 |
"return the smallest integer-valued float greater or equal to the receiver. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2345 |
This is much like #ceiling, but avoids a (possibly expensive) conversion |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2346 |
of the result to an integer. |
7355 | 2347 |
It may be useful, if the result is to be further used in another float-operation." |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2348 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2349 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2350 |
double dVal; |
7355 | 2351 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2352 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2353 |
dVal = ceil(__floatVal(self)); |
7355 | 2354 |
__qMKFLOAT(v, dVal); |
2355 |
RETURN (v); |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2356 |
%} |
7355 | 2357 |
" |
2358 |
0.5 ceilingAsFloat |
|
2359 |
-0.5 ceilingAsFloat |
|
2360 |
-1.5 ceilingAsFloat |
|
2361 |
" |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2362 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2363 |
|
701 | 2364 |
floor |
2365 |
"return the integer nearest the receiver towards negative infinity." |
|
2366 |
||
2367 |
|val| |
|
2368 |
||
2369 |
%{ |
|
2370 |
double dVal; |
|
2371 |
||
7355 | 2372 |
dVal = floor(__floatVal(self)); |
701 | 2373 |
/* |
2374 |
* ST-80 (and X3J20) returns integer. |
|
2375 |
*/ |
|
2376 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
8913 | 2377 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 2378 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2379 |
__qMKFLOAT(val, dVal); |
701 | 2380 |
%}. |
2381 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2382 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2383 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2384 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2385 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2386 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2387 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2388 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2389 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2390 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2391 |
floorAsFloat |
7355 | 2392 |
"return the integer nearest the receiver towards negative infinity as a float. |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2393 |
This is much like #floor, but avoids a (possibly expensive) conversion |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2394 |
of the result to an integer. |
7355 | 2395 |
It may be useful, if the result is to be further used in another float-operation." |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2396 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2397 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2398 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2399 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2400 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2401 |
dVal = floor(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2402 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2403 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2404 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2405 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2406 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2407 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2408 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2409 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2410 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2411 |
" |
701 | 2412 |
! |
2413 |
||
3896 | 2414 |
fractionPart |
2415 |
"extract the after-decimal fraction part. |
|
7355 | 2416 |
such that (self truncated + self fractionPart) = self" |
3896 | 2417 |
|
2418 |
%{ /* NOCONTEXT */ |
|
2419 |
||
2420 |
double modf(); |
|
2421 |
double frac, trunc; |
|
2422 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
2423 |
__threadErrno = 0; |
3896 | 2424 |
frac = modf(__floatVal(self), &trunc); |
7403 | 2425 |
if (! isnan(frac)) { |
2426 |
if (__threadErrno == 0) { |
|
2427 |
RETURN (__MKFLOAT(frac)); |
|
2428 |
} |
|
3896 | 2429 |
} |
2430 |
%}. |
|
7403 | 2431 |
^ self class |
2432 |
raise:#domainErrorSignal |
|
2433 |
receiver:self |
|
2434 |
selector:#fractionPart |
|
2435 |
arguments:#() |
|
2436 |
errorString:'bad receiver in fractionPart' |
|
3896 | 2437 |
|
2438 |
" |
|
7355 | 2439 |
1.6 fractionPart + 1.6 truncated |
2440 |
-1.6 fractionPart + -1.6 truncated |
|
2441 |
||
3896 | 2442 |
1.0 fractionPart |
2443 |
2.0 fractionPart |
|
2444 |
3.0 fractionPart |
|
2445 |
4.0 fractionPart |
|
2446 |
0.5 fractionPart |
|
2447 |
0.25 fractionPart |
|
2448 |
3.14159 fractionPart |
|
2449 |
12345673.14159 fractionPart |
|
2450 |
123456731231231231.14159 fractionPart |
|
2451 |
||
2452 |
3.14159 fractionPart + 3.14159 truncated |
|
2453 |
||
2454 |
12345673.14159 fractionPart + 12345673.14159 truncated |
|
2455 |
||
2456 |
123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated |
|
2457 |
" |
|
2458 |
! |
|
2459 |
||
701 | 2460 |
rounded |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2461 |
"return the receiver rounded to the nearest integer" |
701 | 2462 |
|
2463 |
|val| |
|
2464 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2465 |
%{ |
701 | 2466 |
double dVal; |
2467 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2468 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2469 |
if (dVal < 0.0) { |
7355 | 2470 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2471 |
} else { |
7355 | 2472 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2473 |
} |
701 | 2474 |
/* |
2475 |
* ST-80 (and X3J20) returns integer. |
|
2476 |
*/ |
|
2477 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
8913 | 2478 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 2479 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2480 |
__qMKFLOAT(val, dVal); |
701 | 2481 |
%}. |
7355 | 2482 |
^ val asInteger |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2483 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2484 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2485 |
0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2486 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2487 |
0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2488 |
-0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2489 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2490 |
-0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2491 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2492 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2493 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2494 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2495 |
"return the receiver rounded to the nearest integer as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2496 |
This is much like #rounded, but avoids a (possibly expensive) conversion |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2497 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2498 |
It may be useful, if the result is to be further used in another |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2499 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2500 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2501 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2502 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2503 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2504 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2505 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2506 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2507 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2508 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2509 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2510 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2511 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2512 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2513 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2514 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2515 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2516 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2517 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2518 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2519 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2520 |
0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2521 |
-0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2522 |
" |
701 | 2523 |
! |
2524 |
||
2525 |
truncated |
|
2526 |
"return the receiver truncated towards zero as an integer" |
|
2527 |
||
2528 |
|val| |
|
2529 |
||
2530 |
%{ |
|
2531 |
double dVal; |
|
2532 |
||
1133 | 2533 |
dVal = __floatVal(self); |
701 | 2534 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2535 |
dVal = ceil(dVal); |
701 | 2536 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2537 |
dVal = floor(dVal); |
701 | 2538 |
} |
2539 |
||
2540 |
/* |
|
2541 |
* ST-80 (and X3J20) returns integer. |
|
2542 |
*/ |
|
2543 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
8913 | 2544 |
RETURN ( __mkSmallInteger( (INT) dVal ) ); |
701 | 2545 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2546 |
__qMKFLOAT(val, dVal); |
701 | 2547 |
%}. |
2548 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2549 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2550 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2551 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2552 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2553 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2554 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2555 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2556 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2557 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2558 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2559 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2560 |
"return the receiver truncated towards zero as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2561 |
This is much like #truncated, but avoids a (possibly expensive) conversion |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2562 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2563 |
It may be useful, if the result is to be further used in another |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2564 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2565 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2566 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2567 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2568 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2569 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2570 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2571 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2572 |
dVal = ceil(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2573 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2574 |
dVal = floor(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2575 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2576 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2577 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2578 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2579 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2580 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2581 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2582 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2583 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2584 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2585 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2586 |
|
701 | 2587 |
! ! |
2588 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2589 |
!Float class methodsFor:'documentation'! |
701 | 2590 |
|
2591 |
version |
|
9150 | 2592 |
^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.161 2006-02-20 11:28:56 cg Exp $' |
701 | 2593 |
! ! |
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2594 |
|
2387 | 2595 |
Float initialize! |