author | Claus Gittinger <cg@exept.de> |
Tue, 11 Nov 2003 14:16:57 +0100 | |
changeset 7746 | 4a4208ef7699 |
parent 7724 | 1c8c8024c902 |
child 8302 | e13f6ce60077 |
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 |
||
340 |
#ifdef i386 /* actually: LSBFIRST */ |
|
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 */ |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
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 |
||
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 |
||
7746 | 1343 |
|
92 | 1344 |
!Float methodsFor:'printing & storing'! |
1 | 1345 |
|
1346 |
printString |
|
2358 | 1347 |
"return a printed representation of the receiver; |
1348 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1349 |
6 valid digits are printed. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1350 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1351 |
#printOn: as basic print mechanism." |
1 | 1352 |
|
1353 |
%{ /* NOCONTEXT */ |
|
1354 |
||
13 | 1355 |
char buffer[64]; |
1 | 1356 |
REGISTER char *cp; |
314 | 1357 |
OBJ s; |
2358 | 1358 |
char *fmt; |
1359 |
char fmtBuffer[20]; |
|
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 |
|
2358 | 1381 |
sprintf(buffer, fmtBuffer, __floatVal(self)); |
1 | 1382 |
|
1383 |
/* |
|
13 | 1384 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
1 | 1385 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
1386 |
*/ |
|
1387 |
for (cp = buffer; *cp; cp++) { |
|
7441 | 1388 |
if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
1 | 1389 |
} |
7441 | 1390 |
if (!*cp && (cp[-1] >= '0') && (cp[-1] <= '9')) { |
1391 |
*cp++ = '.'; |
|
1392 |
*cp++ = '0'; |
|
1393 |
*cp = '\0'; |
|
1 | 1394 |
} |
1395 |
||
1133 | 1396 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 1397 |
if (s != nil) { |
7441 | 1398 |
RETURN (s); |
314 | 1399 |
} |
1400 |
%}. |
|
1401 |
" |
|
1402 |
memory allocation (for the new string) failed. |
|
1403 |
When we arrive here, there was no memory, even after a garbage collect. |
|
1404 |
This means, that the VM wanted to get some more memory from the |
|
1405 |
OS, which was not kind enough to give it. |
|
1406 |
Bad luck - you should increase the swap space on your machine. |
|
1407 |
" |
|
1408 |
^ ObjectMemory allocationFailureSignal raise. |
|
1409 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1410 |
" |
7441 | 1411 |
1.0 printString |
1412 |
1.234 printString |
|
1413 |
1e10 printString |
|
1414 |
1.2e3 printString |
|
1415 |
1.2e30 printString |
|
1416 |
(1.0 uncheckedDivide:0) printString |
|
1417 |
(0.0 uncheckedDivide:0) printString |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1418 |
" |
1 | 1419 |
! |
1420 |
||
1421 |
printfPrintString:formatString |
|
7746 | 1422 |
"non-standard: return a printed representation of the receiver |
1 | 1423 |
as specified by formatString, which is defined by printf. |
31 | 1424 |
If you use this, be aware, that specifying doubles differs on |
1 | 1425 |
systems; on SYSV machines you have to give something like %lf, |
13 | 1426 |
while on BSD systems the format string has to be %F. |
31 | 1427 |
Also, the resulting string may not be longer than 255 bytes - |
54 | 1428 |
since thats the (static) size of the buffer. |
1429 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 1430 |
|
13 | 1431 |
%{ /* STACK: 400 */ |
1 | 1432 |
char buffer[256]; |
314 | 1433 |
OBJ s; |
1 | 1434 |
|
54 | 1435 |
if (__isString(formatString)) { |
7355 | 1436 |
sprintf(buffer, __stringVal(formatString), __floatVal(self)); |
369 | 1437 |
|
7355 | 1438 |
s = __MKSTRING(buffer COMMA_SND); |
1439 |
if (s != nil) { |
|
1440 |
RETURN (s); |
|
1441 |
} |
|
1 | 1442 |
} |
314 | 1443 |
%}. |
1 | 1444 |
self primitiveFailed |
1445 |
||
7355 | 1446 |
" |
1447 |
Float pi printfPrintString:'%%lg -> %lg' |
|
1448 |
Float pi printfPrintString:'%%lf -> %lf' |
|
1449 |
Float pi printfPrintString:'%%7.5lg -> %7.5lg' |
|
1450 |
Float pi printfPrintString:'%%7.5lf -> %7.5lf' |
|
1451 |
Float pi printfPrintString:'%%G -> %G' |
|
1452 |
Float pi printfPrintString:'%%F -> %F' |
|
1453 |
Float pi printfPrintString:'%%7.5G -> %7.5G' |
|
1454 |
Float pi printfPrintString:'%%7.5F -> %7.5F' |
|
1455 |
" |
|
1 | 1456 |
! ! |
701 | 1457 |
|
7258 | 1458 |
!Float methodsFor:'private-accessing'! |
701 | 1459 |
|
1460 |
basicAt:index |
|
1461 |
"return an internal byte of the float. |
|
1462 |
The value returned here depends on byte order, float representation etc. |
|
1463 |
Therefore, this method should be used strictly private. |
|
1464 |
||
1465 |
Notice: |
|
7217 | 1466 |
the need to redefine this method here is due to the |
1467 |
inability of many machines to store floats in non-double aligned memory. |
|
1468 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
1469 |
and the actual float is stored at index 5 .. 12. |
|
1470 |
To hide this at one place, this method knows about that, and returns |
|
1471 |
values as if this filler wasnt present." |
|
701 | 1472 |
|
1473 |
%{ /* NOCONTEXT */ |
|
1474 |
||
1475 |
register int indx; |
|
1476 |
unsigned char *cp; |
|
1477 |
||
1478 |
/* |
|
1479 |
* notice the missing test for self being a nonNilObject - |
|
1480 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1481 |
* and SmallInteger |
|
1482 |
*/ |
|
1483 |
if (__isSmallInteger(index)) { |
|
7217 | 1484 |
indx = __intVal(index) - 1; |
1485 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
1486 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
1487 |
RETURN ( __MKSMALLINT(cp[indx] & 0xFF) ); |
|
1488 |
} |
|
701 | 1489 |
} |
1490 |
%}. |
|
7217 | 1491 |
^ self indexNotIntegerOrOutOfBounds:index |
701 | 1492 |
! |
1493 |
||
1494 |
basicAt:index put:value |
|
1495 |
"set an internal byte of the float. |
|
1496 |
The value to be stored here depends on byte order, float representation etc. |
|
1497 |
Therefore, this method should be used strictly private. |
|
1498 |
||
1499 |
Notice: |
|
7217 | 1500 |
the need to redefine this method here is due to the |
1501 |
inability of many machines to store floats in non-double aligned memory. |
|
1502 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
1503 |
and the actual float is stored at index 5 .. 12. |
|
1504 |
To hide this at one place, this method knows about that, and returns |
|
1505 |
values as if this filler wasnt present." |
|
701 | 1506 |
|
1507 |
%{ /* NOCONTEXT */ |
|
1508 |
register int indx, val; |
|
1509 |
unsigned char *cp; |
|
1510 |
||
1511 |
/* |
|
1512 |
* notice the missing test for self being a nonNilObject - |
|
1513 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1514 |
* and SmallInteger |
|
1515 |
*/ |
|
1516 |
if (__bothSmallInteger(index, value)) { |
|
7217 | 1517 |
val = __intVal(value); |
1518 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1519 |
indx = __intVal(index) - 1; |
|
1520 |
if (((unsigned)(indx)) < sizeof(double)) { |
|
1521 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
|
1522 |
cp[indx] = val; |
|
1523 |
RETURN ( value ); |
|
1524 |
} |
|
1525 |
} |
|
701 | 1526 |
} |
1527 |
%}. |
|
1528 |
value isInteger ifFalse:[ |
|
7217 | 1529 |
" |
1530 |
the object to store should be an integer number |
|
1531 |
" |
|
1532 |
^ self elementNotInteger |
|
701 | 1533 |
]. |
1534 |
(value between:0 and:255) ifFalse:[ |
|
7217 | 1535 |
" |
1536 |
the object to store must be a bytes value |
|
1537 |
" |
|
1538 |
^ self elementBoundsError:value |
|
701 | 1539 |
]. |
7217 | 1540 |
^ self indexNotIntegerOrOutOfBounds:index |
5557 | 1541 |
! ! |
1542 |
||
1543 |
!Float methodsFor:'queries'! |
|
4592 | 1544 |
|
1545 |
basicSize |
|
1546 |
"return the size in bytes of the float. |
|
1547 |
||
1548 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1549 |
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
|
1550 |
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
|
1551 |
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
|
1552 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1553 |
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
|
1554 |
values as if this filler wasnt present." |
4592 | 1555 |
|
1556 |
%{ /* NOCONTEXT */ |
|
1557 |
||
1558 |
RETURN (__MKSMALLINT(sizeof(double))); |
|
1559 |
%}. |
|
701 | 1560 |
! ! |
1561 |
||
3896 | 1562 |
!Float methodsFor:'special access'! |
1563 |
||
1564 |
exponent |
|
1565 |
"extract a normalized floats exponent. |
|
1566 |
The returned value depends on the float-representation of |
|
1567 |
the underlying machine and is therefore highly unportable. |
|
1568 |
This is not for general use. |
|
1569 |
This assumes that the mantissa is normalized to |
|
1570 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1571 |
||
1572 |
%{ /* NOCONTEXT */ |
|
1573 |
||
1574 |
double frexp(); |
|
1575 |
double frac; |
|
1576 |
INT exp; |
|
1577 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1578 |
__threadErrno = 0; |
3896 | 1579 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1580 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1581 |
RETURN (__MKSMALLINT(exp)); |
3896 | 1582 |
} |
1583 |
%}. |
|
1584 |
^ self primitiveFailed |
|
1585 |
||
1586 |
" |
|
1587 |
1.0 exponent |
|
1588 |
2.0 exponent |
|
1589 |
3.0 exponent |
|
1590 |
4.0 exponent |
|
1591 |
0.5 exponent |
|
1592 |
0.4 exponent |
|
1593 |
0.25 exponent |
|
1594 |
0.00000011111 exponent |
|
1595 |
" |
|
1596 |
! |
|
1597 |
||
1598 |
mantissa |
|
1599 |
"extract a normalized floats mantissa. |
|
1600 |
The returned value depends on the float-representation of |
|
1601 |
the underlying machine and is therefore highly unportable. |
|
1602 |
This is not for general use. |
|
1603 |
This assumes that the mantissa is normalized to |
|
1604 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1605 |
||
1606 |
%{ /* NOCONTEXT */ |
|
1607 |
||
1608 |
double frexp(); |
|
1609 |
double frac; |
|
1610 |
INT exp; |
|
1611 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1612 |
__threadErrno = 0; |
3896 | 1613 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1614 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1615 |
RETURN (__MKFLOAT(frac)); |
3896 | 1616 |
} |
1617 |
%}. |
|
1618 |
^ self primitiveFailed |
|
1619 |
||
1620 |
" |
|
1621 |
1.0 exponent |
|
1622 |
1.0 mantissa |
|
1623 |
||
1624 |
0.25 exponent |
|
1625 |
0.25 mantissa |
|
1626 |
||
1627 |
0.00000011111 exponent |
|
1628 |
0.00000011111 mantissa |
|
1629 |
" |
|
1630 |
! ! |
|
1631 |
||
701 | 1632 |
!Float methodsFor:'testing'! |
1633 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1634 |
isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1635 |
"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
|
1636 |
i.e. not NaN and not infinite." |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1637 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1638 |
%{ /* NOCONTEXT */ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1639 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1640 |
double dV = __floatVal(self); |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1641 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1642 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1643 |
* 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
|
1644 |
* a finite() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1645 |
* 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
|
1646 |
*/ |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1647 |
if (finite(dV)) { |
6344 | 1648 |
RETURN (true); |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1649 |
} |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1650 |
%}. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1651 |
^false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1652 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1653 |
" |
6344 | 1654 |
1.0 isFinite |
1655 |
Float NaN isFinite |
|
1656 |
Float infinity isFinite |
|
1657 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
1658 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1659 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1660 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1661 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1662 |
isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1663 |
"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
|
1664 |
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
|
1665 |
however, inline C-code could produce them ... |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1666 |
Redefined here for speed" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1667 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1668 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1669 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1670 |
double dV = __floatVal(self); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1671 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1672 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1673 |
* 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
|
1674 |
* finite() & isnan() macros or functions (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1675 |
* 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
|
1676 |
*/ |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1677 |
#if defined(isinf) || defined(LINUX) |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1678 |
if (isinf(dV)) { RETURN (true); } |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1679 |
#else |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1680 |
if (!finite(dV) && !isnan(dV)) { RETURN (true); } |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1681 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1682 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1683 |
^ false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1684 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1685 |
" |
7420 | 1686 |
1.0 isInfinite |
1687 |
(0.0 uncheckedDivide: 0.0) isInfinite |
|
1688 |
(1.0 uncheckedDivide: 0.0) isInfinite |
|
1689 |
(-1.0 uncheckedDivide: 0.0) isInfinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1690 |
" |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1691 |
! |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1692 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1693 |
isLiteral |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1694 |
"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
|
1695 |
(i.e. can be used in constant arrays)" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1696 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1697 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1698 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1699 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1700 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1701 |
|
2387 | 1702 |
isNaN |
1703 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
1704 |
These are not created by ST/X float operations (they raise an exception); |
|
1705 |
however, inline C-code could produce them ..." |
|
1706 |
||
1707 |
%{ /* NOCONTEXT */ |
|
1708 |
||
3139 | 1709 |
double dV = (__floatVal(self)); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1710 |
|
7420 | 1711 |
if (isnan(dV)) { |
1712 |
RETURN (true); |
|
1713 |
} |
|
2392 | 1714 |
%}. |
1715 |
^ false |
|
3139 | 1716 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1717 |
" |
7420 | 1718 |
1.0 isNaN |
1719 |
(0.0 uncheckedDivide: 0.0) isNaN |
|
1720 |
(1.0 uncheckedDivide: 0.0) isNaN |
|
1721 |
(-1.0 uncheckedDivide: 0.0) isNaN |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1722 |
" |
2387 | 1723 |
! |
1724 |
||
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1725 |
isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1726 |
"many systems have two float.Pnt zeros" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1727 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1728 |
%{ |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1729 |
#if defined(i386) && defined(linux) |
7441 | 1730 |
unsigned int biasedExponent; |
1731 |
||
1732 |
biasedExponent = ((short *)(__ByteArrayInstPtr(self)->ba_element))[3] & 0xFF70; |
|
1733 |
RETURN ((biasedExponent == 0x8000) ? true : false ); |
|
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1734 |
#endif |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1735 |
%}. |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1736 |
^ super isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1737 |
|
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1738 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1739 |
0.0 isNegativeZero |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1740 |
-0.0 isNegativeZero |
7441 | 1741 |
-1.0 isNegativeZero |
1742 |
1.0 isNegativeZero |
|
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1743 |
" |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1744 |
! |
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
1745 |
|
701 | 1746 |
negative |
1747 |
"return true if the receiver is less than zero" |
|
1748 |
||
1749 |
%{ /* NOCONTEXT */ |
|
1750 |
||
1133 | 1751 |
RETURN ( (__floatVal(self) < 0.0) ? true : false ); |
5411 | 1752 |
%}. |
701 | 1753 |
! |
1754 |
||
5357 | 1755 |
numberOfBits |
1756 |
"return the size (in bits) of the real; |
|
1757 |
typically, 64 is returned here, |
|
1758 |
but who knows ..." |
|
1759 |
||
1760 |
%{ /* NOCONTEXT */ |
|
1761 |
||
1762 |
RETURN (__MKSMALLINT (sizeof(double) * 8)); |
|
1763 |
%} |
|
1764 |
||
1765 |
" |
|
1766 |
1.2 numberOfBits |
|
1767 |
1.2 asShortFloat numberOfBits |
|
1768 |
" |
|
1769 |
! |
|
1770 |
||
701 | 1771 |
positive |
1772 |
"return true if the receiver is greater or equal to zero" |
|
1773 |
||
1774 |
%{ /* NOCONTEXT */ |
|
1775 |
||
1133 | 1776 |
RETURN ( (__floatVal(self) >= 0.0) ? true : false ); |
701 | 1777 |
%} |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1778 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1779 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1780 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1781 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1782 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1783 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1784 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1785 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1786 |
%} |
701 | 1787 |
! ! |
1788 |
||
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1789 |
!Float methodsFor:'tracing'! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1790 |
|
4682 | 1791 |
traceInto:aRequestor level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1792 |
"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
|
1793 |
|
4682 | 1794 |
^ aRequestor traceFloat:self level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1795 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1796 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1797 |
! ! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1798 |
|
7385 | 1799 |
!Float methodsFor:'trigonometric'! |
1800 |
||
1801 |
arcCos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1802 |
"return the arccosine of the receiver (as radians). |
7385 | 1803 |
Raises an exception, if the receiver is not in -1..1" |
1804 |
||
1805 |
%{ /* NOCONTEXT */ |
|
1806 |
||
1807 |
double val, rslt; |
|
1808 |
OBJ newFloat; |
|
1809 |
||
1810 |
val = __floatVal(self); |
|
1811 |
||
1812 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
|
1813 |
if ((val >= -1.0) && (val <= 1.0)) |
|
1814 |
#endif |
|
1815 |
{ |
|
1816 |
__threadErrno = 0; |
|
1817 |
rslt = acos(val); |
|
7393 | 1818 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 1819 |
{ |
1820 |
if (__threadErrno == 0) { |
|
1821 |
__qMKFLOAT(newFloat, rslt); |
|
1822 |
RETURN ( newFloat ); |
|
1823 |
} |
|
1824 |
} |
|
1825 |
} |
|
1826 |
%}. |
|
1827 |
^ self class |
|
1828 |
raise:#domainErrorSignal |
|
1829 |
receiver:self |
|
1830 |
selector:#arcCos |
|
1831 |
arguments:#() |
|
1832 |
errorString:'bad receiver in arcCos' |
|
1833 |
||
1834 |
" |
|
1835 |
-10 arcCos |
|
1836 |
1 arcCos |
|
1837 |
" |
|
1838 |
||
1839 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
1840 |
! |
|
1841 |
||
1842 |
arcCosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1843 |
"return the hyperbolic arccosine of the receiver." |
7385 | 1844 |
|
7410 | 1845 |
|useFallBack| |
1846 |
||
1847 |
%{ |
|
1848 |
#ifdef NO_ACOSH |
|
1849 |
useFallBack = true; |
|
1850 |
#else |
|
7385 | 1851 |
double val, rslt; |
1852 |
OBJ newFloat; |
|
1853 |
||
1854 |
val = __floatVal(self); |
|
1855 |
||
7410 | 1856 |
# 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
|
1857 |
if (val >= 1.0) |
7410 | 1858 |
# endif |
7385 | 1859 |
{ |
1860 |
__threadErrno = 0; |
|
1861 |
rslt = acosh(val); |
|
7393 | 1862 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 1863 |
{ |
1864 |
if (__threadErrno == 0) { |
|
1865 |
__qMKFLOAT(newFloat, rslt); |
|
1866 |
RETURN ( newFloat ); |
|
1867 |
} |
|
1868 |
} |
|
1869 |
} |
|
7410 | 1870 |
#endif |
7385 | 1871 |
%}. |
7410 | 1872 |
useFallBack notNil ifTrue:[ |
1873 |
^ super arcCosh |
|
1874 |
]. |
|
1875 |
||
7385 | 1876 |
^ self class |
1877 |
raise:#domainErrorSignal |
|
1878 |
receiver:self |
|
1879 |
selector:#arcCosh |
|
1880 |
arguments:#() |
|
1881 |
errorString:'bad receiver in arcCosh' |
|
1882 |
||
1883 |
" |
|
1884 |
-10.0 arcCosh |
|
1885 |
1.0 arcCosh |
|
1886 |
" |
|
1887 |
||
1888 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
|
1889 |
! |
|
1890 |
||
1891 |
arcSin |
|
1892 |
"return the arcsine of myself (I am interpreted as radians). |
|
1893 |
Raises an exception, if the receiver is not in -1..1" |
|
1894 |
||
1895 |
%{ /* NOCONTEXT */ |
|
1896 |
||
1897 |
double val, rslt; |
|
1898 |
OBJ newFloat; |
|
1899 |
||
1900 |
val = __floatVal(self); |
|
1901 |
||
1902 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
|
1903 |
if ((val >= -1.0) && (val <= 1.0)) |
|
1904 |
#endif |
|
1905 |
{ |
|
1906 |
__threadErrno = 0; |
|
1907 |
rslt = asin(val); |
|
7393 | 1908 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 1909 |
{ |
1910 |
if (__threadErrno == 0) { |
|
1911 |
__qMKFLOAT(newFloat, rslt); |
|
1912 |
RETURN ( newFloat ); |
|
1913 |
} |
|
1914 |
} |
|
1915 |
} |
|
1916 |
%}. |
|
1917 |
^ self class |
|
1918 |
raise:#domainErrorSignal |
|
1919 |
receiver:self |
|
1920 |
selector:#arcSin |
|
1921 |
arguments:#() |
|
1922 |
errorString:'bad receiver in arcSin' |
|
1923 |
||
1924 |
" |
|
1925 |
-10 arcSin |
|
1926 |
1 arcSin |
|
1927 |
" |
|
1928 |
||
1929 |
"Modified: / 16.11.2001 / 14:14:18 / cg" |
|
1930 |
! |
|
1931 |
||
1932 |
arcSinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1933 |
"return the hyperbolic arcsine of the receiver." |
7385 | 1934 |
|
7410 | 1935 |
|useFallBack| |
1936 |
%{ |
|
1937 |
#ifdef NO_ASINH |
|
1938 |
useFallBack = true; |
|
1939 |
#else |
|
7385 | 1940 |
double val, rslt; |
1941 |
OBJ newFloat; |
|
1942 |
||
1943 |
val = __floatVal(self); |
|
1944 |
||
7410 | 1945 |
# 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
|
1946 |
if (val >= 1.0) |
7410 | 1947 |
# endif |
7385 | 1948 |
{ |
1949 |
__threadErrno = 0; |
|
1950 |
rslt = asinh(val); |
|
7393 | 1951 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
7385 | 1952 |
{ |
1953 |
if (__threadErrno == 0) { |
|
1954 |
__qMKFLOAT(newFloat, rslt); |
|
1955 |
RETURN ( newFloat ); |
|
1956 |
} |
|
1957 |
} |
|
1958 |
} |
|
7410 | 1959 |
#endif |
7385 | 1960 |
%}. |
7410 | 1961 |
useFallBack notNil ifTrue:[ |
1962 |
^ super arcSinh |
|
1963 |
]. |
|
7385 | 1964 |
^ self class |
1965 |
raise:#domainErrorSignal |
|
1966 |
receiver:self |
|
1967 |
selector:#arcSinh |
|
1968 |
arguments:#() |
|
1969 |
errorString:'bad receiver in arcSinh' |
|
1970 |
||
1971 |
" |
|
1972 |
-10.0 arcSinh |
|
1973 |
1.0 arcSinh |
|
1974 |
" |
|
1975 |
! |
|
1976 |
||
1977 |
arcTan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
1978 |
"return the arctangent of the receiver (as radians)" |
7385 | 1979 |
|
1980 |
%{ /* NOCONTEXT */ |
|
1981 |
||
1982 |
double rslt; |
|
1983 |
OBJ newFloat; |
|
1984 |
||
1985 |
__threadErrno = 0; |
|
1986 |
rslt = atan(__floatVal(self)); |
|
7393 | 1987 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
1988 |
{ |
|
1989 |
if (__threadErrno == 0) { |
|
1990 |
__qMKFLOAT(newFloat, rslt); |
|
1991 |
RETURN ( newFloat ); |
|
1992 |
} |
|
7385 | 1993 |
} |
1994 |
%}. |
|
1995 |
^ self class |
|
1996 |
raise:#domainErrorSignal |
|
1997 |
receiver:self |
|
1998 |
selector:#arcTan |
|
1999 |
arguments:#() |
|
2000 |
errorString:'bad receiver in arcTan' |
|
2001 |
||
2002 |
"Modified: / 16.11.2001 / 14:14:22 / cg" |
|
2003 |
! |
|
2004 |
||
2005 |
arcTanh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2006 |
"return the hyperbolic arctangent of the receiver." |
7385 | 2007 |
|
7410 | 2008 |
|useFallBack| |
2009 |
%{ |
|
2010 |
#ifdef NO_ATANH |
|
2011 |
useFallBack = true; |
|
2012 |
#else |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2013 |
double val, rslt; |
7385 | 2014 |
OBJ newFloat; |
2015 |
||
2016 |
__threadErrno = 0; |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2017 |
val = __floatVal(self); |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2018 |
# 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
|
2019 |
if ((val >= -1.0) && (val <= 1.0)) |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2020 |
# endif |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2021 |
{ |
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2022 |
rslt = atanh(__floatVal(self)); |
7393 | 2023 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2024 |
{ |
|
2025 |
if (__threadErrno == 0) { |
|
2026 |
__qMKFLOAT(newFloat, rslt); |
|
2027 |
RETURN ( newFloat ); |
|
2028 |
} |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2029 |
} |
7385 | 2030 |
} |
7410 | 2031 |
#endif |
7385 | 2032 |
%}. |
7410 | 2033 |
useFallBack notNil ifTrue:[ |
2034 |
^ super arcTanh |
|
2035 |
]. |
|
7385 | 2036 |
^ self class |
2037 |
raise:#domainErrorSignal |
|
2038 |
receiver:self |
|
2039 |
selector:#arcTanh |
|
2040 |
arguments:#() |
|
2041 |
errorString:'bad receiver in arcTanh' |
|
2042 |
! |
|
2043 |
||
2044 |
cos |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2045 |
"return the cosine of the receiver (interpreted as radians)" |
7385 | 2046 |
|
2047 |
%{ /* NOCONTEXT */ |
|
2048 |
||
2049 |
double rslt; |
|
2050 |
OBJ newFloat; |
|
2051 |
||
2052 |
__threadErrno = 0; |
|
2053 |
rslt = cos(__floatVal(self)); |
|
7393 | 2054 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2055 |
{ |
|
2056 |
if (__threadErrno == 0) { |
|
2057 |
__qMKFLOAT(newFloat, rslt); |
|
2058 |
RETURN ( newFloat ); |
|
2059 |
} |
|
7385 | 2060 |
} |
2061 |
%}. |
|
2062 |
^ self class |
|
2063 |
raise:#domainErrorSignal |
|
2064 |
receiver:self |
|
2065 |
selector:#cos |
|
2066 |
arguments:#() |
|
2067 |
errorString:'bad receiver in cos' |
|
2068 |
||
2069 |
"Modified: / 16.11.2001 / 14:14:26 / cg" |
|
2070 |
! |
|
2071 |
||
2072 |
cosh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2073 |
"return the hyperbolic cosine of the receiver" |
7385 | 2074 |
|
2075 |
%{ /* NOCONTEXT */ |
|
2076 |
||
2077 |
double rslt; |
|
2078 |
OBJ newFloat; |
|
2079 |
||
2080 |
__threadErrno = 0; |
|
2081 |
rslt = cosh(__floatVal(self)); |
|
7393 | 2082 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2083 |
{ |
|
2084 |
if (__threadErrno == 0) { |
|
2085 |
__qMKFLOAT(newFloat, rslt); |
|
2086 |
RETURN ( newFloat ); |
|
2087 |
} |
|
7385 | 2088 |
} |
2089 |
%}. |
|
2090 |
^ self class |
|
2091 |
raise:#domainErrorSignal |
|
2092 |
receiver:self |
|
2093 |
selector:#cosh |
|
2094 |
arguments:#() |
|
2095 |
errorString:'bad receiver in cosh' |
|
2096 |
! |
|
2097 |
||
2098 |
sin |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2099 |
"return the sine of the receiver (interpreted as radians)" |
7385 | 2100 |
|
2101 |
%{ /* NOCONTEXT */ |
|
2102 |
||
2103 |
double rslt; |
|
2104 |
OBJ newFloat; |
|
2105 |
||
2106 |
__threadErrno = 0; |
|
2107 |
rslt = sin(__floatVal(self)); |
|
7393 | 2108 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2109 |
{ |
|
2110 |
if (__threadErrno == 0) { |
|
2111 |
__qMKFLOAT(newFloat, rslt); |
|
2112 |
RETURN ( newFloat ); |
|
2113 |
} |
|
7385 | 2114 |
} |
2115 |
%}. |
|
2116 |
^ self class |
|
2117 |
raise:#domainErrorSignal |
|
2118 |
receiver:self |
|
2119 |
selector:#sin |
|
2120 |
arguments:#() |
|
2121 |
errorString:'bad receiver in sin' |
|
2122 |
||
2123 |
"Modified: / 16.11.2001 / 14:14:37 / cg" |
|
2124 |
! |
|
2125 |
||
2126 |
sinh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2127 |
"return the hyperbolic sine of the receiver" |
7385 | 2128 |
|
2129 |
%{ /* NOCONTEXT */ |
|
2130 |
||
2131 |
double rslt; |
|
2132 |
OBJ newFloat; |
|
2133 |
||
2134 |
__threadErrno = 0; |
|
2135 |
rslt = sinh(__floatVal(self)); |
|
7393 | 2136 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2137 |
{ |
|
2138 |
if (__threadErrno == 0) { |
|
2139 |
__qMKFLOAT(newFloat, rslt); |
|
2140 |
RETURN ( newFloat ); |
|
2141 |
} |
|
7385 | 2142 |
} |
2143 |
%}. |
|
2144 |
^ self class |
|
2145 |
raise:#domainErrorSignal |
|
2146 |
receiver:self |
|
2147 |
selector:#sinh |
|
2148 |
arguments:#() |
|
2149 |
errorString:'bad receiver in sinh' |
|
2150 |
! |
|
2151 |
||
2152 |
tan |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2153 |
"return the tangens of the receiver (interpreted as radians)" |
7385 | 2154 |
|
2155 |
%{ /* NOCONTEXT */ |
|
2156 |
||
2157 |
double rslt; |
|
2158 |
OBJ newFloat; |
|
2159 |
||
2160 |
__threadErrno = 0; |
|
2161 |
rslt = tan(__floatVal(self)); |
|
7393 | 2162 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2163 |
{ |
|
2164 |
if (__threadErrno == 0) { |
|
2165 |
__qMKFLOAT(newFloat, rslt); |
|
2166 |
RETURN ( newFloat ); |
|
2167 |
} |
|
7385 | 2168 |
} |
2169 |
%}. |
|
2170 |
^ self class |
|
2171 |
raise:#domainErrorSignal |
|
2172 |
receiver:self |
|
2173 |
selector:#tan |
|
2174 |
arguments:#() |
|
2175 |
errorString:'bad receiver in tan' |
|
2176 |
||
2177 |
"Modified: / 16.11.2001 / 14:14:49 / cg" |
|
2178 |
! |
|
2179 |
||
2180 |
tanh |
|
7391
55ca5a24162a
added more math functions (hyperbolic)
Claus Gittinger <cg@exept.de>
parents:
7385
diff
changeset
|
2181 |
"return the hyperbolic tangens of the receiver" |
7385 | 2182 |
|
2183 |
%{ /* NOCONTEXT */ |
|
2184 |
||
2185 |
double rslt; |
|
2186 |
OBJ newFloat; |
|
2187 |
||
2188 |
__threadErrno = 0; |
|
2189 |
rslt = tanh(__floatVal(self)); |
|
7393 | 2190 |
if (! isnan(rslt)) /* Currently all our systems support isnan() */ |
2191 |
{ |
|
2192 |
if (__threadErrno == 0) { |
|
2193 |
__qMKFLOAT(newFloat, rslt); |
|
2194 |
RETURN ( newFloat ); |
|
2195 |
} |
|
7385 | 2196 |
} |
2197 |
%}. |
|
2198 |
^ self class |
|
2199 |
raise:#domainErrorSignal |
|
2200 |
receiver:self |
|
2201 |
selector:#tanh |
|
2202 |
arguments:#() |
|
2203 |
errorString:'bad receiver in tanh' |
|
2204 |
! ! |
|
2205 |
||
5552 | 2206 |
!Float methodsFor:'truncation & rounding'! |
701 | 2207 |
|
2208 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2209 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 2210 |
|
2211 |
|val| |
|
2212 |
||
2213 |
%{ |
|
2214 |
double dVal; |
|
2215 |
||
7355 | 2216 |
dVal = ceil(__floatVal(self)); |
701 | 2217 |
/* |
2218 |
* ST-80 (and X3J20) returns integer. |
|
2219 |
*/ |
|
2220 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
7355 | 2221 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2222 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2223 |
__qMKFLOAT(val, dVal); |
701 | 2224 |
%}. |
2225 |
^ val asInteger |
|
2226 |
! |
|
2227 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2228 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2229 |
"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
|
2230 |
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
|
2231 |
of the result to an integer. |
7355 | 2232 |
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
|
2233 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2234 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2235 |
double dVal; |
7355 | 2236 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2237 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2238 |
dVal = ceil(__floatVal(self)); |
7355 | 2239 |
__qMKFLOAT(v, dVal); |
2240 |
RETURN (v); |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2241 |
%} |
7355 | 2242 |
" |
2243 |
0.5 ceilingAsFloat |
|
2244 |
-0.5 ceilingAsFloat |
|
2245 |
-1.5 ceilingAsFloat |
|
2246 |
" |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2247 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2248 |
|
701 | 2249 |
floor |
2250 |
"return the integer nearest the receiver towards negative infinity." |
|
2251 |
||
2252 |
|val| |
|
2253 |
||
2254 |
%{ |
|
2255 |
double dVal; |
|
2256 |
||
7355 | 2257 |
dVal = floor(__floatVal(self)); |
701 | 2258 |
/* |
2259 |
* ST-80 (and X3J20) returns integer. |
|
2260 |
*/ |
|
2261 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
7355 | 2262 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2263 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2264 |
__qMKFLOAT(val, dVal); |
701 | 2265 |
%}. |
2266 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2267 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2268 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2269 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2270 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2271 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2272 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2273 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2274 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2275 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2276 |
floorAsFloat |
7355 | 2277 |
"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
|
2278 |
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
|
2279 |
of the result to an integer. |
7355 | 2280 |
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
|
2281 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2282 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2283 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2284 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2285 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2286 |
dVal = floor(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2287 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2288 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2289 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2290 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2291 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2292 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2293 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2294 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2295 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2296 |
" |
701 | 2297 |
! |
2298 |
||
3896 | 2299 |
fractionPart |
2300 |
"extract the after-decimal fraction part. |
|
7355 | 2301 |
such that (self truncated + self fractionPart) = self" |
3896 | 2302 |
|
2303 |
%{ /* NOCONTEXT */ |
|
2304 |
||
2305 |
double modf(); |
|
2306 |
double frac, trunc; |
|
2307 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
2308 |
__threadErrno = 0; |
3896 | 2309 |
frac = modf(__floatVal(self), &trunc); |
7403 | 2310 |
if (! isnan(frac)) { |
2311 |
if (__threadErrno == 0) { |
|
2312 |
RETURN (__MKFLOAT(frac)); |
|
2313 |
} |
|
3896 | 2314 |
} |
2315 |
%}. |
|
7403 | 2316 |
^ self class |
2317 |
raise:#domainErrorSignal |
|
2318 |
receiver:self |
|
2319 |
selector:#fractionPart |
|
2320 |
arguments:#() |
|
2321 |
errorString:'bad receiver in fractionPart' |
|
3896 | 2322 |
|
2323 |
" |
|
7355 | 2324 |
1.6 fractionPart + 1.6 truncated |
2325 |
-1.6 fractionPart + -1.6 truncated |
|
2326 |
||
3896 | 2327 |
1.0 fractionPart |
2328 |
2.0 fractionPart |
|
2329 |
3.0 fractionPart |
|
2330 |
4.0 fractionPart |
|
2331 |
0.5 fractionPart |
|
2332 |
0.25 fractionPart |
|
2333 |
3.14159 fractionPart |
|
2334 |
12345673.14159 fractionPart |
|
2335 |
123456731231231231.14159 fractionPart |
|
2336 |
||
2337 |
3.14159 fractionPart + 3.14159 truncated |
|
2338 |
||
2339 |
12345673.14159 fractionPart + 12345673.14159 truncated |
|
2340 |
||
2341 |
123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated |
|
2342 |
" |
|
2343 |
! |
|
2344 |
||
701 | 2345 |
rounded |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2346 |
"return the receiver rounded to the nearest integer" |
701 | 2347 |
|
2348 |
|val| |
|
2349 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2350 |
%{ |
701 | 2351 |
double dVal; |
2352 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2353 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2354 |
if (dVal < 0.0) { |
7355 | 2355 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2356 |
} else { |
7355 | 2357 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2358 |
} |
701 | 2359 |
/* |
2360 |
* ST-80 (and X3J20) returns integer. |
|
2361 |
*/ |
|
2362 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
7355 | 2363 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2364 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2365 |
__qMKFLOAT(val, dVal); |
701 | 2366 |
%}. |
7355 | 2367 |
^ val asInteger |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2368 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2369 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2370 |
0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2371 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2372 |
0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2373 |
-0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2374 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2375 |
-0.6 rounded |
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 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2379 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2380 |
"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
|
2381 |
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
|
2382 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2383 |
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
|
2384 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2385 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2386 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2387 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2388 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2389 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2390 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2391 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2392 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2393 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2394 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2395 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2396 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2397 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2398 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2399 |
RETURN (v); |
1879
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 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2402 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2403 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2404 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2405 |
0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2406 |
-0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2407 |
" |
701 | 2408 |
! |
2409 |
||
2410 |
truncated |
|
2411 |
"return the receiver truncated towards zero as an integer" |
|
2412 |
||
2413 |
|val| |
|
2414 |
||
2415 |
%{ |
|
2416 |
double dVal; |
|
2417 |
||
1133 | 2418 |
dVal = __floatVal(self); |
701 | 2419 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2420 |
dVal = ceil(dVal); |
701 | 2421 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2422 |
dVal = floor(dVal); |
701 | 2423 |
} |
2424 |
||
2425 |
/* |
|
2426 |
* ST-80 (and X3J20) returns integer. |
|
2427 |
*/ |
|
2428 |
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
|
2429 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2430 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2431 |
__qMKFLOAT(val, dVal); |
701 | 2432 |
%}. |
2433 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2434 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2435 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2436 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2437 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2438 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2439 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2440 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2441 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2442 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2443 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2444 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2445 |
"return the receiver truncated towards zero as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2446 |
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
|
2447 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2448 |
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
|
2449 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2450 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2451 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2452 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2453 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2454 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2455 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2456 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2457 |
dVal = ceil(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2458 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2459 |
dVal = floor(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2460 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2461 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2462 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2463 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2464 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2465 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2466 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2467 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2468 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2469 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2470 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2471 |
|
701 | 2472 |
! ! |
2473 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2474 |
!Float class methodsFor:'documentation'! |
701 | 2475 |
|
2476 |
version |
|
7746 | 2477 |
^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.151 2003-11-11 13:16:57 cg Exp $' |
701 | 2478 |
! ! |
6890
8e74eff54c3d
added isNegativeZero to test for -0.0
Claus Gittinger <cg@exept.de>
parents:
6674
diff
changeset
|
2479 |
|
2387 | 2480 |
Float initialize! |