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