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