author | Stefan Vogel <sv@exept.de> |
Tue, 11 Jun 2002 23:43:11 +0200 | |
changeset 6574 | 788f5a36dcb1 |
parent 6344 | f49b43e5b724 |
child 6674 | c383bfa3dc8c |
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 |
5822
4e56f8aadda5
Get nan.h from bits/nan.h for Linux
Stefan Vogel <sv@exept.de>
parents:
5557
diff
changeset
|
50 |
# include <bits/nan.h> |
4825 | 51 |
# endif |
2396 | 52 |
#endif |
4825 | 53 |
|
2399 | 54 |
#if defined(solaris) || defined(sunos) |
2398 | 55 |
# include <nan.h> |
56 |
#endif |
|
2394 | 57 |
|
3129 | 58 |
/* |
59 |
* sigh - some systems define that stuff; others dont. |
|
60 |
* (AIX even declares them as macros, so an external decl |
|
61 |
* will not work below ... |
|
62 |
*/ |
|
3240 | 63 |
#if !defined(_AIX) && !defined(NEXT3) |
3129 | 64 |
|
65 |
# ifdef acos |
|
66 |
double acos(); |
|
67 |
# endif |
|
68 |
# ifdef asin |
|
69 |
double asin(); |
|
70 |
# endif |
|
71 |
# ifndef atan |
|
72 |
double atan(); |
|
73 |
# endif |
|
74 |
# ifndef cos |
|
75 |
double cos(); |
|
76 |
# endif |
|
77 |
# ifndef sin |
|
78 |
double sin(); |
|
79 |
# endif |
|
80 |
# ifndef pow |
|
81 |
double pow(); |
|
82 |
# endif |
|
83 |
# ifndef log |
|
84 |
double log(); |
|
85 |
# endif |
|
86 |
# ifndef exp |
|
87 |
double exp(); |
|
88 |
# endif |
|
89 |
# ifndef sqrt |
|
90 |
double sqrt(); |
|
91 |
# endif |
|
92 |
# ifndef tan |
|
93 |
double tan(); |
|
94 |
# endif |
|
95 |
||
96 |
#endif /* not AIX */ |
|
97 |
||
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
98 |
#ifdef WIN32 |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
99 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
100 |
* no finite(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
101 |
* no isnan(x) ? |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
102 |
*/ |
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 |
|
6341 | 507 |
infinity |
508 |
"return a float representing infinity" |
|
509 |
||
510 |
^ 1.0 uncheckedDivide:0.0 |
|
511 |
! |
|
512 |
||
701 | 513 |
pi |
1260 | 514 |
"return the constant pi as Float" |
1 | 515 |
|
3244 | 516 |
"/ dont expect this many valid digits on all machines; |
517 |
"/ The actual precision is very CPU specific. |
|
518 |
||
6063 | 519 |
^ 3.14159265358979323846264338327950288419716939937510582097494459 |
1260 | 520 |
|
521 |
"Modified: 23.4.1996 / 09:27:02 / cg" |
|
1 | 522 |
! |
523 |
||
6574 | 524 |
precision |
525 |
"answer the precision of a Float |
|
526 |
This is an IEEE float, only the fraction from the normalized mantissa is stored |
|
527 |
and so there is a hidden bit and the mantissa is actually represented |
|
528 |
by 53 binary digits" |
|
529 |
||
530 |
^ 53 |
|
531 |
! |
|
532 |
||
533 |
radix |
|
534 |
"answer the radix of a Float |
|
535 |
This is an IEEE float, which is represented as binary" |
|
536 |
||
537 |
^ 2 |
|
538 |
! |
|
539 |
||
1 | 540 |
unity |
1260 | 541 |
"return the neutral element for multiplication (1.0) as Float" |
1 | 542 |
|
543 |
^ 1.0 |
|
1260 | 544 |
|
545 |
"Modified: 23.4.1996 / 09:27:09 / cg" |
|
1 | 546 |
! |
547 |
||
701 | 548 |
zero |
1260 | 549 |
"return the neutral element for addition (0.0) as Float" |
1 | 550 |
|
701 | 551 |
^ 0.0 |
1260 | 552 |
|
553 |
"Modified: 23.4.1996 / 09:27:15 / cg" |
|
1 | 554 |
! ! |
555 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
556 |
!Float class methodsFor:'queries'! |
3 | 557 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
558 |
hasSharedInstances |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
559 |
"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
|
560 |
with the same value are identical. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
561 |
Although not really shared, floats should be treated |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
562 |
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
|
563 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
564 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
565 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
566 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
567 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
568 |
|
3 | 569 |
isBuiltInClass |
1264 | 570 |
"return true if this class is known by the run-time-system. |
571 |
Here, true is returned for myself, false for subclasses." |
|
3 | 572 |
|
573 |
^ self == Float |
|
1264 | 574 |
|
575 |
"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
|
576 |
! |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
577 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
578 |
isIEEEFormat |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
579 |
"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
|
580 |
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
|
581 |
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
|
582 |
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
|
583 |
machine). |
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
584 |
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
|
585 |
(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
|
586 |
|
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
587 |
^ true "/ this may be a lie |
3 | 588 |
! ! |
589 |
||
1 | 590 |
!Float methodsFor:'arithmetic'! |
591 |
||
701 | 592 |
* aNumber |
593 |
"return the product of the receiver and the argument, aNumber" |
|
594 |
||
595 |
%{ /* NOCONTEXT */ |
|
596 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
597 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
598 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
599 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
600 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
601 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
602 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
603 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
604 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
605 |
*/ |
701 | 606 |
OBJ newFloat; |
607 |
double result; |
|
608 |
||
609 |
if (__isSmallInteger(aNumber)) { |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
610 |
result = __floatVal(self) * (double)(__intVal(aNumber)); |
701 | 611 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
612 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
613 |
RETURN ( newFloat ); |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
614 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
615 |
if (__isFloatLike(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
616 |
result = __floatVal(self) * __floatVal(aNumber); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
617 |
goto retResult; |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
618 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
619 |
if (__isShortFloat(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
620 |
result = __floatVal(self) * (double)(__shortFloatVal(aNumber)); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
621 |
goto retResult; |
701 | 622 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
623 |
%}. |
701 | 624 |
^ aNumber productFromFloat:self |
625 |
! |
|
626 |
||
1 | 627 |
+ aNumber |
628 |
"return the sum of the receiver and the argument, aNumber" |
|
629 |
||
630 |
%{ /* NOCONTEXT */ |
|
13 | 631 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
632 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
633 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
634 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
635 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
636 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
637 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
638 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
639 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
640 |
*/ |
1 | 641 |
OBJ newFloat; |
642 |
double result; |
|
643 |
||
250 | 644 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
645 |
result = __floatVal(self) + (double)(__intVal(aNumber)); |
1 | 646 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
647 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
648 |
RETURN ( newFloat ); |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
649 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
650 |
if (__isFloatLike(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
651 |
result = __floatVal(self) + __floatVal(aNumber); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
652 |
goto retResult; |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
653 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
654 |
if (__isShortFloat(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
655 |
result = __floatVal(self) + (double)(__shortFloatVal(aNumber)); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
656 |
goto retResult; |
1 | 657 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
658 |
%}. |
1 | 659 |
^ aNumber sumFromFloat:self |
660 |
! |
|
661 |
||
662 |
- aNumber |
|
663 |
"return the difference of the receiver and the argument, aNumber" |
|
664 |
||
665 |
%{ /* NOCONTEXT */ |
|
13 | 666 |
|
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
667 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
668 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
669 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
670 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
671 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
672 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
673 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
674 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
675 |
*/ |
1 | 676 |
OBJ newFloat; |
677 |
double result; |
|
678 |
||
250 | 679 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
680 |
result = __floatVal(self) - (double)(__intVal(aNumber)); |
1 | 681 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
682 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
683 |
RETURN ( newFloat ); |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
684 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
685 |
if (__isFloatLike(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
686 |
result = __floatVal(self) - __floatVal(aNumber); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
687 |
goto retResult; |
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
688 |
} |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
689 |
if (__isShortFloat(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
690 |
result = __floatVal(self) - (double)(__shortFloatVal(aNumber)); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
691 |
goto retResult; |
1 | 692 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
693 |
%}. |
1 | 694 |
^ aNumber differenceFromFloat:self |
695 |
! |
|
696 |
||
697 |
/ aNumber |
|
698 |
"return the quotient of the receiver and the argument, aNumber" |
|
699 |
||
700 |
%{ /* NOCONTEXT */ |
|
701 |
||
6064
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
702 |
/* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
703 |
* notice: |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
704 |
* the following inline code handles some common cases, |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
705 |
* and exists as an optimization, to speed up those cases. |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
706 |
* |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
707 |
* Conceptionally, (and for most other argument types), |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
708 |
* mixed arithmetic is implemented by double dispatching |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
709 |
* (see the message send at the bottom) |
04bde2eeb749
comments about double dispatching
Claus Gittinger <cg@exept.de>
parents:
6063
diff
changeset
|
710 |
*/ |
1 | 711 |
OBJ newFloat; |
712 |
double result, val; |
|
713 |
||
250 | 714 |
if (__isSmallInteger(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
715 |
if (aNumber != __MKSMALLINT(0)) { |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
716 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
1 | 717 |
retResult: |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
718 |
__qMKFLOAT(newFloat, result); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
719 |
RETURN ( newFloat ); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
720 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
721 |
} else if (__isFloatLike(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
722 |
val = __floatVal(aNumber); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
723 |
if (val != 0.0) { |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
724 |
result = __floatVal(self) / val; |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
725 |
goto retResult; |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
726 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
727 |
} else if (__isShortFloat(aNumber)) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
728 |
val = (double)(__shortFloatVal(aNumber)); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
729 |
if (val != 0.0) { |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
730 |
result = __floatVal(self) / val; |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
731 |
goto retResult; |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
732 |
} |
1 | 733 |
} |
3530
a1af5dafc3ee
float op shortFloat added inline.
Claus Gittinger <cg@exept.de>
parents:
3472
diff
changeset
|
734 |
%}. |
1 | 735 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
736 |
" |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
737 |
No, you shalt not divide by zero |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
738 |
" |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
739 |
^ DivisionByZeroSignal raiseRequestWith:thisContext. |
1 | 740 |
]. |
741 |
^ aNumber quotientFromFloat:self |
|
742 |
! |
|
743 |
||
5411 | 744 |
abs |
745 |
"return the absolute value of the receiver |
|
746 |
reimplemented here for speed" |
|
747 |
||
748 |
%{ /* NOCONTEXT */ |
|
749 |
||
750 |
OBJ newFloat; |
|
751 |
double val =__floatVal(self); |
|
752 |
double rslt; |
|
753 |
||
754 |
if (val < 0.0) { |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
755 |
rslt = -val; |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
756 |
__qMKFLOAT(newFloat, rslt); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
757 |
RETURN ( newFloat ); |
5411 | 758 |
} |
759 |
RETURN (self); |
|
760 |
%}. |
|
761 |
^ super abs |
|
762 |
||
763 |
" |
|
764 |
3.0 abs |
|
765 |
-3.0 abs |
|
766 |
" |
|
767 |
! |
|
768 |
||
1 | 769 |
negated |
770 |
"return myself negated" |
|
771 |
||
772 |
%{ /* NOCONTEXT */ |
|
13 | 773 |
|
3 | 774 |
OBJ newFloat; |
1133 | 775 |
double rslt = - __floatVal(self); |
3 | 776 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
777 |
__qMKFLOAT(newFloat, rslt); |
3 | 778 |
RETURN ( newFloat ); |
5411 | 779 |
%}. |
780 |
^ 0.0 - self |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
781 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
782 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
783 |
uncheckedDivide:aNumber |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
784 |
"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
|
785 |
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
|
786 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
787 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
788 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
789 |
OBJ newFloat; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
790 |
double result, val; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
791 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
792 |
if (__isSmallInteger(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
793 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
794 |
retResult: |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
795 |
__qMKFLOAT(newFloat, result); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
796 |
RETURN ( newFloat ); |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
797 |
} else if (__isFloatLike(aNumber)) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
798 |
val = __floatVal(aNumber); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
799 |
result = __floatVal(self) / val; |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
800 |
goto retResult; |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
801 |
} |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
802 |
%} |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
803 |
. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
804 |
^ aNumber quotientFromFloat:self |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
805 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
806 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
807 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
808 |
0.0 uncheckedDivide:0.0 |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
809 |
1.0 uncheckedDivide:0.0 |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
810 |
" |
1 | 811 |
! ! |
812 |
||
701 | 813 |
!Float methodsFor:'binary storage'! |
814 |
||
815 |
storeBinaryDefinitionOn:stream manager:manager |
|
1260 | 816 |
"store the receiver in a binary format on stream. |
817 |
This is an internal interface for binary storage mechanism." |
|
818 |
||
701 | 819 |
manager putIdOfClass:(self class) on:stream. |
820 |
Float storeBinaryIEEEDouble:self on:stream. |
|
1260 | 821 |
|
822 |
"Modified: 23.4.1996 / 09:29:48 / cg" |
|
701 | 823 |
! ! |
824 |
||
5238 | 825 |
!Float methodsFor:'coercing & converting'! |
1 | 826 |
|
3014 | 827 |
asDouble |
828 |
"ST80 compatibility: return a float with same value - thats me" |
|
829 |
||
830 |
^ self |
|
831 |
! |
|
832 |
||
701 | 833 |
asFloat |
834 |
"return a float with same value - thats me" |
|
835 |
||
836 |
^ self |
|
837 |
! |
|
838 |
||
839 |
asInteger |
|
840 |
"return an integer with same value - might truncate" |
|
841 |
||
1 | 842 |
%{ /* NOCONTEXT */ |
1670 | 843 |
double dVal; |
13 | 844 |
|
1670 | 845 |
dVal = __floatVal(self); |
3427
ba90490c94b6
added query for IEE format (for future use)
Claus Gittinger <cg@exept.de>
parents:
3414
diff
changeset
|
846 |
|
1670 | 847 |
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
|
848 |
RETURN ( __MKSMALLINT( (INT)dVal) ); |
701 | 849 |
} |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
850 |
%}. |
701 | 851 |
^ super asInteger |
852 |
||
853 |
"12345.0 asInteger" |
|
854 |
"1e15 asInteger" |
|
1 | 855 |
! |
856 |
||
5986 | 857 |
asLongFloat |
858 |
"return a longFloat with same value as receiver" |
|
859 |
||
860 |
%{ /* NOCONTEXT */ |
|
861 |
#ifdef LONGFLOAT |
|
862 |
OBJ dummy = @global(LongFloat); |
|
863 |
OBJ newFloat; |
|
864 |
LONGFLOAT fVal = (LONGFLOAT)__floatVal(self); |
|
865 |
||
866 |
__qMKLFLOAT(newFloat, fVal); |
|
867 |
RETURN ( newFloat ); |
|
868 |
#endif |
|
869 |
%}. |
|
870 |
^ self |
|
871 |
||
872 |
" |
|
873 |
123 asFloat asLongFloat |
|
874 |
" |
|
875 |
||
876 |
"Created: / 7.9.2001 / 13:43:04 / cg" |
|
877 |
"Modified: / 7.9.2001 / 13:43:16 / cg" |
|
878 |
! |
|
879 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
880 |
asShortFloat |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
881 |
"return a shortFloat with same value as receiver" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
882 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
883 |
%{ /* NOCONTEXT */ |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
884 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
885 |
OBJ dummy = @global(ShortFloat); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
886 |
OBJ newFloat; |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
887 |
float fVal = (float)__floatVal(self); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
888 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
889 |
__qMKSFLOAT(newFloat, fVal); |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
890 |
RETURN ( newFloat ); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
891 |
%} |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
892 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
893 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
894 |
asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
895 |
"Answer a fraction that EXACTLY represents self, |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
896 |
a double precision IEEE floating point number. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
897 |
Floats are stored in the same form on all platforms. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
898 |
(Does not handle gradual underflow or NANs.) |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
899 |
By David N. Smith with significant performance |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
900 |
improvements by Luciano Esteban Notarfrancesco. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
901 |
(Version of 11April97)" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
902 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
903 |
|shifty sign expPart exp fraction fractionPart result zeroBitsCount| |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
904 |
|
6344 | 905 |
self isFinite ifFalse:[ |
906 |
^ self class |
|
907 |
raise:#conversionErrorSignal |
|
908 |
receiver:self |
|
909 |
selector:#asTrueFraction |
|
910 |
arguments:#() |
|
911 |
errorString:'Cannot represent non-finite float as a fraction'. |
|
6341 | 912 |
]. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
913 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
914 |
"Extract the bits of an IEEE double float " |
6341 | 915 |
shifty := LargeInteger basicNew numberOfDigits:8. |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
916 |
UninterpretedBytes isBigEndian ifTrue:[ |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
917 |
"/ shifty := ((self basicAt: 1) bitShift: 32) + (self basicAt: 2). |
6341 | 918 |
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
|
919 |
] ifFalse:[ |
6341 | 920 |
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
|
921 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
922 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
923 |
" Extract the sign and the biased exponent " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
924 |
sign := (shifty bitShift: -63) = 0 ifTrue: [1] ifFalse: [-1]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
925 |
expPart := (shifty bitShift: -52) bitAnd: 16r7FF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
926 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
927 |
" Extract 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
|
928 |
fractionPart := shifty bitAnd: 16r000FFFFFFFFFFFFF. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
929 |
( expPart=0 and: [ fractionPart=0 ] ) ifTrue: [ ^ 0 ]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
930 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
931 |
" Replace omitted leading 1 in fraction " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
932 |
fraction := fractionPart bitOr: 16r0010000000000000. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
933 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
934 |
"Unbias exponent: 16r3FF is bias; 52 is fraction width" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
935 |
exp := 16r3FF + 52 - expPart. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
936 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
937 |
" 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
|
938 |
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
|
939 |
the (huge) time otherwise spent in #gcd:. " |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
940 |
exp negative ifTrue: [ |
6341 | 941 |
result := sign * fraction bitShift: exp negated |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
942 |
] ifFalse:[ |
6341 | 943 |
zeroBitsCount := fraction lowBit - 1. |
944 |
exp := exp - zeroBitsCount. |
|
945 |
exp <= 0 ifTrue: [ |
|
946 |
zeroBitsCount := zeroBitsCount + exp. |
|
947 |
"exp := 0." " Not needed; exp not refernced again " |
|
948 |
result := sign * fraction bitShift:zeroBitsCount negated |
|
949 |
] ifFalse: [ |
|
950 |
result := Fraction |
|
951 |
numerator: (sign * fraction bitShift: zeroBitsCount negated) |
|
952 |
denominator: (1 bitShift:exp) |
|
953 |
] |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
954 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
955 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
956 |
"Low cost validation omitted after extensive testing" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
957 |
"(result asFloat = self) ifFalse: [self error: 'asTrueFraction validation failed']." |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
958 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
959 |
^ result |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
960 |
|
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
961 |
" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
962 |
0.3 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
963 |
1.25 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
964 |
0.25 asTrueFraction |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
965 |
-0.25 asTrueFraction |
6341 | 966 |
3e37 asTrueFraction |
967 |
Float NaN asTrueFraction |
|
6344 | 968 |
Float infinity asTrueFraction |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
969 |
" |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
970 |
! |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4594
diff
changeset
|
971 |
|
701 | 972 |
coerce:aNumber |
973 |
"return aNumber converted into receivers type" |
|
1 | 974 |
|
701 | 975 |
^ aNumber asFloat |
976 |
! |
|
13 | 977 |
|
701 | 978 |
generality |
979 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
980 |
||
981 |
^ 80 |
|
1 | 982 |
! ! |
983 |
||
984 |
!Float methodsFor:'comparing'! |
|
985 |
||
986 |
< aNumber |
|
987 |
"return true, if the argument is greater" |
|
988 |
||
989 |
%{ /* NOCONTEXT */ |
|
13 | 990 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
991 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
992 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
993 |
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
|
994 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
995 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
996 |
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
|
997 |
} |
1 | 998 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
999 |
%}. |
1 | 1000 |
^ aNumber lessFromFloat:self |
1001 |
! |
|
1002 |
||
1003 |
<= aNumber |
|
1004 |
"return true, if the argument is greater or equal" |
|
1005 |
||
1006 |
%{ /* NOCONTEXT */ |
|
13 | 1007 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1008 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1009 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1010 |
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
|
1011 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1012 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1013 |
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
|
1014 |
} |
1 | 1015 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1016 |
%}. |
1 | 1017 |
^ self retry:#<= coercing:aNumber |
1018 |
! |
|
1019 |
||
1020 |
= aNumber |
|
175 | 1021 |
"return true, if the arguments value are equal by value" |
1 | 1022 |
|
1023 |
%{ /* NOCONTEXT */ |
|
13 | 1024 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1025 |
if (aNumber != nil) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1026 |
if (__isSmallInteger(aNumber)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1027 |
RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1028 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1029 |
if (__qIsFloatLike(aNumber)) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1030 |
RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1031 |
} |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1032 |
if (__qClass(aNumber)==ShortFloat) { |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1033 |
RETURN ( (__floatVal(self) == (double)(__shortFloatVal(aNumber))) ? true : false ); |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1034 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1035 |
} else { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1036 |
RETURN (false); |
1 | 1037 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1038 |
%}. |
1 | 1039 |
^ self retry:#= coercing:aNumber |
1040 |
! |
|
1041 |
||
701 | 1042 |
> aNumber |
1043 |
"return true, if the argument is less" |
|
1 | 1044 |
|
1045 |
%{ /* NOCONTEXT */ |
|
13 | 1046 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1047 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1048 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1049 |
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
|
1050 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1051 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1052 |
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
|
1053 |
} |
1 | 1054 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1055 |
%}. |
701 | 1056 |
^ self retry:#> coercing:aNumber |
1057 |
! |
|
1058 |
||
1059 |
>= aNumber |
|
1060 |
"return true, if the argument is less or equal" |
|
1061 |
||
1062 |
%{ /* NOCONTEXT */ |
|
1063 |
||
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1064 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1065 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1066 |
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
|
1067 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1068 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1069 |
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
|
1070 |
} |
701 | 1071 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1072 |
%}. |
701 | 1073 |
^ self retry:#>= coercing:aNumber |
92 | 1074 |
! |
1075 |
||
1076 |
hash |
|
1077 |
"return a number for hashing; redefined, since floats compare |
|
1078 |
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
|
1079 |
as 3 hash." |
92 | 1080 |
|
305 | 1081 |
|i| |
92 | 1082 |
|
1083 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1084 |
i := self asInteger. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1085 |
self = i ifTrue:[ |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1086 |
^ i hash |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1087 |
]. |
92 | 1088 |
]. |
1089 |
||
1090 |
" |
|
305 | 1091 |
mhmh take some of my value-bits to hash on |
92 | 1092 |
" |
4590 | 1093 |
^ (((self basicAt:8) bitAnd:16r1F) bitShift:24) + |
305 | 1094 |
((self basicAt:7) bitShift:16) + |
1095 |
((self basicAt:6) bitShift:8) + |
|
4592 | 1096 |
(((self basicAt:5) + (self basicAt:1) + (self basicAt:2)) bitAnd:16rFF) |
92 | 1097 |
|
1098 |
" |
|
1099 |
3 hash |
|
1100 |
3.0 hash |
|
1101 |
3.1 hash |
|
1102 |
3.14159 hash |
|
1103 |
31.4159 hash |
|
1104 |
3.141591 hash |
|
1105 |
1.234567890123456 hash |
|
1106 |
1.234567890123457 hash |
|
1107 |
Set withAll:#(3 3.0 99 99.0 3.1415) |
|
1108 |
" |
|
1 | 1109 |
! |
1110 |
||
701 | 1111 |
~= aNumber |
1112 |
"return true, if the arguments value are not equal" |
|
1 | 1113 |
|
1114 |
%{ /* NOCONTEXT */ |
|
1115 |
||
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1116 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1117 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1118 |
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
|
1119 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1120 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1121 |
RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1122 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1123 |
} else { |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
1124 |
RETURN (true); |
1 | 1125 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1126 |
%}. |
701 | 1127 |
^ self retry:#~= coercing:aNumber |
1 | 1128 |
! ! |
1129 |
||
1130 |
!Float methodsFor:'mathematical functions'! |
|
1131 |
||
701 | 1132 |
arcCos |
6193 | 1133 |
"return the arccosine of myself (I am interpreted as radians). |
1134 |
Raises an exception, if the receiver is not in -1..1" |
|
701 | 1135 |
|
1136 |
%{ /* NOCONTEXT */ |
|
1137 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1138 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1139 |
OBJ newFloat; |
701 | 1140 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1141 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1142 |
|
6193 | 1143 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1144 |
if ((val >= -1.0) && (val <= 1.0)) |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1145 |
#endif |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1146 |
{ |
6193 | 1147 |
__threadErrno = 0; |
1148 |
rslt = acos(val); |
|
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1149 |
#ifdef LINUX /* and maybe others */ |
6193 | 1150 |
if (! isnan(rslt)) |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1151 |
#endif |
6193 | 1152 |
{ |
1153 |
if (__threadErrno == 0) { |
|
1154 |
__qMKFLOAT(newFloat, rslt); |
|
1155 |
RETURN ( newFloat ); |
|
1156 |
} |
|
1157 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1158 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1159 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1160 |
^ self class |
6193 | 1161 |
raise:#domainErrorSignal |
1162 |
receiver:self |
|
1163 |
selector:#arcCos |
|
6195 | 1164 |
arguments:#() |
6193 | 1165 |
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
|
1166 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1167 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1168 |
-10 arcCos |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1169 |
1 arcCos |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1170 |
" |
6193 | 1171 |
|
6195 | 1172 |
"Modified: / 16.11.2001 / 14:14:13 / cg" |
701 | 1173 |
! |
1174 |
||
1175 |
arcSin |
|
6193 | 1176 |
"return the arcsine of myself (I am interpreted as radians). |
1177 |
Raises an exception, if the receiver is not in -1..1" |
|
701 | 1178 |
|
1179 |
%{ /* NOCONTEXT */ |
|
1180 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1181 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1182 |
OBJ newFloat; |
701 | 1183 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1184 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1185 |
|
6193 | 1186 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1187 |
if ((val >= -1.0) && (val <= 1.0)) |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1188 |
#endif |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1189 |
{ |
6193 | 1190 |
__threadErrno = 0; |
1191 |
rslt = asin(val); |
|
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1192 |
#ifdef LINUX /* and maybe others */ |
6193 | 1193 |
if (! isnan(rslt)) |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1194 |
#endif |
6193 | 1195 |
{ |
1196 |
if (__threadErrno == 0) { |
|
1197 |
__qMKFLOAT(newFloat, rslt); |
|
1198 |
RETURN ( newFloat ); |
|
1199 |
} |
|
1200 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1201 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1202 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1203 |
^ self class |
6193 | 1204 |
raise:#domainErrorSignal |
1205 |
receiver:self |
|
1206 |
selector:#arcSin |
|
6195 | 1207 |
arguments:#() |
6193 | 1208 |
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
|
1209 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1210 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1211 |
-10 arcSin |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1212 |
1 arcSin |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1213 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1214 |
|
6195 | 1215 |
"Modified: / 16.11.2001 / 14:14:18 / cg" |
701 | 1216 |
! |
1217 |
||
1218 |
arcTan |
|
1219 |
"return the arctangent of myself as radians" |
|
1220 |
||
1221 |
%{ /* NOCONTEXT */ |
|
1222 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1223 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1224 |
OBJ newFloat; |
701 | 1225 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1226 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1227 |
rslt = atan(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1228 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1229 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1230 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1231 |
if (__threadErrno == 0) { |
6195 | 1232 |
__qMKFLOAT(newFloat, rslt); |
1233 |
RETURN ( newFloat ); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1234 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1235 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1236 |
^ self class |
6195 | 1237 |
raise:#domainErrorSignal |
1238 |
receiver:self |
|
1239 |
selector:#arcTan |
|
1240 |
arguments:#() |
|
1241 |
errorString:'bad receiver in arcTan' |
|
1242 |
||
1243 |
"Modified: / 16.11.2001 / 14:14:22 / cg" |
|
701 | 1244 |
! |
1245 |
||
1246 |
cos |
|
1247 |
"return the cosine of myself interpreted as radians" |
|
1248 |
||
1249 |
%{ /* NOCONTEXT */ |
|
1250 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1251 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1252 |
OBJ newFloat; |
701 | 1253 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1254 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1255 |
rslt = cos(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1256 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1257 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1258 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1259 |
if (__threadErrno == 0) { |
6195 | 1260 |
__qMKFLOAT(newFloat, rslt); |
1261 |
RETURN ( newFloat ); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1262 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1263 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1264 |
^ self class |
6195 | 1265 |
raise:#domainErrorSignal |
1266 |
receiver:self |
|
1267 |
selector:#cos |
|
1268 |
arguments:#() |
|
1269 |
errorString:'bad receiver in cos' |
|
1270 |
||
1271 |
"Modified: / 16.11.2001 / 14:14:26 / cg" |
|
701 | 1272 |
! |
1273 |
||
1274 |
exp |
|
1275 |
"return e raised to the power of the receiver" |
|
1276 |
||
1277 |
%{ /* NOCONTEXT */ |
|
1278 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1279 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1280 |
OBJ newFloat; |
701 | 1281 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1282 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1283 |
rslt = exp(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1284 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1285 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1286 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1287 |
if (__threadErrno == 0) { |
6195 | 1288 |
__qMKFLOAT(newFloat, rslt); |
1289 |
RETURN ( newFloat ); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1290 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1291 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1292 |
^ self class |
6195 | 1293 |
raise:#domainErrorSignal |
1294 |
receiver:self |
|
1295 |
selector:#exp |
|
1296 |
arguments:#() |
|
1297 |
errorString:'bad receiver in exp' |
|
1298 |
||
1299 |
"Modified: / 16.11.2001 / 14:14:29 / cg" |
|
701 | 1300 |
! |
1301 |
||
1 | 1302 |
ln |
6193 | 1303 |
"return the natural logarithm of myself. |
1304 |
Raises an exception, if the receiver is less or equal to zero." |
|
1 | 1305 |
|
1306 |
%{ /* NOCONTEXT */ |
|
1307 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1308 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1309 |
OBJ newFloat; |
1 | 1310 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1311 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1312 |
|
6193 | 1313 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1314 |
if (val > 0.0) |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1315 |
#endif |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1316 |
{ |
6193 | 1317 |
__threadErrno = 0; |
1318 |
rslt = log(val); |
|
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1319 |
#ifdef LINUX /* and maybe others */ |
6193 | 1320 |
if (! isnan(rslt)) |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1321 |
#endif |
6193 | 1322 |
{ |
1323 |
if (__threadErrno == 0) { |
|
1324 |
__qMKFLOAT(newFloat, rslt); |
|
1325 |
RETURN ( newFloat ); |
|
1326 |
} |
|
1327 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1328 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1329 |
%}. |
142 | 1330 |
" |
1331 |
an invalid value for logarithm |
|
1332 |
" |
|
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1333 |
^ self class |
6193 | 1334 |
raise:#domainErrorSignal |
1335 |
receiver:self |
|
1336 |
selector:#ln |
|
6195 | 1337 |
arguments:#() |
6193 | 1338 |
errorString:'bad receiver in ln' |
1339 |
||
6195 | 1340 |
"Modified: / 16.11.2001 / 14:14:33 / cg" |
1 | 1341 |
! |
1342 |
||
1343 |
raisedTo:aNumber |
|
1344 |
"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
|
1345 |
|
1 | 1346 |
|n| |
1347 |
||
1348 |
n := aNumber asFloat. |
|
1349 |
%{ |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1350 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1351 |
OBJ newFloat; |
1 | 1352 |
|
283 | 1353 |
if (__isFloatLike(n)) { |
6195 | 1354 |
__threadErrno = 0; |
1355 |
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
|
1356 |
#ifdef LINUX /* and maybe others */ |
6195 | 1357 |
if (! isnan(rslt)) |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1358 |
#endif |
6195 | 1359 |
if (__threadErrno == 0) { |
1360 |
__qMKFLOAT(newFloat, rslt); |
|
1361 |
RETURN ( newFloat ); |
|
1362 |
} |
|
1 | 1363 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1364 |
%}. |
142 | 1365 |
" |
1366 |
an invalid argument (not convertable to float ?) |
|
1367 |
" |
|
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1368 |
^ self class |
6195 | 1369 |
raise:#domainErrorSignal |
1370 |
receiver:self |
|
1371 |
selector:#raisedTo: |
|
1372 |
arguments:(Array with:aNumber) |
|
1373 |
errorString:'bad receiver/arg in raisedTo:' |
|
1374 |
||
1375 |
"Modified: / 16.11.2001 / 14:16:51 / cg" |
|
1 | 1376 |
! |
1377 |
||
1378 |
sin |
|
1379 |
"return the sine of myself interpreted as radians" |
|
1380 |
||
1381 |
%{ /* NOCONTEXT */ |
|
1382 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1383 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1384 |
OBJ newFloat; |
1 | 1385 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1386 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1387 |
rslt = sin(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1388 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1389 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1390 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1391 |
if (__threadErrno == 0) { |
6195 | 1392 |
__qMKFLOAT(newFloat, rslt); |
1393 |
RETURN ( newFloat ); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1394 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1395 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1396 |
^ self class |
6195 | 1397 |
raise:#domainErrorSignal |
1398 |
receiver:self |
|
1399 |
selector:#sin |
|
1400 |
arguments:#() |
|
1401 |
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
|
1402 |
|
6195 | 1403 |
"Modified: / 16.11.2001 / 14:14:37 / cg" |
1 | 1404 |
! |
1405 |
||
1406 |
sqrt |
|
6193 | 1407 |
"return the square root of myself. |
1408 |
Raises an exception, if the receiver is less than zero." |
|
1 | 1409 |
|
1410 |
%{ /* NOCONTEXT */ |
|
1411 |
||
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1412 |
double val, rslt; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1413 |
OBJ newFloat; |
1 | 1414 |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1415 |
val = __floatVal(self); |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1416 |
|
6193 | 1417 |
#ifdef WIN32 /* dont know (yet) how to suppress the warnBox opened by win32 */ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1418 |
if (val >= 0.0) |
3889
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1419 |
#endif |
3466554b639f
manually check receiver for beeing >= 0 under WINDOWS
Claus Gittinger <cg@exept.de>
parents:
3632
diff
changeset
|
1420 |
{ |
6193 | 1421 |
__threadErrno = 0; |
1422 |
rslt = sqrt(val); |
|
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1423 |
#ifdef LINUX /* and maybe others */ |
6193 | 1424 |
if (! isnan(rslt)) |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1425 |
#endif |
6193 | 1426 |
{ |
1427 |
if (__threadErrno == 0) { |
|
1428 |
__qMKFLOAT(newFloat, rslt); |
|
1429 |
RETURN ( newFloat ); |
|
1430 |
} |
|
1431 |
} |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1432 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1433 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1434 |
^ self class |
6193 | 1435 |
raise:#domainErrorSignal |
1436 |
receiver:self |
|
1437 |
selector:#sqrt |
|
6195 | 1438 |
arguments:#() |
6193 | 1439 |
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
|
1440 |
|
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1441 |
" |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1442 |
10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1443 |
-10 sqrt |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1444 |
" |
6193 | 1445 |
|
6195 | 1446 |
"Modified: / 16.11.2001 / 14:14:43 / cg" |
701 | 1447 |
! |
258 | 1448 |
|
701 | 1449 |
tan |
1450 |
"return the tangent of myself interpreted as radians" |
|
258 | 1451 |
|
1452 |
%{ /* NOCONTEXT */ |
|
1453 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1454 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1455 |
OBJ newFloat; |
44 | 1456 |
|
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1457 |
__threadErrno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1458 |
rslt = tan(__floatVal(self)); |
3399
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1459 |
#ifdef LINUX /* and maybe others */ |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1460 |
if (! isnan(rslt)) |
4f45ebb7bc60
oops - linux does not set errNo on some domainErrors;
Claus Gittinger <cg@exept.de>
parents:
3395
diff
changeset
|
1461 |
#endif |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1462 |
if (__threadErrno == 0) { |
6195 | 1463 |
__qMKFLOAT(newFloat, rslt); |
1464 |
RETURN ( newFloat ); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1465 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1466 |
%}. |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3279
diff
changeset
|
1467 |
^ self class |
6195 | 1468 |
raise:#domainErrorSignal |
1469 |
receiver:self |
|
1470 |
selector:#tan |
|
1471 |
arguments:#() |
|
1472 |
errorString:'bad receiver in tan' |
|
1473 |
||
1474 |
"Modified: / 16.11.2001 / 14:14:49 / cg" |
|
13 | 1475 |
! ! |
1476 |
||
92 | 1477 |
!Float methodsFor:'printing & storing'! |
1 | 1478 |
|
1479 |
printString |
|
2358 | 1480 |
"return a printed representation of the receiver; |
1481 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1482 |
6 valid digits are printed. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1483 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3163
diff
changeset
|
1484 |
#printOn: as basic print mechanism." |
1 | 1485 |
|
1486 |
%{ /* NOCONTEXT */ |
|
1487 |
||
13 | 1488 |
char buffer[64]; |
1 | 1489 |
REGISTER char *cp; |
314 | 1490 |
OBJ s; |
2358 | 1491 |
char *fmt; |
1492 |
char fmtBuffer[20]; |
|
1493 |
||
1494 |
if (__isString(@global(DefaultPrintFormat))) { |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1495 |
fmt = (char *) __stringVal(@global(DefaultPrintFormat)); |
2358 | 1496 |
} else { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1497 |
/* |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1498 |
* in case we get called before #initialize ... |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1499 |
*/ |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1500 |
fmt = ".6"; |
2358 | 1501 |
} |
1502 |
||
1503 |
/* |
|
1504 |
* build a printf format string |
|
1505 |
*/ |
|
1506 |
fmtBuffer[0] = '%'; |
|
1507 |
strncpy(fmtBuffer+1, fmt, 10); |
|
1508 |
#ifdef SYSV |
|
1509 |
strcat(fmtBuffer, "lg"); |
|
1510 |
#else |
|
1511 |
strcat(fmtBuffer, "G"); |
|
1512 |
#endif |
|
314 | 1513 |
|
2358 | 1514 |
sprintf(buffer, fmtBuffer, __floatVal(self)); |
1 | 1515 |
|
1516 |
/* |
|
13 | 1517 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
1 | 1518 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
1519 |
*/ |
|
1520 |
for (cp = buffer; *cp; cp++) { |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1521 |
if ((*cp == '.') || (*cp == 'E') || (*cp == 'e')) break; |
1 | 1522 |
} |
1523 |
if (! *cp) { |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1524 |
*cp++ = '.'; |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1525 |
*cp++ = '0'; |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1526 |
*cp = '\0'; |
1 | 1527 |
} |
1528 |
||
1133 | 1529 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 1530 |
if (s != nil) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1531 |
RETURN (s); |
314 | 1532 |
} |
1533 |
%}. |
|
1534 |
" |
|
1535 |
memory allocation (for the new string) failed. |
|
1536 |
When we arrive here, there was no memory, even after a garbage collect. |
|
1537 |
This means, that the VM wanted to get some more memory from the |
|
1538 |
OS, which was not kind enough to give it. |
|
1539 |
Bad luck - you should increase the swap space on your machine. |
|
1540 |
" |
|
1541 |
^ ObjectMemory allocationFailureSignal raise. |
|
1542 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1543 |
" |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1544 |
1.0 printString |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1545 |
1.234 printString |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1546 |
1e10 printString |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1547 |
1.2e3 printString |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1548 |
1.2e30 printString |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1549 |
(1.0 uncheckedDivide:0) printString |
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
1550 |
(0.0 uncheckedDivide:0) printString |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1551 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1552 |
|
1 | 1553 |
! |
1554 |
||
1555 |
printfPrintString:formatString |
|
1556 |
"non-portable: return a printed representation of the receiver |
|
1557 |
as specified by formatString, which is defined by printf. |
|
31 | 1558 |
If you use this, be aware, that specifying doubles differs on |
1 | 1559 |
systems; on SYSV machines you have to give something like %lf, |
13 | 1560 |
while on BSD systems the format string has to be %F. |
31 | 1561 |
Also, the resulting string may not be longer than 255 bytes - |
54 | 1562 |
since thats the (static) size of the buffer. |
1563 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 1564 |
|
13 | 1565 |
%{ /* STACK: 400 */ |
1 | 1566 |
char buffer[256]; |
314 | 1567 |
OBJ s; |
1 | 1568 |
|
54 | 1569 |
if (__isString(formatString)) { |
1133 | 1570 |
sprintf(buffer, __stringVal(formatString), __floatVal(self)); |
369 | 1571 |
|
1133 | 1572 |
s = __MKSTRING(buffer COMMA_SND); |
343 | 1573 |
if (s != nil) { |
1574 |
RETURN (s); |
|
1575 |
} |
|
1 | 1576 |
} |
314 | 1577 |
%}. |
1 | 1578 |
self primitiveFailed |
1579 |
||
1580 |
"Float pi printfPrintString:'%%lg -> %lg'" |
|
1581 |
"Float pi printfPrintString:'%%lf -> %lf'" |
|
1582 |
"Float pi printfPrintString:'%%7.5lg -> %7.5lg'" |
|
1583 |
"Float pi printfPrintString:'%%7.5lf -> %7.5lf'" |
|
1584 |
"Float pi printfPrintString:'%%G -> %G'" |
|
1585 |
"Float pi printfPrintString:'%%F -> %F'" |
|
1586 |
"Float pi printfPrintString:'%%7.5G -> %7.5G'" |
|
1587 |
"Float pi printfPrintString:'%%7.5F -> %7.5F'" |
|
1588 |
! ! |
|
701 | 1589 |
|
1590 |
!Float methodsFor:'private accessing'! |
|
1591 |
||
1592 |
basicAt:index |
|
1593 |
"return an internal byte of the float. |
|
1594 |
The value returned here depends on byte order, float representation etc. |
|
1595 |
Therefore, this method should be used strictly private. |
|
1596 |
||
1597 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1598 |
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
|
1599 |
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
|
1600 |
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
|
1601 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1602 |
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
|
1603 |
values as if this filler wasnt present." |
701 | 1604 |
|
1605 |
%{ /* NOCONTEXT */ |
|
1606 |
||
1607 |
register int indx; |
|
1608 |
unsigned char *cp; |
|
1609 |
||
1610 |
/* |
|
1611 |
* notice the missing test for self being a nonNilObject - |
|
1612 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1613 |
* and SmallInteger |
|
1614 |
*/ |
|
1615 |
if (__isSmallInteger(index)) { |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1616 |
indx = __intVal(index) - 1; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1617 |
if (((unsigned)(indx)) < sizeof(double)) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1618 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1619 |
RETURN ( __MKSMALLINT(cp[indx] & 0xFF) ); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1620 |
} |
701 | 1621 |
} |
1622 |
%}. |
|
1623 |
index isInteger ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1624 |
^ self indexNotInteger |
701 | 1625 |
]. |
1626 |
^ self subscriptBoundsError:index |
|
1627 |
! |
|
1628 |
||
1629 |
basicAt:index put:value |
|
1630 |
"set an internal byte of the float. |
|
1631 |
The value to be stored here depends on byte order, float representation etc. |
|
1632 |
Therefore, this method should be used strictly private. |
|
1633 |
||
1634 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1635 |
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
|
1636 |
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
|
1637 |
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
|
1638 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1639 |
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
|
1640 |
values as if this filler wasnt present." |
701 | 1641 |
|
1642 |
%{ /* NOCONTEXT */ |
|
1643 |
register int indx, val; |
|
1644 |
unsigned char *cp; |
|
1645 |
||
1646 |
/* |
|
1647 |
* notice the missing test for self being a nonNilObject - |
|
1648 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1649 |
* and SmallInteger |
|
1650 |
*/ |
|
1651 |
if (__bothSmallInteger(index, value)) { |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1652 |
val = __intVal(value); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1653 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1654 |
indx = __intVal(index) - 1; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1655 |
if (((unsigned)(indx)) < sizeof(double)) { |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1656 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1657 |
cp[indx] = val; |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1658 |
RETURN ( value ); |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1659 |
} |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1660 |
} |
701 | 1661 |
} |
1662 |
%}. |
|
1663 |
index isInteger ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1664 |
^ self indexNotInteger |
701 | 1665 |
]. |
1666 |
value isInteger ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1667 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1668 |
the object to store should be an integer number |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1669 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1670 |
^ self elementNotInteger |
701 | 1671 |
]. |
1672 |
(value between:0 and:255) ifFalse:[ |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1673 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1674 |
the object to store must be a bytes value |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1675 |
" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1676 |
^ self elementBoundsError |
701 | 1677 |
]. |
1678 |
^ self subscriptBoundsError:index |
|
5557 | 1679 |
! ! |
1680 |
||
1681 |
!Float methodsFor:'queries'! |
|
4592 | 1682 |
|
1683 |
basicSize |
|
1684 |
"return the size in bytes of the float. |
|
1685 |
||
1686 |
Notice: |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1687 |
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
|
1688 |
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
|
1689 |
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
|
1690 |
and the actual float is stored at index 5 .. 12. |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1691 |
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
|
1692 |
values as if this filler wasnt present." |
4592 | 1693 |
|
1694 |
%{ /* NOCONTEXT */ |
|
1695 |
||
1696 |
RETURN (__MKSMALLINT(sizeof(double))); |
|
1697 |
%}. |
|
5884
92d1470a57dc
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
1698 |
! |
92d1470a57dc
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
1699 |
|
92d1470a57dc
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
1700 |
defaultNumberOfDigits |
92d1470a57dc
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
1701 |
"Answer how many digits of accuracy this class supports" |
92d1470a57dc
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
1702 |
|
92d1470a57dc
added #defaultNumberOfDigits
Claus Gittinger <cg@exept.de>
parents:
5822
diff
changeset
|
1703 |
^ 14 |
701 | 1704 |
! ! |
1705 |
||
3896 | 1706 |
!Float methodsFor:'special access'! |
1707 |
||
1708 |
exponent |
|
1709 |
"extract a normalized floats exponent. |
|
1710 |
The returned value depends on the float-representation of |
|
1711 |
the underlying machine and is therefore highly unportable. |
|
1712 |
This is not for general use. |
|
1713 |
This assumes that the mantissa is normalized to |
|
1714 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1715 |
||
1716 |
%{ /* NOCONTEXT */ |
|
1717 |
||
1718 |
double frexp(); |
|
1719 |
double frac; |
|
1720 |
INT exp; |
|
1721 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1722 |
__threadErrno = 0; |
3896 | 1723 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1724 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1725 |
RETURN (__MKSMALLINT(exp)); |
3896 | 1726 |
} |
1727 |
%}. |
|
1728 |
^ self primitiveFailed |
|
1729 |
||
1730 |
" |
|
1731 |
1.0 exponent |
|
1732 |
2.0 exponent |
|
1733 |
3.0 exponent |
|
1734 |
4.0 exponent |
|
1735 |
0.5 exponent |
|
1736 |
0.4 exponent |
|
1737 |
0.25 exponent |
|
1738 |
0.00000011111 exponent |
|
1739 |
" |
|
1740 |
! |
|
1741 |
||
1742 |
mantissa |
|
1743 |
"extract a normalized floats mantissa. |
|
1744 |
The returned value depends on the float-representation of |
|
1745 |
the underlying machine and is therefore highly unportable. |
|
1746 |
This is not for general use. |
|
1747 |
This assumes that the mantissa is normalized to |
|
1748 |
0.5 .. 1.0 and the floats value is mantissa * 2^exp" |
|
1749 |
||
1750 |
%{ /* NOCONTEXT */ |
|
1751 |
||
1752 |
double frexp(); |
|
1753 |
double frac; |
|
1754 |
INT exp; |
|
1755 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1756 |
__threadErrno = 0; |
3896 | 1757 |
frac = frexp(__floatVal(self), &exp); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
1758 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1759 |
RETURN (__MKFLOAT(frac)); |
3896 | 1760 |
} |
1761 |
%}. |
|
1762 |
^ self primitiveFailed |
|
1763 |
||
1764 |
" |
|
1765 |
1.0 exponent |
|
1766 |
1.0 mantissa |
|
1767 |
||
1768 |
0.25 exponent |
|
1769 |
0.25 mantissa |
|
1770 |
||
1771 |
0.00000011111 exponent |
|
1772 |
0.00000011111 mantissa |
|
1773 |
" |
|
1774 |
! ! |
|
1775 |
||
701 | 1776 |
!Float methodsFor:'testing'! |
1777 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1778 |
isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1779 |
"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
|
1780 |
i.e. not NaN and not infinite." |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1781 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1782 |
%{ /* NOCONTEXT */ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1783 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1784 |
double dV = __floatVal(self); |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1785 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1786 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1787 |
* 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
|
1788 |
* a finite() macro or function (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1789 |
* 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
|
1790 |
*/ |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1791 |
if (finite(dV)) { |
6344 | 1792 |
RETURN (true); |
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1793 |
} |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1794 |
%}. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1795 |
^false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1796 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1797 |
" |
6344 | 1798 |
1.0 isFinite |
1799 |
Float NaN isFinite |
|
1800 |
Float infinity isFinite |
|
1801 |
(0.0 uncheckedDivide: 0.0) isFinite |
|
1802 |
(1.0 uncheckedDivide: 0.0) isFinite |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1803 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1804 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1805 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1806 |
isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1807 |
"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
|
1808 |
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
|
1809 |
however, inline C-code could produce them ... |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1810 |
Redefined here for speed" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1811 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1812 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1813 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1814 |
double dV = __floatVal(self); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1815 |
|
3198
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1816 |
/* |
4f930c1c96e7
care for systems which do not define finite() / isnan() - sigh
Claus Gittinger <cg@exept.de>
parents:
3194
diff
changeset
|
1817 |
* 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
|
1818 |
* finite() & isnan() macros or functions (WIN32), |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1819 |
* 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
|
1820 |
*/ |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1821 |
#if defined(isinf) || defined(LINUX) |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1822 |
if (isinf(dV)) { RETURN (true); } |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1823 |
#else |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1824 |
if (!finite(dV) && !isnan(dV)) { RETURN (true); } |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1825 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1826 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1827 |
^ false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1828 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1829 |
" |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1830 |
1.0 isInfinite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1831 |
(0.0 uncheckedDivide: 0.0) isInfinite |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1832 |
(1.0 uncheckedDivide: 0.0) isInfinite |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1833 |
" |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1834 |
! |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1835 |
|
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1836 |
isLiteral |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1837 |
"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
|
1838 |
(i.e. can be used in constant arrays)" |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1839 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1840 |
^ true |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1841 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1842 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1843 |
! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1844 |
|
2387 | 1845 |
isNaN |
1846 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
1847 |
These are not created by ST/X float operations (they raise an exception); |
|
1848 |
however, inline C-code could produce them ..." |
|
1849 |
||
1850 |
%{ /* NOCONTEXT */ |
|
1851 |
||
3139 | 1852 |
double dV = (__floatVal(self)); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1853 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1854 |
if (isnan(dV)) { RETURN (true); } |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1855 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1856 |
#if 0 /* Currently all our systems support isnan() |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1857 |
* 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
|
1858 |
*/ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1859 |
|
2395 | 1860 |
/* |
1861 |
* sigh - every vendor is playing its own game here ... |
|
1862 |
* Q: what are standards worth, anyway ? |
|
1863 |
*/ |
|
2392 | 1864 |
#ifdef IS_NAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1865 |
if (IS_NAN(dV)) { RETURN (true); } |
3139 | 1866 |
RETURN (false); |
2393 | 1867 |
#endif |
3139 | 1868 |
|
2393 | 1869 |
#ifdef IS_QNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1870 |
if (IS_QNAN(dV)) { RETURN (true); } |
3139 | 1871 |
RETURN (false); |
2393 | 1872 |
#endif |
2392 | 1873 |
|
2393 | 1874 |
#ifdef FLT_SNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1875 |
if (dV == FLT_SNAN) { RETURN (true); } |
3139 | 1876 |
RETURN (false); |
2393 | 1877 |
#endif |
3139 | 1878 |
|
2393 | 1879 |
#ifdef FLT_QNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1880 |
if (dV == FLT_QNAN) { RETURN (true); } |
3139 | 1881 |
RETURN (false); |
2393 | 1882 |
#endif |
1883 |
||
1884 |
#ifdef _SNANF |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1885 |
if (dV == _SNAN) { RETURN (true); } |
3139 | 1886 |
RETURN (false); |
2393 | 1887 |
#endif |
3139 | 1888 |
|
2393 | 1889 |
#ifdef _QNANF |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1890 |
if (dV == _QNAN) { RETURN (true); } |
3139 | 1891 |
RETURN (false); |
2393 | 1892 |
#endif |
2392 | 1893 |
|
2395 | 1894 |
#ifdef IsPosNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1895 |
if IsPosNAN(dV) { RETURN (true); } |
3139 | 1896 |
RETURN (false); |
2395 | 1897 |
#endif |
3139 | 1898 |
|
2395 | 1899 |
#ifdef IsNegNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1900 |
if IsNegNAN(dV) { RETURN (true); } |
3139 | 1901 |
RETURN (false); |
2395 | 1902 |
#endif |
1903 |
||
2393 | 1904 |
#ifdef NAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1905 |
if (dV == NAN) { RETURN (true); } |
3139 | 1906 |
RETURN (false); |
2390 | 1907 |
#endif |
3139 | 1908 |
|
2399 | 1909 |
#ifdef NaN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1910 |
if (NaN(dV)) { RETURN (true); } |
3139 | 1911 |
RETURN (false); |
2399 | 1912 |
#endif |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1913 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1914 |
#endif /* 0 */ |
2392 | 1915 |
%}. |
1916 |
^ false |
|
3139 | 1917 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1918 |
" |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1919 |
1.0 isNaN |
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
1920 |
(0.0 uncheckedDivide: 0.0) isNaN |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1921 |
" |
2387 | 1922 |
! |
1923 |
||
701 | 1924 |
negative |
1925 |
"return true if the receiver is less than zero" |
|
1926 |
||
1927 |
%{ /* NOCONTEXT */ |
|
1928 |
||
1133 | 1929 |
RETURN ( (__floatVal(self) < 0.0) ? true : false ); |
5411 | 1930 |
%}. |
1931 |
^ self < 0.0 |
|
701 | 1932 |
! |
1933 |
||
5357 | 1934 |
numberOfBits |
1935 |
"return the size (in bits) of the real; |
|
1936 |
typically, 64 is returned here, |
|
1937 |
but who knows ..." |
|
1938 |
||
1939 |
%{ /* NOCONTEXT */ |
|
1940 |
||
1941 |
RETURN (__MKSMALLINT (sizeof(double) * 8)); |
|
1942 |
%} |
|
1943 |
||
1944 |
" |
|
1945 |
1.2 numberOfBits |
|
1946 |
1.2 asShortFloat numberOfBits |
|
1947 |
" |
|
1948 |
! |
|
1949 |
||
701 | 1950 |
positive |
1951 |
"return true if the receiver is greater or equal to zero" |
|
1952 |
||
1953 |
%{ /* NOCONTEXT */ |
|
1954 |
||
1133 | 1955 |
RETURN ( (__floatVal(self) >= 0.0) ? true : false ); |
701 | 1956 |
%} |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1957 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1958 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1959 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1960 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1961 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1962 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1963 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1964 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1965 |
%} |
701 | 1966 |
! ! |
1967 |
||
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1968 |
!Float methodsFor:'tracing'! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1969 |
|
4682 | 1970 |
traceInto:aRequestor level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1971 |
"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
|
1972 |
|
4682 | 1973 |
^ aRequestor traceFloat:self level:level from:referrer |
4655
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1974 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1975 |
|
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1976 |
! ! |
b9405ca0bb4e
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4615
diff
changeset
|
1977 |
|
5552 | 1978 |
!Float methodsFor:'truncation & rounding'! |
701 | 1979 |
|
1980 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1981 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 1982 |
|
1983 |
|val| |
|
1984 |
||
1985 |
%{ |
|
1986 |
double dVal; |
|
1987 |
||
1988 |
/* |
|
1989 |
* ST-80 (and X3J20) returns integer. |
|
1990 |
*/ |
|
1133 | 1991 |
dVal = ceil(__floatVal(self)); |
701 | 1992 |
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
|
1993 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1994 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
1995 |
__qMKFLOAT(val, dVal); |
701 | 1996 |
%}. |
1997 |
^ val asInteger |
|
1998 |
! |
|
1999 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2000 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2001 |
"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
|
2002 |
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
|
2003 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2004 |
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
|
2005 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2006 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2007 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2008 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2009 |
OBJ val; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2010 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2011 |
/* |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2012 |
* ST-80 (and X3J20) returns integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2013 |
*/ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2014 |
dVal = ceil(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2015 |
__qMKFLOAT(val, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2016 |
RETURN (val); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2017 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2018 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2019 |
|
701 | 2020 |
floor |
2021 |
"return the integer nearest the receiver towards negative infinity." |
|
2022 |
||
2023 |
|val| |
|
2024 |
||
2025 |
%{ |
|
2026 |
double dVal; |
|
2027 |
||
2028 |
/* |
|
2029 |
* ST-80 (and X3J20) returns integer. |
|
2030 |
*/ |
|
1133 | 2031 |
dVal = floor(__floatVal(self)); |
701 | 2032 |
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
|
2033 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2034 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2035 |
__qMKFLOAT(val, dVal); |
701 | 2036 |
%}. |
2037 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2038 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2039 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2040 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2041 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2042 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2043 |
-0.5 floorAsFloat |
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 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2046 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2047 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2048 |
floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2049 |
"return the integer nearest the receiver towards negative infinity |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2050 |
as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2051 |
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
|
2052 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2053 |
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
|
2054 |
float-operation." |
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 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2057 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2058 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2059 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2060 |
dVal = floor(__floatVal(self)); |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2061 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2062 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2063 |
%} |
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 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2067 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2068 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2069 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2070 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2071 |
|
701 | 2072 |
! |
2073 |
||
3896 | 2074 |
fractionPart |
2075 |
"extract the after-decimal fraction part. |
|
2076 |
the floats value is |
|
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
2077 |
float truncated + float fractionalPart" |
3896 | 2078 |
|
2079 |
%{ /* NOCONTEXT */ |
|
2080 |
||
2081 |
double modf(); |
|
2082 |
double frac, trunc; |
|
2083 |
||
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
2084 |
__threadErrno = 0; |
3896 | 2085 |
frac = modf(__floatVal(self), &trunc); |
5120
13143fbcbdf8
introduced __threadErrno (for native threads)
Claus Gittinger <cg@exept.de>
parents:
4825
diff
changeset
|
2086 |
if (__threadErrno == 0) { |
4305
e71100d13b67
void possible return warning
Claus Gittinger <cg@exept.de>
parents:
4296
diff
changeset
|
2087 |
RETURN (__MKFLOAT(frac)); |
3896 | 2088 |
} |
2089 |
%}. |
|
2090 |
^ self primitiveFailed |
|
2091 |
||
2092 |
" |
|
2093 |
1.0 fractionPart |
|
2094 |
2.0 fractionPart |
|
2095 |
3.0 fractionPart |
|
2096 |
4.0 fractionPart |
|
2097 |
0.5 fractionPart |
|
2098 |
0.25 fractionPart |
|
2099 |
3.14159 fractionPart |
|
2100 |
12345673.14159 fractionPart |
|
2101 |
123456731231231231.14159 fractionPart |
|
2102 |
||
2103 |
3.14159 fractionPart + 3.14159 truncated |
|
2104 |
||
2105 |
12345673.14159 fractionPart + 12345673.14159 truncated |
|
2106 |
||
2107 |
123456731231231231.14159 fractionPart + 123456731231231231.14159 truncated |
|
2108 |
" |
|
2109 |
! |
|
2110 |
||
701 | 2111 |
rounded |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2112 |
"return the receiver rounded to the nearest integer" |
701 | 2113 |
|
2114 |
|val| |
|
2115 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2116 |
%{ |
701 | 2117 |
double dVal; |
2118 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2119 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2120 |
if (dVal < 0.0) { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2121 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2122 |
} else { |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2123 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2124 |
} |
701 | 2125 |
/* |
2126 |
* ST-80 (and X3J20) returns integer. |
|
2127 |
*/ |
|
2128 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2129 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2130 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2131 |
__qMKFLOAT(val, dVal); |
701 | 2132 |
%}. |
5436 | 2133 |
val notNil ifTrue:[ |
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2134 |
^ val asInteger |
5436 | 2135 |
]. |
2136 |
self < 0.0 ifTrue:[ |
|
6189
f4bfc2dacdb7
win32: care for some math errors
Claus Gittinger <cg@exept.de>
parents:
6145
diff
changeset
|
2137 |
^ (self - 0.5) ceiling asInteger |
5436 | 2138 |
]. |
2139 |
^ (self + 0.5) floor asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2140 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2141 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2142 |
0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2143 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2144 |
0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2145 |
-0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2146 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2147 |
-0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2148 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2149 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2150 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2151 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2152 |
"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
|
2153 |
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
|
2154 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2155 |
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
|
2156 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2157 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2158 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2159 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2160 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2161 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2162 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2163 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2164 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2165 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2166 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2167 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2168 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2169 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2170 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2171 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2172 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2173 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2174 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2175 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2176 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2177 |
0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2178 |
-0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2179 |
" |
701 | 2180 |
! |
2181 |
||
2182 |
truncated |
|
2183 |
"return the receiver truncated towards zero as an integer" |
|
2184 |
||
2185 |
|val| |
|
2186 |
||
2187 |
%{ |
|
2188 |
double dVal; |
|
2189 |
||
1133 | 2190 |
dVal = __floatVal(self); |
701 | 2191 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2192 |
dVal = ceil(dVal); |
701 | 2193 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2194 |
dVal = floor(dVal); |
701 | 2195 |
} |
2196 |
||
2197 |
/* |
|
2198 |
* ST-80 (and X3J20) returns integer. |
|
2199 |
*/ |
|
2200 |
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
|
2201 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 2202 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2203 |
__qMKFLOAT(val, dVal); |
701 | 2204 |
%}. |
2205 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2206 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2207 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2208 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2209 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2210 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2211 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2212 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2213 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2214 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2215 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2216 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2217 |
"return the receiver truncated towards zero as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2218 |
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
|
2219 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2220 |
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
|
2221 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2222 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2223 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2224 |
double dVal; |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2225 |
OBJ v; |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2226 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2227 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2228 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2229 |
dVal = ceil(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2230 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
2231 |
dVal = floor(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2232 |
} |
3163
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2233 |
__qMKFLOAT(v, dVal); |
212a539ee379
added #readFrom: to avoid returning an int.
Claus Gittinger <cg@exept.de>
parents:
3146
diff
changeset
|
2234 |
RETURN (v); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2235 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2236 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2237 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2238 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2239 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2240 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2241 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2242 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2243 |
|
701 | 2244 |
! ! |
2245 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
2246 |
!Float class methodsFor:'documentation'! |
701 | 2247 |
|
2248 |
version |
|
6574 | 2249 |
^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.126 2002-06-11 21:42:34 stefan Exp $' |
701 | 2250 |
! ! |
2387 | 2251 |
Float initialize! |