author | Claus Gittinger <cg@exept.de> |
Fri, 23 Jun 2000 21:03:30 +0200 | |
changeset 5411 | c396c6640868 |
parent 5357 | 39860dd8b0f5 |
child 5436 | f67d84b60f38 |
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:'' |
2358 | 17 |
classVariableNames:'DefaultPrintFormat' |
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 |
50 |
# include <nan.h> |
|
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 |
*/ |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
103 |
# ifndef finite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
104 |
# define finite(x) 1 |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
105 |
# endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
106 |
# ifndef isnan |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
107 |
# define isnan(x) 0 |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
108 |
# endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
109 |
#endif |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
110 |
|
3414 | 111 |
#ifdef realIX |
112 |
/* |
|
113 |
* no finite(x) |
|
114 |
*/ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
115 |
# ifndef finite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
116 |
# define finite(x) 1 |
3414 | 117 |
# endif |
118 |
#endif |
|
119 |
||
3241 | 120 |
#ifndef NEXT3 |
121 |
# ifndef ceil |
|
122 |
double ceil(); |
|
123 |
double floor(); |
|
124 |
# endif |
|
125 |
#endif |
|
126 |
||
701 | 127 |
%} |
128 |
! ! |
|
129 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
130 |
!Float class methodsFor:'documentation'! |
68 | 131 |
|
88 | 132 |
copyright |
133 |
" |
|
134 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
175 | 135 |
All Rights Reserved |
88 | 136 |
|
137 |
This software is furnished under a license and may be used |
|
138 |
only in accordance with the terms of that license and with the |
|
139 |
inclusion of the above copyright notice. This software may not |
|
140 |
be provided or otherwise made available to, or used by, any |
|
141 |
other person. No title to or ownership of the software is |
|
142 |
hereby transferred. |
|
143 |
" |
|
144 |
! |
|
145 |
||
68 | 146 |
documentation |
147 |
" |
|
148 |
Floats represent rational numbers with limited precision. In ST/X, Float uses |
|
149 |
the underlying C-compilers double implementation, therefore instances of Float |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
150 |
are usually represented by the 8-byte IEEE double precision float format. |
68 | 151 |
(but there is no guaranty). |
1 | 152 |
|
68 | 153 |
Notice, that Floats are defined as Byte-array to prevent the garbage collector |
154 |
from going into the value ... otherwise I needed a special case in many places. |
|
155 |
||
156 |
Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change |
|
157 |
in one of the next versions (at least on machines, which provide different float |
|
158 |
and double types in their C-compiler. |
|
159 |
||
160 |
WARNING: |
|
161 |
The layout of float instances is known by the runtime system and the compiler; |
|
162 |
you may not add instance variables here. |
|
369 | 163 |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
164 |
Also, subclassing is complicated by the fact, that the VM creates floats as results |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
165 |
of arithmetic operations (even if the operands are subclass-instances). |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
166 |
(It does the float-check by probing a bit in the classes flag instVar). |
85 | 167 |
|
1892 | 168 |
Mixed mode arithmetic: |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
169 |
float op float -> float |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
170 |
float op fix -> float |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
171 |
float op integer -> float |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
172 |
float op float -> float |
1892 | 173 |
|
1295 | 174 |
[Class Variables:] |
85 | 175 |
|
1295 | 176 |
[see also:] |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
177 |
Number |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
178 |
ShortFloat Fraction FixedPoint Integer |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
179 |
FloatArray DoubleArray |
1295 | 180 |
|
181 |
[author:] |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
182 |
Claus Gittinger |
68 | 183 |
" |
2215 | 184 |
! |
185 |
||
186 |
errorHandling |
|
187 |
" |
|
188 |
Floating point error handling and signalling depends on the systems |
|
189 |
(actually: the C-runtime systems) ability to handle floating point errors. |
|
190 |
Most systems report errors by raising an OS floatingPoint exception, |
|
191 |
which is mapped to a fpExceptionInterrupt in ST/X. |
|
192 |
However, some systems do return NaN as result. |
|
193 |
||
194 |
Currently, ST/X does not care specially for these systems - it maybe added |
|
195 |
easily, if there is sufficient customer interest, though. |
|
196 |
||
197 |
Try: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
198 |
|f1 f2| |
2215 | 199 |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
200 |
f1 := 1.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
201 |
f2 := 0.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
202 |
f1 / f2 |
2215 | 203 |
|
204 |
or: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
205 |
2 arcSin |
2215 | 206 |
" |
68 | 207 |
! ! |
1 | 208 |
|
2387 | 209 |
!Float class methodsFor:'initialization'! |
210 |
||
211 |
initialize |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
212 |
DefaultPrintFormat := '.6' "/ 6 valid digits |
2387 | 213 |
|
214 |
" |
|
215 |
DefaultPrintFormat := '.9' |
|
216 |
DefaultPrintFormat := '.6' |
|
217 |
" |
|
218 |
! ! |
|
219 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
220 |
!Float class methodsFor:'instance creation'! |
1 | 221 |
|
222 |
basicNew |
|
223 |
"return a new float - here we return 0.0 |
|
224 |
- floats are usually NOT created this way ... |
|
225 |
Its implemented here to allow things like binary store & load |
|
226 |
of floats. (but even this support will go away eventually, its not |
|
227 |
a good idea to store the bits of a float - the reader might have a |
|
13 | 228 |
totally different representation - so floats will eventually be |
229 |
binary stored in a device independent format." |
|
1 | 230 |
|
231 |
%{ /* NOCONTEXT */ |
|
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
232 |
OBJ newFloat; |
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
233 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
234 |
__qMKFLOAT(newFloat, 0.0); |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
235 |
RETURN (newFloat); |
1 | 236 |
%} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
237 |
! |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
238 |
|
4295 | 239 |
fastFromString:aString at:startIndex |
240 |
"return the next Float from the string starting at startIndex. |
|
241 |
No spaces are skipped. |
|
242 |
||
243 |
This is a specially tuned entry (using a low-level C-call), which |
|
244 |
returns garbage if the argument string is not a valid float number. |
|
245 |
It has been added to allow higher speed string decomposition into |
|
246 |
numbers." |
|
247 |
%{ |
|
248 |
if (__isString(aString) && __isSmallInteger(startIndex)) { |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
249 |
char *cp = (char *)(__stringVal(aString)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
250 |
int idx = __intVal(startIndex) - 1; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
251 |
double atof(); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
252 |
double val; |
4295 | 253 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
254 |
if ((unsigned)idx < __stringSize(aString)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
255 |
val = atof(cp + idx); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
256 |
RETURN (__MKFLOAT(val)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
257 |
} |
4295 | 258 |
} |
259 |
%}. |
|
260 |
self primitiveFailed. |
|
261 |
||
262 |
" |
|
4296 | 263 |
Float fastFromString:'123.45' at:1 |
264 |
Float fastFromString:'123.45' at:2 |
|
265 |
Float fastFromString:'123.45E4' at:1 |
|
266 |
Float fastFromString:'hello123.45E4' at:6 |
|
4295 | 267 |
Float fastFromString:'12345' at:1 |
268 |
Float fastFromString:'12345' at:2 |
|
269 |
Float fastFromString:'12345' at:3 |
|
270 |
Float fastFromString:'12345' at:4 |
|
271 |
Float fastFromString:'12345' at:5 |
|
272 |
Float fastFromString:'12345' at:6 |
|
273 |
Float fastFromString:'12345' at:0 |
|
4296 | 274 |
Float fastFromString:'hello123.45E4' at:1 |
4295 | 275 |
|
276 |
Time millisecondsToRun:[ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
277 |
100000 timesRepeat:[ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
278 |
Float readFrom:'123.45' |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
279 |
] |
4295 | 280 |
] |
281 |
" |
|
282 |
||
283 |
" |
|
284 |
Time millisecondsToRun:[ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
285 |
100000 timesRepeat:[ |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
286 |
Float fastFromString:'123.45' at:1 |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
287 |
] |
4295 | 288 |
] |
289 |
" |
|
290 |
||
291 |
||
292 |
! |
|
293 |
||
3279 | 294 |
fromVAXFloatBytes:b1 b2:b2 b3:b3 b4:b4 |
295 |
"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
|
296 |
For NaNs and Infinity, nil is returned. |
3279 | 297 |
" |
298 |
||
299 |
%{ /* NOCONTEXT */ |
|
300 |
||
301 |
REGISTER union { |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
302 |
unsigned char b[4]; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
303 |
unsigned int l; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
304 |
float f; |
3279 | 305 |
} r; |
306 |
||
307 |
#ifdef i386 /* actually: LSBFIRST */ |
|
308 |
r.b[3] = __intVal( b2 ); |
|
309 |
r.b[2] = __intVal( b1 ); |
|
310 |
r.b[1] = __intVal( b4 ); |
|
311 |
r.b[0] = __intVal( b3 ); |
|
312 |
#else |
|
313 |
r.b[0] = __intVal( b2 ); |
|
314 |
r.b[1] = __intVal( b1 ); |
|
315 |
r.b[2] = __intVal( b4 ); |
|
316 |
r.b[3] = __intVal( b3 ); |
|
317 |
#endif |
|
318 |
if( (r.l & 0xff800000) != 0x80000000 ) |
|
319 |
{ |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
320 |
if( (r.l & 0x7f800000) > 0x01000000 ) |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
321 |
r.l -= 0x01000000; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
322 |
else |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
323 |
r.l = 0; |
3279 | 324 |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
325 |
RETURN( __MKFLOAT(r.f) ); |
3279 | 326 |
} |
327 |
%}. |
|
328 |
^ nil |
|
329 |
! |
|
330 |
||
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
331 |
readFrom:aStringOrStream onError:exceptionBlock |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
332 |
"read a float from a string" |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
333 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
334 |
|num| |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
335 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
336 |
num := super readFrom:aStringOrStream onError:nil. |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
337 |
num isNil ifTrue:[ |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
338 |
^ exceptionBlock value |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
339 |
]. |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
340 |
^ num asFloat |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
341 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
342 |
" |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
343 |
Float readFrom:'0.1' |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
344 |
Float readFrom:'0' |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
345 |
" |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
346 |
|
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
347 |
"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
|
348 |
"Modified: / 7.1.1998 / 16:18:33 / cg" |
1 | 349 |
! ! |
350 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
351 |
!Float class methodsFor:'binary storage'! |
701 | 352 |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
353 |
binaryDefinitionFrom:aStream manager: manager |
701 | 354 |
|f| |
355 |
||
356 |
f := self basicNew. |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
357 |
self readBinaryIEEEDoubleFrom:aStream into:f. |
701 | 358 |
^ f |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
359 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
360 |
"Modified: 16.4.1996 / 21:23:38 / cg" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
361 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
362 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
363 |
readBinaryIEEEDoubleFrom:aStream |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
364 |
"read a float from the binary stream, aStream, |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
365 |
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
|
366 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
367 |
|f| |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
368 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
369 |
f := self basicNew. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
370 |
self readBinaryIEEEDoubleFrom:aStream into:f. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
371 |
^ f |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
372 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
373 |
"Created: 16.4.1996 / 20:59:59 / cg" |
701 | 374 |
! |
375 |
||
376 |
readBinaryIEEEDoubleFrom:aStream into:aFloat |
|
377 |
"read the receivers value from the binary stream, aStream, |
|
378 |
interpreting the next bytes as an IEEE formatted 8-byte float" |
|
379 |
||
380 |
" |
|
381 |
this implementation is wrong: does not work on non-IEEE machines |
|
382 |
(to date all machines where ST/X is running on use |
|
383 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
384 |
" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
385 |
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
|
386 |
|
701 | 387 |
UninterpretedBytes isBigEndian ifFalse:[ |
388 |
"swap the bytes" |
|
389 |
8 to:1 by:-1 do:[:i | |
|
390 |
aFloat basicAt:i put:(aStream next) |
|
391 |
]. |
|
392 |
^ self |
|
393 |
]. |
|
394 |
1 to:8 do:[:i | |
|
395 |
aFloat basicAt:i put:aStream next |
|
396 |
] |
|
397 |
! |
|
398 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
399 |
readBinaryIEEESingleFrom:aStream |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
400 |
"read a float value from the binary stream, aStream, |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
401 |
interpreting the next bytes as an IEEE formatted 4-byte float" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
402 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
403 |
|f| |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
404 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
405 |
f := self basicNew. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
406 |
self readBinaryIEEESingleFrom:aStream into:f. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
407 |
^ f |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
408 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
409 |
"Created: 16.4.1996 / 21:00:35 / cg" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
410 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
411 |
|
701 | 412 |
readBinaryIEEESingleFrom:aStream into:aFloat |
413 |
"read a float value from the binary stream, aStream, |
|
414 |
interpreting the next bytes as an IEEE formatted 4-byte float" |
|
415 |
||
416 |
" |
|
417 |
this implementation is wrong: does not work on non-IEEE machines |
|
418 |
(to date all machines where ST/X is running on use |
|
419 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
420 |
" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
421 |
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
|
422 |
|
701 | 423 |
UninterpretedBytes isBigEndian ifFalse:[ |
424 |
"swap the bytes" |
|
425 |
8 to:4 by:-1 do:[:i | |
|
426 |
aFloat basicAt:i put:(aStream next) |
|
427 |
]. |
|
428 |
^ self |
|
429 |
]. |
|
430 |
1 to:4 do:[:i | |
|
431 |
aFloat basicAt:i put:aStream next |
|
432 |
] |
|
433 |
! |
|
434 |
||
435 |
storeBinaryIEEEDouble:aFloat on:aStream |
|
436 |
"store aFloat as an IEEE formatted 8-byte float |
|
437 |
onto the binary stream, aStream" |
|
438 |
||
439 |
" |
|
440 |
this implementation is wrong: does not work on non-IEEE machines |
|
441 |
(to date all machines where ST/X is running on use |
|
442 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
443 |
" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
444 |
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
|
445 |
|
701 | 446 |
UninterpretedBytes isBigEndian ifFalse:[ |
447 |
"swap the bytes" |
|
448 |
8 to:1 by:-1 do:[:i | |
|
449 |
aStream nextPut:(aFloat basicAt:i). |
|
450 |
]. |
|
451 |
^ self |
|
452 |
]. |
|
453 |
1 to:8 do:[:i | |
|
454 |
aStream nextPut:(aFloat basicAt:i). |
|
455 |
]. |
|
456 |
! |
|
457 |
||
458 |
storeBinaryIEEESingle:aFloat on:aStream |
|
459 |
"store aFloat as an IEEE formatted 4-byte float |
|
460 |
onto the binary stream, aStream" |
|
461 |
||
462 |
" |
|
463 |
this implementation is wrong: does not work on non-IEEE machines |
|
464 |
(to date all machines where ST/X is running on use |
|
465 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
466 |
" |
|
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
467 |
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
|
468 |
|
701 | 469 |
UninterpretedBytes isBigEndian ifFalse:[ |
470 |
"swap the bytes" |
|
471 |
8 to:4 by:-1 do:[:i | |
|
472 |
aStream nextPut:(aFloat basicAt:i). |
|
473 |
]. |
|
474 |
^ self |
|
475 |
]. |
|
476 |
1 to:4 do:[:i | |
|
477 |
aStream nextPut:(aFloat basicAt:i). |
|
478 |
] |
|
479 |
! ! |
|
480 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
481 |
!Float class methodsFor:'constants'! |
1 | 482 |
|
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
483 |
NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
484 |
"return the constant NaN (not a Number). |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
485 |
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
|
486 |
few selected architectures." |
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 |
%{ |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
489 |
#if defined(LINUX) && defined(i386) |
3955 | 490 |
# ifdef NAN |
491 |
RETURN (__MKFLOAT(NAN)); |
|
492 |
# else |
|
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
493 |
RETURN (__MKFLOAT(_SNAN)); |
3955 | 494 |
# endif |
3945
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
495 |
#endif |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
496 |
%}. |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
497 |
^ nil |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
498 |
|
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
499 |
" |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
500 |
Float NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
501 |
Float NaN + 0.0 |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
502 |
Float NaN + Float NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
503 |
0.0 + Float NaN |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
504 |
" |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
505 |
! |
1745e97364cb
added preliminary version of NaN
Claus Gittinger <cg@exept.de>
parents:
3903
diff
changeset
|
506 |
|
701 | 507 |
pi |
1260 | 508 |
"return the constant pi as Float" |
1 | 509 |
|
3244 | 510 |
"/ dont expect this many valid digits on all machines; |
511 |
"/ The actual precision is very CPU specific. |
|
512 |
||
513 |
^ 3.14159265358979323846264338327950288 |
|
1260 | 514 |
|
515 |
"Modified: 23.4.1996 / 09:27:02 / cg" |
|
1 | 516 |
! |
517 |
||
518 |
unity |
|
1260 | 519 |
"return the neutral element for multiplication (1.0) as Float" |
1 | 520 |
|
521 |
^ 1.0 |
|
1260 | 522 |
|
523 |
"Modified: 23.4.1996 / 09:27:09 / cg" |
|
1 | 524 |
! |
525 |
||
701 | 526 |
zero |
1260 | 527 |
"return the neutral element for addition (0.0) as Float" |
1 | 528 |
|
701 | 529 |
^ 0.0 |
1260 | 530 |
|
531 |
"Modified: 23.4.1996 / 09:27:15 / cg" |
|
1 | 532 |
! ! |
533 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
534 |
!Float class methodsFor:'queries'! |
3 | 535 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
536 |
hasSharedInstances |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
537 |
"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
|
538 |
with the same value are identical. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
539 |
Although not really shared, floats should be treated |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
540 |
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
|
541 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
542 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
543 |
|
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 |
|
3 | 547 |
isBuiltInClass |
1264 | 548 |
"return true if this class is known by the run-time-system. |
549 |
Here, true is returned for myself, false for subclasses." |
|
3 | 550 |
|
551 |
^ self == Float |
|
1264 | 552 |
|
553 |
"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
|
554 |
! |
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 |
isIEEEFormat |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
557 |
"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
|
558 |
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
|
559 |
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
|
560 |
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
|
561 |
machine). |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
562 |
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
|
563 |
(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
|
564 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
565 |
^ true "/ this may be a lie |
3 | 566 |
! ! |
567 |
||
1 | 568 |
!Float methodsFor:'arithmetic'! |
569 |
||
701 | 570 |
* aNumber |
571 |
"return the product of the receiver and the argument, aNumber" |
|
572 |
||
573 |
%{ /* NOCONTEXT */ |
|
574 |
||
575 |
OBJ newFloat; |
|
576 |
double result; |
|
577 |
||
578 |
if (__isSmallInteger(aNumber)) { |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
579 |
result = __floatVal(self) * (double)(__intVal(aNumber)); |
701 | 580 |
retResult: |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
581 |
__qMKFLOAT(newFloat, result); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
582 |
RETURN ( newFloat ); |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
583 |
} else if (__isFloatLike(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
584 |
result = __floatVal(self) * __floatVal(aNumber); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
585 |
goto retResult; |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
586 |
} else if (__isShortFloat(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
587 |
result = __floatVal(self) * (double)(__shortFloatVal(aNumber)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
588 |
goto retResult; |
701 | 589 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
590 |
%}. |
701 | 591 |
^ aNumber productFromFloat:self |
592 |
! |
|
593 |
||
1 | 594 |
+ aNumber |
595 |
"return the sum of the receiver and the argument, aNumber" |
|
596 |
||
597 |
%{ /* NOCONTEXT */ |
|
13 | 598 |
|
1 | 599 |
OBJ newFloat; |
600 |
double result; |
|
601 |
||
250 | 602 |
if (__isSmallInteger(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
603 |
result = __floatVal(self) + (double)(__intVal(aNumber)); |
1 | 604 |
retResult: |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
605 |
__qMKFLOAT(newFloat, result); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
606 |
RETURN ( newFloat ); |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
607 |
} else if (__isFloatLike(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
608 |
result = __floatVal(self) + __floatVal(aNumber); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
609 |
goto retResult; |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
610 |
} else if (__isShortFloat(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
611 |
result = __floatVal(self) + (double)(__shortFloatVal(aNumber)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
612 |
goto retResult; |
1 | 613 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
614 |
%}. |
1 | 615 |
^ aNumber sumFromFloat:self |
616 |
! |
|
617 |
||
618 |
- aNumber |
|
619 |
"return the difference of the receiver and the argument, aNumber" |
|
620 |
||
621 |
%{ /* NOCONTEXT */ |
|
13 | 622 |
|
1 | 623 |
OBJ newFloat; |
624 |
double result; |
|
625 |
||
250 | 626 |
if (__isSmallInteger(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
627 |
result = __floatVal(self) - (double)(__intVal(aNumber)); |
1 | 628 |
retResult: |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
629 |
__qMKFLOAT(newFloat, result); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
630 |
RETURN ( newFloat ); |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
631 |
} else if (__isFloatLike(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
632 |
result = __floatVal(self) - __floatVal(aNumber); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
633 |
goto retResult; |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
634 |
} else if (__isShortFloat(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
635 |
result = __floatVal(self) - (double)(__shortFloatVal(aNumber)); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
636 |
goto retResult; |
1 | 637 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
638 |
%}. |
1 | 639 |
^ aNumber differenceFromFloat:self |
640 |
! |
|
641 |
||
642 |
/ aNumber |
|
643 |
"return the quotient of the receiver and the argument, aNumber" |
|
644 |
||
645 |
%{ /* NOCONTEXT */ |
|
646 |
||
647 |
OBJ newFloat; |
|
648 |
double result, val; |
|
649 |
||
250 | 650 |
if (__isSmallInteger(aNumber)) { |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
651 |
if (aNumber != __MKSMALLINT(0)) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
652 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
1 | 653 |
retResult: |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
654 |
__qMKFLOAT(newFloat, result); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
655 |
RETURN ( newFloat ); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
656 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
657 |
} else if (__isFloatLike(aNumber)) { |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
658 |
val = __floatVal(aNumber); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
659 |
if (val != 0.0) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
660 |
result = __floatVal(self) / val; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
661 |
goto retResult; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
662 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
663 |
} else if (__isShortFloat(aNumber)) { |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
664 |
val = (double)(__shortFloatVal(aNumber)); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
665 |
if (val != 0.0) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
666 |
result = __floatVal(self) / val; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
667 |
goto retResult; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
668 |
} |
1 | 669 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
670 |
%}. |
1 | 671 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
672 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
673 |
No, you shalt not divide by zero |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
674 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
675 |
^ DivisionByZeroSignal raiseRequest. |
1 | 676 |
]. |
677 |
^ aNumber quotientFromFloat:self |
|
678 |
! |
|
679 |
||
5411 | 680 |
abs |
681 |
"return the absolute value of the receiver |
|
682 |
reimplemented here for speed" |
|
683 |
||
684 |
%{ /* NOCONTEXT */ |
|
685 |
||
686 |
OBJ newFloat; |
|
687 |
double val =__floatVal(self); |
|
688 |
double rslt; |
|
689 |
||
690 |
if (val < 0.0) { |
|
691 |
rslt = -val; |
|
692 |
__qMKFLOAT(newFloat, rslt); |
|
693 |
RETURN ( newFloat ); |
|
694 |
} |
|
695 |
RETURN (self); |
|
696 |
%}. |
|
697 |
^ super abs |
|
698 |
||
699 |
" |
|
700 |
3.0 abs |
|
701 |
-3.0 abs |
|
702 |
" |
|
703 |
! |
|
704 |
||
1 | 705 |
negated |
706 |
"return myself negated" |
|
707 |
||
708 |
%{ /* NOCONTEXT */ |
|
13 | 709 |
|
3 | 710 |
OBJ newFloat; |
1133 | 711 |
double rslt = - __floatVal(self); |
3 | 712 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
713 |
__qMKFLOAT(newFloat, rslt); |
3 | 714 |
RETURN ( newFloat ); |
5411 | 715 |
%}. |
716 |
^ 0.0 - self |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
717 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
718 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
719 |
uncheckedDivide:aNumber |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
720 |
"return the quotient of the receiver and the argument, aNumber. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
721 |
Do not check for divide by zero (return NaN or infinity)" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
722 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
723 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
724 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
725 |
OBJ newFloat; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
726 |
double result, val; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
727 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
728 |
if (__isSmallInteger(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
729 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
730 |
retResult: |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
731 |
__qMKFLOAT(newFloat, result); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
732 |
RETURN ( newFloat ); |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
733 |
} else if (__isFloatLike(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
734 |
val = __floatVal(aNumber); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
735 |
result = __floatVal(self) / val; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
736 |
goto retResult; |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
737 |
} |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
738 |
%} |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
739 |
. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
740 |
^ aNumber quotientFromFloat:self |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
741 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
742 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
743 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
744 |
0.0 uncheckedDivide:0.0 |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
745 |
1.0 uncheckedDivide:0.0 |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
746 |
" |
1 | 747 |
! ! |
748 |
||
701 | 749 |
!Float methodsFor:'binary storage'! |
750 |
||
751 |
storeBinaryDefinitionOn:stream manager:manager |
|
1260 | 752 |
"store the receiver in a binary format on stream. |
753 |
This is an internal interface for binary storage mechanism." |
|
754 |
||
701 | 755 |
manager putIdOfClass:(self class) on:stream. |
756 |
Float storeBinaryIEEEDouble:self on:stream. |
|
1260 | 757 |
|
758 |
"Modified: 23.4.1996 / 09:29:48 / cg" |
|
701 | 759 |
! ! |
760 |
||
5238 | 761 |
!Float methodsFor:'coercing & converting'! |
1 | 762 |
|
3014 | 763 |
asDouble |
764 |
"ST80 compatibility: return a float with same value - thats me" |
|
765 |
||
766 |
^ self |
|
767 |
! |
|
768 |
||
701 | 769 |
asFloat |
770 |
"return a float with same value - thats me" |
|
771 |
||
772 |
^ self |
|
773 |
! |
|
774 |
||
775 |
asInteger |
|
776 |
"return an integer with same value - might truncate" |
|
777 |
||
1 | 778 |
%{ /* NOCONTEXT */ |
1670 | 779 |
double dVal; |
13 | 780 |
|
1670 | 781 |
dVal = __floatVal(self); |
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
782 |
|
1670 | 783 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
784 |
RETURN ( __MKSMALLINT( (INT)dVal) ); |
701 | 785 |
} |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
786 |
%}. |
701 | 787 |
^ super asInteger |
788 |
||
789 |
"12345.0 asInteger" |
|
790 |
"1e15 asInteger" |
|
1 | 791 |
! |
792 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
793 |
asShortFloat |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
794 |
"return a shortFloat with same value as receiver" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
795 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
796 |
%{ /* NOCONTEXT */ |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
797 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
798 |
OBJ dummy = @global(ShortFloat); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
799 |
OBJ newFloat; |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
800 |
float fVal = (float)__floatVal(self); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
801 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
802 |
__qMKSFLOAT(newFloat, fVal); |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
803 |
RETURN ( newFloat ); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
804 |
%} |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
805 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
806 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
807 |
asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
808 |
"Answer a fraction that EXACTLY represents self, |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
809 |
a double precision IEEE floating point number. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
810 |
Floats are stored in the same form on all platforms. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
811 |
(Does not handle gradual underflow or NANs.) |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
812 |
By David N. Smith with significant performance |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
813 |
improvements by Luciano Esteban Notarfrancesco. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
814 |
(Version of 11April97)" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
815 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
816 |
|shifty sign expPart exp fraction fractionPart result zeroBitsCount| |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
817 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
818 |
self isInfinite ifTrue: [self error: 'Cannot represent infinity as a fraction']. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
819 |
self isNaN ifTrue: [self error: 'Cannot represent Not-a-Number as a fraction']. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
820 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
821 |
"Extract the bits of an IEEE double float " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
822 |
UninterpretedBytes isBigEndian ifTrue:[ |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
823 |
"/ shifty := ((self basicAt: 1) bitShift: 32) + (self basicAt: 2). |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
824 |
shifty := LargeInteger basicNew numberOfDigits:8. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
825 |
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
|
826 |
] ifFalse:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
827 |
shifty := LargeInteger basicNew numberOfDigits:8. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
828 |
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
|
829 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
830 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
831 |
" Extract the sign and the biased exponent " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
832 |
sign := (shifty bitShift: -63) = 0 ifTrue: [1] ifFalse: [-1]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
833 |
expPart := (shifty bitShift: -52) bitAnd: 16r7FF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
834 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
835 |
" 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
|
836 |
fractionPart := shifty bitAnd: 16r000FFFFFFFFFFFFF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
837 |
( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0 ]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
838 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
839 |
" Replace omitted leading 1 in fraction " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
840 |
fraction := fractionPart bitOr: 16r0010000000000000. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
841 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
842 |
"Unbias exponent: 16r3FF is bias; 52 is fraction width" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
843 |
exp := 16r3FF + 52 - expPart. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
844 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
845 |
" 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
|
846 |
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
|
847 |
the (huge) time otherwise spent in #gcd:. " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
848 |
exp negative ifTrue: [ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
849 |
result := sign * fraction bitShift: exp negated |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
850 |
] ifFalse:[ |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
851 |
zeroBitsCount := fraction lowBit - 1. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
852 |
exp := exp - zeroBitsCount. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
853 |
exp <= 0 ifTrue: [ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
854 |
zeroBitsCount := zeroBitsCount + exp. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
855 |
"exp := 0." " Not needed; exp not refernced again " |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
856 |
result := sign * fraction bitShift:zeroBitsCount negated |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
857 |
] ifFalse: [ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
858 |
result := Fraction |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
859 |
numerator: (sign * fraction bitShift: zeroBitsCount negated) |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
860 |
denominator: (1 bitShift:exp) |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
861 |
] |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
862 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
863 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
864 |
"Low cost validation omitted after extensive testing" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
865 |
"(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']." |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
866 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
867 |
^ result |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
868 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
869 |
" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
870 |
0.3 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
871 |
1.25 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
872 |
0.25 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
873 |
-0.25 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
874 |
3e37 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
875 |
" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
876 |
! |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
877 |
|
701 | 878 |
coerce:aNumber |
879 |
"return aNumber converted into receivers type" |
|
1 | 880 |
|
701 | 881 |
^ aNumber asFloat |
882 |
! |
|
13 | 883 |
|
701 | 884 |
generality |
885 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
886 |
||
887 |
^ 80 |
|
1 | 888 |
! ! |
889 |
||
890 |
!Float methodsFor:'comparing'! |
|
891 |
||
892 |
< aNumber |
|
893 |
"return true, if the argument is greater" |
|
894 |
||
895 |
%{ /* NOCONTEXT */ |
|
13 | 896 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
897 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
898 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
899 |
RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
900 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
901 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
902 |
RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false ); |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
903 |
} |
1 | 904 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
905 |
%}. |
1 | 906 |
^ aNumber lessFromFloat:self |
907 |
! |
|
908 |
||
909 |
<= aNumber |
|
910 |
"return true, if the argument is greater or equal" |
|
911 |
||
912 |
%{ /* NOCONTEXT */ |
|
13 | 913 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
914 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
915 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
916 |
RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
917 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
918 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
919 |
RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false ); |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
920 |
} |
1 | 921 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
922 |
%}. |
1 | 923 |
^ self retry:#<= coercing:aNumber |
924 |
! |
|
925 |
||
926 |
= aNumber |
|
175 | 927 |
"return true, if the arguments value are equal by value" |
1 | 928 |
|
929 |
%{ /* NOCONTEXT */ |
|
13 | 930 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
931 |
if (aNumber != nil) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
932 |
if (__isSmallInteger(aNumber)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
933 |
RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
934 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
935 |
if (__qIsFloatLike(aNumber)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
936 |
RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
937 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
938 |
if (__qClass(aNumber)==ShortFloat) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
939 |
RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
940 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
941 |
} else { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
942 |
RETURN (false); |
1 | 943 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
944 |
%}. |
1 | 945 |
^ self retry:#= coercing:aNumber |
946 |
! |
|
947 |
||
701 | 948 |
> aNumber |
949 |
"return true, if the argument is less" |
|
1 | 950 |
|
951 |
%{ /* NOCONTEXT */ |
|
13 | 952 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
953 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
954 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
955 |
RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
956 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
957 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
958 |
RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false ); |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
959 |
} |
1 | 960 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
961 |
%}. |
701 | 962 |
^ self retry:#> coercing:aNumber |
963 |
! |
|
964 |
||
965 |
>= aNumber |
|
966 |
"return true, if the argument is less or equal" |
|
967 |
||
968 |
%{ /* NOCONTEXT */ |
|
969 |
||
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
970 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
971 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
972 |
RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
973 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
974 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
975 |
RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false ); |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
976 |
} |
701 | 977 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
978 |
%}. |
701 | 979 |
^ self retry:#>= coercing:aNumber |
92 | 980 |
! |
981 |
||
982 |
hash |
|
983 |
"return a number for hashing; redefined, since floats compare |
|
984 |
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
|
985 |
as 3 hash." |
92 | 986 |
|
305 | 987 |
|i| |
92 | 988 |
|
989 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
990 |
i := self asInteger. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
991 |
self = i ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
992 |
^ i hash |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
993 |
]. |
92 | 994 |
]. |
995 |
||
996 |
" |
|
305 | 997 |
mhmh take some of my value-bits to hash on |
92 | 998 |
" |
4590 | 999 |
^ (((self basicAt:8) bitAnd:16r1F) bitShift:24) + |
305 | 1000 |
((self basicAt:7) bitShift:16) + |
1001 |
((self basicAt:6) bitShift:8) + |
|
4592 | 1002 |
(((self basicAt:5) + (self basicAt:1) + (self basicAt:2)) bitAnd:16rFF) |
92 | 1003 |
|
1004 |
" |
|
1005 |
3 hash |
|
1006 |
3.0 hash |
|
1007 |
3.1 hash |
|
1008 |
3.14159 hash |
|
1009 |
31.4159 hash |
|
1010 |
3.141591 hash |
|
1011 |
1.234567890123456 hash |
|
1012 |
1.234567890123457 hash |
|
1013 |
Set withAll:#(3 3.0 99 99.0 3.1415) |
|
1014 |
" |
|
1 | 1015 |
! |
1016 |
||
701 | 1017 |
~= aNumber |
1018 |
"return true, if the arguments value are not equal" |
|
1 | 1019 |
|
1020 |
%{ /* NOCONTEXT */ |
|
1021 |
||
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1022 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1023 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1024 |
RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1025 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1026 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1027 |
RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1028 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1029 |
} else { |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1030 |
RETURN (true); |
1 | 1031 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1032 |
%}. |
701 | 1033 |
^ self retry:#~= coercing:aNumber |
1 | 1034 |
! ! |
1035 |
||
1036 |
!Float methodsFor:'mathematical functions'! |
|
1037 |
||
701 | 1038 |
arcCos |
1039 |
"return the arccosine of myself as radians" |
|
1040 |
||
1041 |
%{ /* NOCONTEXT */ |
|
1042 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1043 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1044 |
OBJ newFloat; |
701 | 1045 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1046 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1047 |
rslt = acos(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1048 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1049 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1050 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1051 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1052 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1053 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1054 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1055 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1056 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1057 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1058 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1059 |
selector:#arcCos |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1060 |
errorString:'bad receiver in arcCos' |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1061 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1062 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1063 |
-10 arcCos |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1064 |
1 arcCos |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1065 |
" |
701 | 1066 |
! |
1067 |
||
1068 |
arcSin |
|
1069 |
"return the arcsine of myself as radians" |
|
1070 |
||
1071 |
%{ /* NOCONTEXT */ |
|
1072 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1073 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1074 |
OBJ newFloat; |
701 | 1075 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1076 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1077 |
rslt = asin(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1078 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1079 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1080 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1081 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1082 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1083 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1084 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1085 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1086 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1087 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1088 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1089 |
selector:#arcSin |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1090 |
errorString:'bad receiver in arcSin' |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1091 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1092 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1093 |
-10 arcSin |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1094 |
1 arcSin |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1095 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1096 |
|
701 | 1097 |
! |
1098 |
||
1099 |
arcTan |
|
1100 |
"return the arctangent of myself as radians" |
|
1101 |
||
1102 |
%{ /* NOCONTEXT */ |
|
1103 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1104 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1105 |
OBJ newFloat; |
701 | 1106 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1107 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1108 |
rslt = atan(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1109 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1110 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1111 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1112 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1113 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1114 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1115 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1116 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1117 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1118 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1119 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1120 |
selector:#arcTan |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1121 |
errorString:'bad receiver in arcTan' |
701 | 1122 |
! |
1123 |
||
1124 |
cos |
|
1125 |
"return the cosine of myself interpreted as radians" |
|
1126 |
||
1127 |
%{ /* NOCONTEXT */ |
|
1128 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1129 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1130 |
OBJ newFloat; |
701 | 1131 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1132 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1133 |
rslt = cos(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1134 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1135 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1136 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1137 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1138 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1139 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1140 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1141 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1142 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1143 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1144 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1145 |
selector:#cos |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1146 |
errorString:'bad receiver in cos' |
701 | 1147 |
! |
1148 |
||
1149 |
exp |
|
1150 |
"return e raised to the power of the receiver" |
|
1151 |
||
1152 |
%{ /* NOCONTEXT */ |
|
1153 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1154 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1155 |
OBJ newFloat; |
701 | 1156 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1157 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1158 |
rslt = exp(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1159 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1160 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1161 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1162 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1163 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1164 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1165 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1166 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1167 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1168 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1169 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1170 |
selector:#exp |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1171 |
errorString:'bad receiver in exp' |
701 | 1172 |
! |
1173 |
||
1 | 1174 |
ln |
1175 |
"return the natural logarithm of myself" |
|
1176 |
||
1177 |
%{ /* NOCONTEXT */ |
|
1178 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1179 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1180 |
OBJ newFloat; |
1 | 1181 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1182 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1183 |
rslt = log(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1184 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1185 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1186 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1187 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1188 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1189 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1190 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1191 |
%}. |
142 | 1192 |
" |
1193 |
an invalid value for logarithm |
|
1194 |
" |
|
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1195 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1196 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1197 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1198 |
selector:#ln |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1199 |
errorString:'bad receiver in ln' |
1 | 1200 |
! |
1201 |
||
1202 |
raisedTo:aNumber |
|
1203 |
"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
|
1204 |
|
1 | 1205 |
|n| |
1206 |
||
1207 |
n := aNumber asFloat. |
|
1208 |
%{ |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1209 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1210 |
OBJ newFloat; |
1 | 1211 |
|
283 | 1212 |
if (__isFloatLike(n)) { |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1213 |
__threadErrno = 0; |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1214 |
rslt = pow(__floatVal(self), __floatVal(n)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1215 |
#ifdef LINUX /* and maybe others */ |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1216 |
if (! isnan(rslt)) |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1217 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1218 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1219 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1220 |
RETURN ( newFloat ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1221 |
} |
1 | 1222 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1223 |
%}. |
142 | 1224 |
" |
1225 |
an invalid argument (not convertable to float ?) |
|
1226 |
" |
|
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1227 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1228 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1229 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1230 |
selector:#raisedTo: |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1231 |
arg:aNumber |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1232 |
errorString:'bad receiver/arg in raisedTo:' |
1 | 1233 |
! |
1234 |
||
1235 |
sin |
|
1236 |
"return the sine of myself interpreted as radians" |
|
1237 |
||
1238 |
%{ /* NOCONTEXT */ |
|
1239 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1240 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1241 |
OBJ newFloat; |
1 | 1242 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1243 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1244 |
rslt = sin(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1245 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1246 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1247 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1248 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1249 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1250 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1251 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1252 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1253 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1254 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1255 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1256 |
selector:#sin |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1257 |
errorString:'bad receiver in sin' |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1258 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1259 |
|
1 | 1260 |
! |
1261 |
||
1262 |
sqrt |
|
1263 |
"return the square root of myself" |
|
1264 |
||
1265 |
%{ /* NOCONTEXT */ |
|
1266 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1267 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1268 |
OBJ newFloat; |
1 | 1269 |
|
3889
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1270 |
#ifdef WIN32 |
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1271 |
if (__floatVal(self) >= 0.0) |
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1272 |
#endif |
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1273 |
{ |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1274 |
__threadErrno = 0; |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1275 |
rslt = sqrt(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1276 |
#ifdef LINUX /* and maybe others */ |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1277 |
if (! isnan(rslt)) |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1278 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1279 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1280 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1281 |
RETURN ( newFloat ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1282 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1283 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1284 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1285 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1286 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1287 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1288 |
selector:#sqrt |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1289 |
errorString:'bad receiver in sqrt' |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1290 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1291 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1292 |
10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1293 |
-10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1294 |
" |
701 | 1295 |
! |
258 | 1296 |
|
701 | 1297 |
tan |
1298 |
"return the tangent of myself interpreted as radians" |
|
258 | 1299 |
|
1300 |
%{ /* NOCONTEXT */ |
|
1301 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1302 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1303 |
OBJ newFloat; |
44 | 1304 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1305 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1306 |
rslt = tan(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1307 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1308 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1309 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1310 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1311 |
__qMKFLOAT(newFloat, rslt); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1312 |
RETURN ( newFloat ); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1313 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1314 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1315 |
^ self class |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1316 |
raise:#domainErrorSignal |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1317 |
receiver:self |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1318 |
selector:#tan |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1319 |
errorString:'bad receiver in tan' |
13 | 1320 |
! ! |
1321 |
||
92 | 1322 |
!Float methodsFor:'printing & storing'! |
1 | 1323 |
|
1324 |
printString |
|
2358 | 1325 |
"return a printed representation of the receiver; |
1326 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1327 |
6 valid digits are printed. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1328 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1329 |
#printOn: as basic print mechanism." |
1 | 1330 |
|
1331 |
%{ /* NOCONTEXT */ |
|
1332 |
||
13 | 1333 |
char buffer[64]; |
1 | 1334 |
REGISTER char *cp; |
314 | 1335 |
OBJ s; |
2358 | 1336 |
char *fmt; |
1337 |
char fmtBuffer[20]; |
|
1338 |
||
1339 |
if (__isString(@global(DefaultPrintFormat))) { |
|
5317
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1340 |
fmt = (char *) __stringVal(@global(DefaultPrintFormat)); |
2358 | 1341 |
} else { |
5317
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1342 |
/* |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1343 |
* in case we get called before #initialize ... |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1344 |
*/ |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1345 |
fmt = ".6"; |
2358 | 1346 |
} |
1347 |
||
1348 |
/* |
|
1349 |
* build a printf format string |
|
1350 |
*/ |
|
1351 |
fmtBuffer[0] = '%'; |
|
1352 |
strncpy(fmtBuffer+1, fmt, 10); |
|
1353 |
#ifdef SYSV |
|
1354 |
strcat(fmtBuffer, "lg"); |
|
1355 |
#else |
|
1356 |
strcat(fmtBuffer, "G"); |
|
1357 |
#endif |
|
314 | 1358 |
|
2358 | 1359 |
sprintf(buffer, fmtBuffer, __floatVal(self)); |
1 | 1360 |
|
1361 |
/* |
|
13 | 1362 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
1 | 1363 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
1364 |
*/ |
|
1365 |
for (cp = buffer; *cp; cp++) { |
|
5317
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1366 |
if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
1 | 1367 |
} |
1368 |
if (! *cp) { |
|
5317
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1369 |
*cp++ = '.'; |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1370 |
*cp++ = '0'; |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1371 |
*cp = '\0'; |
1 | 1372 |
} |
1373 |
||
1133 | 1374 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 1375 |
if (s != nil) { |
5317
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1376 |
RETURN (s); |
314 | 1377 |
} |
1378 |
%}. |
|
1379 |
" |
|
1380 |
memory allocation (for the new string) failed. |
|
1381 |
When we arrive here, there was no memory, even after a garbage collect. |
|
1382 |
This means, that the VM wanted to get some more memory from the |
|
1383 |
OS, which was not kind enough to give it. |
|
1384 |
Bad luck - you should increase the swap space on your machine. |
|
1385 |
" |
|
1386 |
^ ObjectMemory allocationFailureSignal raise. |
|
1387 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1388 |
" |
5317
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1389 |
1.0 printString |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1390 |
1.234 printString |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1391 |
1e10 printString |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1392 |
1.2e3 printString |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1393 |
1.2e30 printString |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1394 |
(1.0 uncheckedDivide:0) printString |
6004c4c2a916
oops - printString was wrong when exponent was involved
Claus Gittinger <cg@exept.de>
parents:
5238
diff
changeset
|
1395 |
(0.0 uncheckedDivide:0) printString |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1396 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1397 |
|
1 | 1398 |
! |
1399 |
||
1400 |
printfPrintString:formatString |
|
1401 |
"non-portable: return a printed representation of the receiver |
|
1402 |
as specified by formatString, which is defined by printf. |
|
31 | 1403 |
If you use this, be aware, that specifying doubles differs on |
1 | 1404 |
systems; on SYSV machines you have to give something like %lf, |
13 | 1405 |
while on BSD systems the format string has to be %F. |
31 | 1406 |
Also, the resulting string may not be longer than 255 bytes - |
54 | 1407 |
since thats the (static) size of the buffer. |
1408 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 1409 |
|
13 | 1410 |
%{ /* STACK: 400 */ |
1 | 1411 |
char buffer[256]; |
314 | 1412 |
OBJ s; |
1 | 1413 |
|
54 | 1414 |
if (__isString(formatString)) { |
1133 | 1415 |
sprintf(buffer, __stringVal(formatString), __floatVal(self)); |
369 | 1416 |
|
1133 | 1417 |
s = __MKSTRING(buffer COMMA_SND); |
343 | 1418 |
if (s != nil) { |
1419 |
RETURN (s); |
|
1420 |
} |
|
1 | 1421 |
} |
314 | 1422 |
%}. |
1 | 1423 |
self primitiveFailed |
1424 |
||
1425 |
"Float pi printfPrintString:'%%lg -> %lg'" |
|
1426 |
"Float pi printfPrintString:'%%lf -> %lf'" |
|
1427 |
"Float pi printfPrintString:'%%7.5lg -> %7.5lg'" |
|
1428 |
"Float pi printfPrintString:'%%7.5lf -> %7.5lf'" |
|
1429 |
"Float pi printfPrintString:'%%G -> %G'" |
|
1430 |
"Float pi printfPrintString:'%%F -> %F'" |
|
1431 |
"Float pi printfPrintString:'%%7.5G -> %7.5G'" |
|
1432 |
"Float pi printfPrintString:'%%7.5F -> %7.5F'" |
|
1433 |
! ! |
|
701 | 1434 |
|
1435 |
!Float methodsFor:'private accessing'! |
|
1436 |
||
1437 |
basicAt:index |
|
1438 |
"return an internal byte of the float. |
|
1439 |
The value returned here depends on byte order, float representation etc. |
|
1440 |
Therefore, this method should be used strictly private. |
|
1441 |
||
1442 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1443 |
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
|
1444 |
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
|
1445 |
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
|
1446 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1447 |
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
|
1448 |
values as if this filler wasnt present." |
701 | 1449 |
|
1450 |
%{ /* NOCONTEXT */ |
|
1451 |
||
1452 |
register int indx; |
|
1453 |
unsigned char *cp; |
|
1454 |
||
1455 |
/* |
|
1456 |
* notice the missing test for self being a nonNilObject - |
|
1457 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1458 |
* and SmallInteger |
|
1459 |
*/ |
|
1460 |
if (__isSmallInteger(index)) { |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1461 |
indx = __intVal(index) - 1; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1462 |
if (((unsigned)(indx)) < sizeof(double)) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1463 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1464 |
RETURN ( __MKSMALLINT(cp[indx] & 0xFF) ); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1465 |
} |
701 | 1466 |
} |
1467 |
%}. |
|
1468 |
index isInteger ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1469 |
^ self indexNotInteger |
701 | 1470 |
]. |
1471 |
^ self subscriptBoundsError:index |
|
1472 |
! |
|
1473 |
||
1474 |
basicAt:index put:value |
|
1475 |
"set an internal byte of the float. |
|
1476 |
The value to be stored here depends on byte order, float representation etc. |
|
1477 |
Therefore, this method should be used strictly private. |
|
1478 |
||
1479 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1480 |
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
|
1481 |
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
|
1482 |
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
|
1483 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1484 |
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
|
1485 |
values as if this filler wasnt present." |
701 | 1486 |
|
1487 |
%{ /* NOCONTEXT */ |
|
1488 |
register int indx, val; |
|
1489 |
unsigned char *cp; |
|
1490 |
||
1491 |
/* |
|
1492 |
* notice the missing test for self being a nonNilObject - |
|
1493 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1494 |
* and SmallInteger |
|
1495 |
*/ |
|
1496 |
if (__bothSmallInteger(index, value)) { |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1497 |
val = __intVal(value); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1498 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1499 |
indx = __intVal(index) - 1; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1500 |
if (((unsigned)(indx)) < sizeof(double)) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1501 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1502 |
cp[indx] = val; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1503 |
RETURN ( value ); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1504 |
} |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1505 |
} |
701 | 1506 |
} |
1507 |
%}. |
|
1508 |
index isInteger ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1509 |
^ self indexNotInteger |
701 | 1510 |
]. |
1511 |
value isInteger ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1512 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1513 |
the object to store should be an integer number |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1514 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1515 |
^ self elementNotInteger |
701 | 1516 |
]. |
1517 |
(value between:0 and:255) ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1518 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1519 |
the object to store must be a bytes value |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1520 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1521 |
^ self elementBoundsError |
701 | 1522 |
]. |
1523 |
^ self subscriptBoundsError:index |
|
4592 | 1524 |
! |
1525 |
||
1526 |
basicSize |
|
1527 |
"return the size in bytes of the float. |
|
1528 |
||
1529 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1530 |
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
|
1531 |
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
|
1532 |
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
|
1533 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1534 |
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
|
1535 |
values as if this filler wasnt present." |
4592 | 1536 |
|
1537 |
%{ /* NOCONTEXT */ |
|
1538 |
||
1539 |
RETURN (__MKSMALLINT(sizeof(double))); |
|
1540 |
%}. |
|
701 | 1541 |
! ! |
1542 |
||
3896 | 1543 |
!Float methodsFor:'special access'! |
1544 |
||
1545 |
exponent |
|
1546 |
"extract a normalized floats exponent. |
|
1547 |
The returned value depends on the float-representation of |
|
1548 |
the underlying machine and is therefore highly unportable. |
|
1549 |
This is not for general use. |
|
1550 |
This assumes that the mantissa is normalized to |
|
1551 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1552 |
||
1553 |
%{ /* NOCONTEXT */ |
|
1554 |
||
1555 |
double frexp(); |
|
1556 |
double frac; |
|
1557 |
INT exp; |
|
1558 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1559 |
__threadErrno = 0; |
3896 | 1560 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1561 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1562 |
RETURN (__MKSMALLINT(exp)); |
3896 | 1563 |
} |
1564 |
%}. |
|
1565 |
^ self primitiveFailed |
|
1566 |
||
1567 |
" |
|
1568 |
1.0 exponent |
|
1569 |
2.0 exponent |
|
1570 |
3.0 exponent |
|
1571 |
4.0 exponent |
|
1572 |
0.5 exponent |
|
1573 |
0.4 exponent |
|
1574 |
0.25 exponent |
|
1575 |
0.00000011111 exponent |
|
1576 |
" |
|
1577 |
! |
|
1578 |
||
1579 |
mantissa |
|
1580 |
"extract a normalized floats mantissa. |
|
1581 |
The returned value depends on the float-representation of |
|
1582 |
the underlying machine and is therefore highly unportable. |
|
1583 |
This is not for general use. |
|
1584 |
This assumes that the mantissa is normalized to |
|
1585 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1586 |
||
1587 |
%{ /* NOCONTEXT */ |
|
1588 |
||
1589 |
double frexp(); |
|
1590 |
double frac; |
|
1591 |
INT exp; |
|
1592 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1593 |
__threadErrno = 0; |
3896 | 1594 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1595 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1596 |
RETURN (__MKFLOAT(frac)); |
3896 | 1597 |
} |
1598 |
%}. |
|
1599 |
^ self primitiveFailed |
|
1600 |
||
1601 |
" |
|
1602 |
1.0 exponent |
|
1603 |
1.0 mantissa |
|
1604 |
||
1605 |
0.25 exponent |
|
1606 |
0.25 mantissa |
|
1607 |
||
1608 |
0.00000011111 exponent |
|
1609 |
0.00000011111 mantissa |
|
1610 |
" |
|
1611 |
! ! |
|
1612 |
||
701 | 1613 |
!Float methodsFor:'testing'! |
1614 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1615 |
isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1616 |
"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
|
1617 |
i.e. not NaN and not infinite." |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1618 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1619 |
%{ /* NOCONTEXT */ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1620 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1621 |
double dV = __floatVal(self); |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1622 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1623 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1624 |
* 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
|
1625 |
* a finite() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1626 |
* 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
|
1627 |
*/ |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1628 |
if (finite(dV)) { |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1629 |
RETURN (true); |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1630 |
} |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1631 |
%}. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1632 |
^false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1633 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1634 |
" |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1635 |
1.0 isFinite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1636 |
(0.0 uncheckedDivide: 0.0) isFinite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1637 |
(1.0 uncheckedDivide: 0.0) isFinite |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1638 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1639 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1640 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1641 |
isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1642 |
"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
|
1643 |
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
|
1644 |
however, inline C-code could produce them ... |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1645 |
Redefined here for speed" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1646 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1647 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1648 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1649 |
double dV = __floatVal(self); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1650 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1651 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1652 |
* 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
|
1653 |
* finite() & isnan() macros or functions (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1654 |
* 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
|
1655 |
*/ |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1656 |
#if defined(isinf) || defined(LINUX) |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1657 |
if (isinf(dV)) { RETURN (true); } |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1658 |
#else |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1659 |
if (!finite(dV) && !isnan(dV)) { RETURN (true); } |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1660 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1661 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1662 |
^ false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1663 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1664 |
" |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1665 |
1.0 isInfinite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1666 |
(0.0 uncheckedDivide: 0.0) isInfinite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1667 |
(1.0 uncheckedDivide: 0.0) isInfinite |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1668 |
" |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1669 |
! |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1670 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1671 |
isLiteral |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1672 |
"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
|
1673 |
(i.e. can be used in constant arrays)" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1674 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1675 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1676 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1677 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1678 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1679 |
|
2387 | 1680 |
isNaN |
1681 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
1682 |
These are not created by ST/X float operations (they raise an exception); |
|
1683 |
however, inline C-code could produce them ..." |
|
1684 |
||
1685 |
%{ /* NOCONTEXT */ |
|
1686 |
||
3139 | 1687 |
double dV = (__floatVal(self)); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1688 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1689 |
if (isnan(dV)) { RETURN (true); } |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1690 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1691 |
#if 0 /* Currently all our systems support isnan() |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1692 |
* If not, you have to fix librun/jinterpret.c also. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1693 |
*/ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1694 |
|
2395 | 1695 |
/* |
1696 |
* sigh - every vendor is playing its own game here ... |
|
1697 |
* Q: what are standards worth, anyway ? |
|
1698 |
*/ |
|
2392 | 1699 |
#ifdef IS_NAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1700 |
if (IS_NAN(dV)) { RETURN (true); } |
3139 | 1701 |
RETURN (false); |
2393 | 1702 |
#endif |
3139 | 1703 |
|
2393 | 1704 |
#ifdef IS_QNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1705 |
if (IS_QNAN(dV)) { RETURN (true); } |
3139 | 1706 |
RETURN (false); |
2393 | 1707 |
#endif |
2392 | 1708 |
|
2393 | 1709 |
#ifdef FLT_SNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1710 |
if (dV == FLT_SNAN) { RETURN (true); } |
3139 | 1711 |
RETURN (false); |
2393 | 1712 |
#endif |
3139 | 1713 |
|
2393 | 1714 |
#ifdef FLT_QNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1715 |
if (dV == FLT_QNAN) { RETURN (true); } |
3139 | 1716 |
RETURN (false); |
2393 | 1717 |
#endif |
1718 |
||
1719 |
#ifdef _SNANF |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1720 |
if (dV == _SNAN) { RETURN (true); } |
3139 | 1721 |
RETURN (false); |
2393 | 1722 |
#endif |
3139 | 1723 |
|
2393 | 1724 |
#ifdef _QNANF |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1725 |
if (dV == _QNAN) { RETURN (true); } |
3139 | 1726 |
RETURN (false); |
2393 | 1727 |
#endif |
2392 | 1728 |
|
2395 | 1729 |
#ifdef IsPosNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1730 |
if IsPosNAN(dV) { RETURN (true); } |
3139 | 1731 |
RETURN (false); |
2395 | 1732 |
#endif |
3139 | 1733 |
|
2395 | 1734 |
#ifdef IsNegNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1735 |
if IsNegNAN(dV) { RETURN (true); } |
3139 | 1736 |
RETURN (false); |
2395 | 1737 |
#endif |
1738 |
||
2393 | 1739 |
#ifdef NAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1740 |
if (dV == NAN) { RETURN (true); } |
3139 | 1741 |
RETURN (false); |
2390 | 1742 |
#endif |
3139 | 1743 |
|
2399 | 1744 |
#ifdef NaN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1745 |
if (NaN(dV)) { RETURN (true); } |
3139 | 1746 |
RETURN (false); |
2399 | 1747 |
#endif |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1748 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1749 |
#endif /* 0 */ |
2392 | 1750 |
%}. |
1751 |
^ false |
|
3139 | 1752 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1753 |
" |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1754 |
1.0 isNaN |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1755 |
(0.0 uncheckedDivide: 0.0) isNaN |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1756 |
" |
2387 | 1757 |
! |
1758 |
||
701 | 1759 |
negative |
1760 |
"return true if the receiver is less than zero" |
|
1761 |
||
1762 |
%{ /* NOCONTEXT */ |
|
1763 |
||
1133 | 1764 |
RETURN ( (__floatVal(self) < 0.0) ? true : false ); |
5411 | 1765 |
%}. |
1766 |
^ self < 0.0 |
|
701 | 1767 |
! |
1768 |
||
5357 | 1769 |
numberOfBits |
1770 |
"return the size (in bits) of the real; |
|
1771 |
typically, 64 is returned here, |
|
1772 |
but who knows ..." |
|
1773 |
||
1774 |
%{ /* NOCONTEXT */ |
|
1775 |
||
1776 |
RETURN (__MKSMALLINT (sizeof(double) * 8)); |
|
1777 |
%} |
|
1778 |
||
1779 |
" |
|
1780 |
1.2 numberOfBits |
|
1781 |
1.2 asShortFloat numberOfBits |
|
1782 |
" |
|
1783 |
! |
|
1784 |
||
701 | 1785 |
positive |
1786 |
"return true if the receiver is greater or equal to zero" |
|
1787 |
||
1788 |
%{ /* NOCONTEXT */ |
|
1789 |
||
1133 | 1790 |
RETURN ( (__floatVal(self) >= 0.0) ? true : false ); |
701 | 1791 |
%} |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1792 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1793 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1794 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1795 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1796 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1797 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1798 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1799 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1800 |
%} |
701 | 1801 |
! ! |
1802 |
||
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1803 |
!Float methodsFor:'tracing'! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1804 |
|
4682 | 1805 |
traceInto:aRequestor level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1806 |
"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
|
1807 |
|
4682 | 1808 |
^ aRequestor traceFloat:self level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1809 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1810 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1811 |
! ! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1812 |
|
701 | 1813 |
!Float methodsFor:'truncation and rounding'! |
1814 |
||
1815 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1816 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 1817 |
|
1818 |
|val| |
|
1819 |
||
1820 |
%{ |
|
1821 |
double dVal; |
|
1822 |
||
1823 |
/* |
|
1824 |
* ST-80 (and X3J20) returns integer. |
|
1825 |
*/ |
|
1133 | 1826 |
dVal = ceil(__floatVal(self)); |
701 | 1827 |
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
|
1828 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1829 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1830 |
__qMKFLOAT(val, dVal); |
701 | 1831 |
%}. |
1832 |
^ val asInteger |
|
1833 |
! |
|
1834 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1835 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1836 |
"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
|
1837 |
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
|
1838 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1839 |
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
|
1840 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1841 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1842 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1843 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1844 |
OBJ val; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1845 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1846 |
/* |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1847 |
* ST-80 (and X3J20) returns integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1848 |
*/ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1849 |
dVal = ceil(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1850 |
__qMKFLOAT(val, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1851 |
RETURN (val); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1852 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1853 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1854 |
|
701 | 1855 |
floor |
1856 |
"return the integer nearest the receiver towards negative infinity." |
|
1857 |
||
1858 |
|val| |
|
1859 |
||
1860 |
%{ |
|
1861 |
double dVal; |
|
1862 |
||
1863 |
/* |
|
1864 |
* ST-80 (and X3J20) returns integer. |
|
1865 |
*/ |
|
1133 | 1866 |
dVal = floor(__floatVal(self)); |
701 | 1867 |
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
|
1868 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1869 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1870 |
__qMKFLOAT(val, dVal); |
701 | 1871 |
%}. |
1872 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1873 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1874 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1875 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1876 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1877 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1878 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1879 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1880 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1881 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1882 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1883 |
floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1884 |
"return the integer nearest the receiver towards negative infinity |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1885 |
as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1886 |
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
|
1887 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1888 |
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
|
1889 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1890 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1891 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1892 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1893 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1894 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1895 |
dVal = floor(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1896 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1897 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1898 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1899 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1900 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1901 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1902 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1903 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1904 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1905 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1906 |
|
701 | 1907 |
! |
1908 |
||
3896 | 1909 |
fractionPart |
1910 |
"extract the after-decimal fraction part. |
|
1911 |
the floats value is |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1912 |
float truncated + float fractionalPart" |
3896 | 1913 |
|
1914 |
%{ /* NOCONTEXT */ |
|
1915 |
||
1916 |
double modf(); |
|
1917 |
double frac, trunc; |
|
1918 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1919 |
__threadErrno = 0; |
3896 | 1920 |
frac = modf(__floatVal(self), &trunc); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1921 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1922 |
RETURN (__MKFLOAT(frac)); |
3896 | 1923 |
} |
1924 |
%}. |
|
1925 |
^ self primitiveFailed |
|
1926 |
||
1927 |
" |
|
1928 |
1.0 fractionPart |
|
1929 |
2.0 fractionPart |
|
1930 |
3.0 fractionPart |
|
1931 |
4.0 fractionPart |
|
1932 |
0.5 fractionPart |
|
1933 |
0.25 fractionPart |
|
1934 |
3.14159 fractionPart |
|
1935 |
12345673.14159 fractionPart |
|
1936 |
123456731231231231.14159 fractionPart |
|
1937 |
||
1938 |
3.14159 fractionPart + 3.14159 truncated |
|
1939 |
||
1940 |
12345673.14159 fractionPart + 12345673.14159 truncated |
|
1941 |
||
1942 |
123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated |
|
1943 |
" |
|
1944 |
! |
|
1945 |
||
701 | 1946 |
rounded |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1947 |
"return the receiver rounded to the nearest integer" |
701 | 1948 |
|
1949 |
|val| |
|
1950 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1951 |
%{ |
701 | 1952 |
double dVal; |
1953 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1954 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1955 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1956 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1957 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1958 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1959 |
} |
701 | 1960 |
/* |
1961 |
* ST-80 (and X3J20) returns integer. |
|
1962 |
*/ |
|
1963 |
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
|
1964 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1965 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1966 |
__qMKFLOAT(val, dVal); |
701 | 1967 |
%}. |
1968 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1969 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1970 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1971 |
0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1972 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1973 |
0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1974 |
-0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1975 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1976 |
-0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1977 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1978 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1979 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1980 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1981 |
"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
|
1982 |
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
|
1983 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1984 |
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
|
1985 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1986 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1987 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1988 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1989 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1990 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1991 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1992 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1993 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1994 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1995 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1996 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1997 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1998 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1999 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2000 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2001 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2002 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2003 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2004 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2005 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2006 |
0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2007 |
-0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2008 |
" |
701 | 2009 |
! |
2010 |
||
2011 |
truncated |
|
2012 |
"return the receiver truncated towards zero as an integer" |
|
2013 |
||
2014 |
|val| |
|
2015 |
||
2016 |
%{ |
|
2017 |
double dVal; |
|
2018 |
||
1133 | 2019 |
dVal = __floatVal(self); |
701 | 2020 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2021 |
dVal = ceil(dVal); |
701 | 2022 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2023 |
dVal = floor(dVal); |
701 | 2024 |
} |
2025 |
||
2026 |
/* |
|
2027 |
* ST-80 (and X3J20) returns integer. |
|
2028 |
*/ |
|
2029 |
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
|
2030 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2031 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2032 |
__qMKFLOAT(val, dVal); |
701 | 2033 |
%}. |
2034 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2035 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2036 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2037 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2038 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2039 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2040 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2041 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2042 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2043 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2044 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2045 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2046 |
"return the receiver truncated towards zero as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2047 |
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
|
2048 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2049 |
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
|
2050 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2051 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2052 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2053 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2054 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2055 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2056 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2057 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2058 |
dVal = ceil(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2059 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2060 |
dVal = floor(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2061 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2062 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2063 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2064 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2065 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2066 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2067 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2068 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2069 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2070 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2071 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2072 |
|
701 | 2073 |
! ! |
2074 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2075 |
!Float class methodsFor:'documentation'! |
701 | 2076 |
|
2077 |
version |
|
5411 | 2078 |
^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.109 2000-06-23 19:02:38 cg Exp $' |
701 | 2079 |
! ! |
2387 | 2080 |
Float initialize! |