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