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