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