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