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