author | Stefan Vogel <sv@exept.de> |
Wed, 07 Jan 1998 13:02:20 +0100 | |
changeset 3146 | 4e46505d1d59 |
parent 3139 | a4c5540f924a |
child 3163 | 212a539ee379 |
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 |
||
54 | 13 |
LimitedPrecisionReal variableByteSubclass:#Float |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
14 |
instanceVariableNames:'' |
2358 | 15 |
classVariableNames:'DefaultPrintFormat' |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
16 |
poolDictionaries:'' |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
17 |
category:'Magnitude-Numbers' |
1 | 18 |
! |
19 |
||
701 | 20 |
!Float primitiveDefinitions! |
21 |
%{ |
|
22 |
#include <errno.h> |
|
23 |
||
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
24 |
#ifndef __OPTIMIZE__ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
25 |
# define __OPTIMIZE__ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
26 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
27 |
#include <math.h> |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
28 |
|
701 | 29 |
/* |
30 |
* on some systems errno is a macro ... check for it here |
|
31 |
*/ |
|
32 |
#ifndef errno |
|
33 |
extern errno; |
|
34 |
#endif |
|
35 |
||
2394 | 36 |
#if defined (_AIX) |
37 |
# include <float.h> |
|
38 |
#endif |
|
2395 | 39 |
#if defined(IRIX) |
40 |
# include <nan.h> |
|
41 |
#endif |
|
2397 | 42 |
#if defined(LINUX) |
2396 | 43 |
# include <nan.h> |
44 |
#endif |
|
2399 | 45 |
#if defined(solaris) || defined(sunos) |
2398 | 46 |
# include <nan.h> |
47 |
#endif |
|
2394 | 48 |
|
3129 | 49 |
/* |
50 |
* sigh - some systems define that stuff; others dont. |
|
51 |
* (AIX even declares them as macros, so an external decl |
|
52 |
* will not work below ... |
|
53 |
*/ |
|
54 |
#if !defined(_AIX) |
|
55 |
||
56 |
# ifdef acos |
|
57 |
double acos(); |
|
58 |
# endif |
|
59 |
# ifdef asin |
|
60 |
double asin(); |
|
61 |
# endif |
|
62 |
# ifndef atan |
|
63 |
double atan(); |
|
64 |
# endif |
|
65 |
# ifndef cos |
|
66 |
double cos(); |
|
67 |
# endif |
|
68 |
# ifndef sin |
|
69 |
double sin(); |
|
70 |
# endif |
|
71 |
# ifndef pow |
|
72 |
double pow(); |
|
73 |
# endif |
|
74 |
# ifndef log |
|
75 |
double log(); |
|
76 |
# endif |
|
77 |
# ifndef exp |
|
78 |
double exp(); |
|
79 |
# endif |
|
80 |
# ifndef sqrt |
|
81 |
double sqrt(); |
|
82 |
# endif |
|
83 |
# ifndef tan |
|
84 |
double tan(); |
|
85 |
# endif |
|
86 |
||
87 |
#endif /* not AIX */ |
|
88 |
||
701 | 89 |
%} |
90 |
! ! |
|
91 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
92 |
!Float class methodsFor:'documentation'! |
68 | 93 |
|
88 | 94 |
copyright |
95 |
" |
|
96 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
175 | 97 |
All Rights Reserved |
88 | 98 |
|
99 |
This software is furnished under a license and may be used |
|
100 |
only in accordance with the terms of that license and with the |
|
101 |
inclusion of the above copyright notice. This software may not |
|
102 |
be provided or otherwise made available to, or used by, any |
|
103 |
other person. No title to or ownership of the software is |
|
104 |
hereby transferred. |
|
105 |
" |
|
106 |
! |
|
107 |
||
68 | 108 |
documentation |
109 |
" |
|
110 |
Floats represent rational numbers with limited precision. In ST/X, Float uses |
|
111 |
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
|
112 |
are usually represented by the 8-byte IEEE double precision float format. |
68 | 113 |
(but there is no guaranty). |
1 | 114 |
|
68 | 115 |
Notice, that Floats are defined as Byte-array to prevent the garbage collector |
116 |
from going into the value ... otherwise I needed a special case in many places. |
|
117 |
||
118 |
Also notice, that ST/X Floats are what Doubles are in ST-80 - this may change |
|
119 |
in one of the next versions (at least on machines, which provide different float |
|
120 |
and double types in their C-compiler. |
|
121 |
||
122 |
WARNING: |
|
123 |
The layout of float instances is known by the runtime system and the compiler; |
|
124 |
you may not add instance variables here. |
|
369 | 125 |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
126 |
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
|
127 |
of arithmetic operations (even if the operands are subclass-instances). |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
128 |
(It does the float-check by probing a bit in the classes flag instVar). |
85 | 129 |
|
1892 | 130 |
Mixed mode arithmetic: |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
131 |
float op float -> float |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
132 |
float op fix -> float |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
133 |
float op integer -> float |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
134 |
float op float -> float |
1892 | 135 |
|
1295 | 136 |
[Class Variables:] |
85 | 137 |
|
1295 | 138 |
[see also:] |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
139 |
Number |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
140 |
ShortFloat Fraction FixedPoint Integer |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
141 |
FloatArray DoubleArray |
1295 | 142 |
|
143 |
[author:] |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
144 |
Claus Gittinger |
68 | 145 |
" |
2215 | 146 |
! |
147 |
||
148 |
errorHandling |
|
149 |
" |
|
150 |
Floating point error handling and signalling depends on the systems |
|
151 |
(actually: the C-runtime systems) ability to handle floating point errors. |
|
152 |
Most systems report errors by raising an OS floatingPoint exception, |
|
153 |
which is mapped to a fpExceptionInterrupt in ST/X. |
|
154 |
However, some systems do return NaN as result. |
|
155 |
||
156 |
Currently, ST/X does not care specially for these systems - it maybe added |
|
157 |
easily, if there is sufficient customer interest, though. |
|
158 |
||
159 |
Try: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
160 |
|f1 f2| |
2215 | 161 |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
162 |
f1 := 1.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
163 |
f2 := 0.0. |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
164 |
f1 / f2 |
2215 | 165 |
|
166 |
or: |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
167 |
2 arcSin |
2215 | 168 |
" |
68 | 169 |
! ! |
1 | 170 |
|
2387 | 171 |
!Float class methodsFor:'initialization'! |
172 |
||
173 |
initialize |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
174 |
DefaultPrintFormat := '.6' "/ 6 valid digits |
2387 | 175 |
|
176 |
" |
|
177 |
DefaultPrintFormat := '.9' |
|
178 |
DefaultPrintFormat := '.6' |
|
179 |
" |
|
180 |
! ! |
|
181 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
182 |
!Float class methodsFor:'instance creation'! |
1 | 183 |
|
184 |
basicNew |
|
185 |
"return a new float - here we return 0.0 |
|
186 |
- floats are usually NOT created this way ... |
|
187 |
Its implemented here to allow things like binary store & load |
|
188 |
of floats. (but even this support will go away eventually, its not |
|
189 |
a good idea to store the bits of a float - the reader might have a |
|
13 | 190 |
totally different representation - so floats will eventually be |
191 |
binary stored in a device independent format." |
|
1 | 192 |
|
193 |
%{ /* NOCONTEXT */ |
|
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
194 |
OBJ newFloat; |
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
195 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
196 |
__qMKFLOAT(newFloat, 0.0); |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
197 |
RETURN (newFloat); |
1 | 198 |
%} |
1206
9d23c1f5e4d3
use quicker MKFLOAT in FLoat>>basicNew
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
199 |
|
1 | 200 |
! ! |
201 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
202 |
!Float class methodsFor:'binary storage'! |
701 | 203 |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
204 |
binaryDefinitionFrom:aStream manager: manager |
701 | 205 |
|f| |
206 |
||
207 |
f := self basicNew. |
|
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
208 |
self readBinaryIEEEDoubleFrom:aStream into:f. |
701 | 209 |
^ f |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
210 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
211 |
"Modified: 16.4.1996 / 21:23:38 / cg" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
212 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
213 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
214 |
readBinaryIEEEDoubleFrom:aStream |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
215 |
"read a float from the binary stream, aStream, |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
216 |
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
|
217 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
218 |
|f| |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
219 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
220 |
f := self basicNew. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
221 |
self readBinaryIEEEDoubleFrom:aStream into:f. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
222 |
^ f |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
223 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
224 |
"Created: 16.4.1996 / 20:59:59 / cg" |
701 | 225 |
! |
226 |
||
227 |
readBinaryIEEEDoubleFrom:aStream into:aFloat |
|
228 |
"read the receivers value from the binary stream, aStream, |
|
229 |
interpreting the next bytes as an IEEE formatted 8-byte float" |
|
230 |
||
231 |
" |
|
232 |
this implementation is wrong: does not work on non-IEEE machines |
|
233 |
(to date all machines where ST/X is running on use |
|
234 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
235 |
" |
|
236 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
237 |
"swap the bytes" |
|
238 |
8 to:1 by:-1 do:[:i | |
|
239 |
aFloat basicAt:i put:(aStream next) |
|
240 |
]. |
|
241 |
^ self |
|
242 |
]. |
|
243 |
1 to:8 do:[:i | |
|
244 |
aFloat basicAt:i put:aStream next |
|
245 |
] |
|
246 |
! |
|
247 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
248 |
readBinaryIEEESingleFrom:aStream |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
249 |
"read a float value from the binary stream, aStream, |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
250 |
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
|
251 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
252 |
|f| |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
253 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
254 |
f := self basicNew. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
255 |
self readBinaryIEEESingleFrom:aStream into:f. |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
256 |
^ f |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
257 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
258 |
"Created: 16.4.1996 / 21:00:35 / cg" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
259 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
260 |
|
701 | 261 |
readBinaryIEEESingleFrom:aStream into:aFloat |
262 |
"read a float value from the binary stream, aStream, |
|
263 |
interpreting the next bytes as an IEEE formatted 4-byte float" |
|
264 |
||
265 |
" |
|
266 |
this implementation is wrong: does not work on non-IEEE machines |
|
267 |
(to date all machines where ST/X is running on use |
|
268 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
269 |
" |
|
270 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
271 |
"swap the bytes" |
|
272 |
8 to:4 by:-1 do:[:i | |
|
273 |
aFloat basicAt:i put:(aStream next) |
|
274 |
]. |
|
275 |
^ self |
|
276 |
]. |
|
277 |
1 to:4 do:[:i | |
|
278 |
aFloat basicAt:i put:aStream next |
|
279 |
] |
|
280 |
! |
|
281 |
||
282 |
storeBinaryIEEEDouble:aFloat on:aStream |
|
283 |
"store aFloat as an IEEE formatted 8-byte float |
|
284 |
onto the binary stream, aStream" |
|
285 |
||
286 |
" |
|
287 |
this implementation is wrong: does not work on non-IEEE machines |
|
288 |
(to date all machines where ST/X is running on use |
|
289 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
290 |
" |
|
291 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
292 |
"swap the bytes" |
|
293 |
8 to:1 by:-1 do:[:i | |
|
294 |
aStream nextPut:(aFloat basicAt:i). |
|
295 |
]. |
|
296 |
^ self |
|
297 |
]. |
|
298 |
1 to:8 do:[:i | |
|
299 |
aStream nextPut:(aFloat basicAt:i). |
|
300 |
]. |
|
301 |
! |
|
302 |
||
303 |
storeBinaryIEEESingle:aFloat on:aStream |
|
304 |
"store aFloat as an IEEE formatted 4-byte float |
|
305 |
onto the binary stream, aStream" |
|
306 |
||
307 |
" |
|
308 |
this implementation is wrong: does not work on non-IEEE machines |
|
309 |
(to date all machines where ST/X is running on use |
|
310 |
IEEE float format. Need more here, when porting ST/X to 370's) |
|
311 |
" |
|
312 |
UninterpretedBytes isBigEndian ifFalse:[ |
|
313 |
"swap the bytes" |
|
314 |
8 to:4 by:-1 do:[:i | |
|
315 |
aStream nextPut:(aFloat basicAt:i). |
|
316 |
]. |
|
317 |
^ self |
|
318 |
]. |
|
319 |
1 to:4 do:[:i | |
|
320 |
aStream nextPut:(aFloat basicAt:i). |
|
321 |
] |
|
322 |
! ! |
|
323 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
324 |
!Float class methodsFor:'constants'! |
1 | 325 |
|
701 | 326 |
pi |
1260 | 327 |
"return the constant pi as Float" |
1 | 328 |
|
701 | 329 |
^ 3.1415926535897932384626434 |
1260 | 330 |
|
331 |
"Modified: 23.4.1996 / 09:27:02 / cg" |
|
1 | 332 |
! |
333 |
||
334 |
unity |
|
1260 | 335 |
"return the neutral element for multiplication (1.0) as Float" |
1 | 336 |
|
337 |
^ 1.0 |
|
1260 | 338 |
|
339 |
"Modified: 23.4.1996 / 09:27:09 / cg" |
|
1 | 340 |
! |
341 |
||
701 | 342 |
zero |
1260 | 343 |
"return the neutral element for addition (0.0) as Float" |
1 | 344 |
|
701 | 345 |
^ 0.0 |
1260 | 346 |
|
347 |
"Modified: 23.4.1996 / 09:27:15 / cg" |
|
1 | 348 |
! ! |
349 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
350 |
!Float class methodsFor:'queries'! |
3 | 351 |
|
352 |
isBuiltInClass |
|
1264 | 353 |
"return true if this class is known by the run-time-system. |
354 |
Here, true is returned for myself, false for subclasses." |
|
3 | 355 |
|
356 |
^ self == Float |
|
1264 | 357 |
|
358 |
"Modified: 23.4.1996 / 15:59:04 / cg" |
|
3 | 359 |
! ! |
360 |
||
1 | 361 |
!Float methodsFor:'arithmetic'! |
362 |
||
701 | 363 |
* aNumber |
364 |
"return the product of the receiver and the argument, aNumber" |
|
365 |
||
366 |
%{ /* NOCONTEXT */ |
|
367 |
||
368 |
OBJ newFloat; |
|
369 |
double result; |
|
370 |
||
371 |
if (__isSmallInteger(aNumber)) { |
|
1133 | 372 |
result = __floatVal(self) * (double)(__intVal(aNumber)); |
701 | 373 |
retResult: |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
374 |
__qMKFLOAT(newFloat, result); |
701 | 375 |
RETURN ( newFloat ); |
376 |
} |
|
377 |
if (__isFloatLike(aNumber)) { |
|
1133 | 378 |
result = __floatVal(self) * __floatVal(aNumber); |
701 | 379 |
goto retResult; |
380 |
} |
|
381 |
%} |
|
382 |
. |
|
383 |
^ aNumber productFromFloat:self |
|
384 |
! |
|
385 |
||
1 | 386 |
+ aNumber |
387 |
"return the sum of the receiver and the argument, aNumber" |
|
388 |
||
389 |
%{ /* NOCONTEXT */ |
|
13 | 390 |
|
1 | 391 |
OBJ newFloat; |
392 |
double result; |
|
393 |
||
250 | 394 |
if (__isSmallInteger(aNumber)) { |
1133 | 395 |
result = __floatVal(self) + (double)(__intVal(aNumber)); |
1 | 396 |
retResult: |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
397 |
__qMKFLOAT(newFloat, result); |
175 | 398 |
RETURN ( newFloat ); |
1 | 399 |
} |
283 | 400 |
if (__isFloatLike(aNumber)) { |
1133 | 401 |
result = __floatVal(self) + __floatVal(aNumber); |
175 | 402 |
goto retResult; |
1 | 403 |
} |
404 |
%} |
|
405 |
. |
|
406 |
^ aNumber sumFromFloat:self |
|
407 |
! |
|
408 |
||
409 |
- aNumber |
|
410 |
"return the difference of the receiver and the argument, aNumber" |
|
411 |
||
412 |
%{ /* NOCONTEXT */ |
|
13 | 413 |
|
1 | 414 |
OBJ newFloat; |
415 |
double result; |
|
416 |
||
250 | 417 |
if (__isSmallInteger(aNumber)) { |
1133 | 418 |
result = __floatVal(self) - (double)(__intVal(aNumber)); |
1 | 419 |
retResult: |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
420 |
__qMKFLOAT(newFloat, result); |
175 | 421 |
RETURN ( newFloat ); |
1 | 422 |
} |
283 | 423 |
if (__isFloatLike(aNumber)) { |
1133 | 424 |
result = __floatVal(self) - __floatVal(aNumber); |
175 | 425 |
goto retResult; |
1 | 426 |
} |
427 |
%} |
|
428 |
. |
|
429 |
^ aNumber differenceFromFloat:self |
|
430 |
! |
|
431 |
||
432 |
/ aNumber |
|
433 |
"return the quotient of the receiver and the argument, aNumber" |
|
434 |
||
435 |
%{ /* NOCONTEXT */ |
|
436 |
||
437 |
OBJ newFloat; |
|
438 |
double result, val; |
|
439 |
||
250 | 440 |
if (__isSmallInteger(aNumber)) { |
1133 | 441 |
if (aNumber != __MKSMALLINT(0)) { |
442 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
|
1 | 443 |
retResult: |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
444 |
__qMKFLOAT(newFloat, result); |
175 | 445 |
RETURN ( newFloat ); |
446 |
} |
|
1 | 447 |
} else { |
305 | 448 |
if (__isFloatLike(aNumber)) { |
1133 | 449 |
val = __floatVal(aNumber); |
175 | 450 |
if (val != 0.0) { |
1133 | 451 |
result = __floatVal(self) / val; |
175 | 452 |
goto retResult; |
453 |
} |
|
454 |
} |
|
1 | 455 |
} |
456 |
%} |
|
457 |
. |
|
458 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
142 | 459 |
" |
460 |
No, you shalt not divide by zero |
|
461 |
" |
|
175 | 462 |
^ DivisionByZeroSignal raise. |
1 | 463 |
]. |
464 |
^ aNumber quotientFromFloat:self |
|
465 |
! |
|
466 |
||
467 |
negated |
|
468 |
"return myself negated" |
|
469 |
||
470 |
%{ /* NOCONTEXT */ |
|
13 | 471 |
|
3 | 472 |
OBJ newFloat; |
1133 | 473 |
double rslt = - __floatVal(self); |
3 | 474 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
475 |
__qMKFLOAT(newFloat, rslt); |
3 | 476 |
RETURN ( newFloat ); |
1 | 477 |
%} |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
478 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
479 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
480 |
uncheckedDivide:aNumber |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
481 |
"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
|
482 |
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
|
483 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
484 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
485 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
486 |
OBJ newFloat; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
487 |
double result, val; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
488 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
489 |
if (__isSmallInteger(aNumber)) { |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
490 |
result = __floatVal(self) / ( (double)__intVal(aNumber)) ; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
491 |
retResult: |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
492 |
__qMKFLOAT(newFloat, result); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
493 |
RETURN ( newFloat ); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
494 |
} else if (__isFloatLike(aNumber)) { |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
495 |
val = __floatVal(aNumber); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
496 |
result = __floatVal(self) / val; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
497 |
goto retResult; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
498 |
} |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
499 |
%} |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
500 |
. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
501 |
^ aNumber quotientFromFloat:self |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
502 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
503 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
504 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
505 |
0.0 uncheckedDivide:0.0 |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
506 |
1.0 uncheckedDivide:0.0 |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
507 |
" |
1 | 508 |
! ! |
509 |
||
701 | 510 |
!Float methodsFor:'binary storage'! |
511 |
||
512 |
storeBinaryDefinitionOn:stream manager:manager |
|
1260 | 513 |
"store the receiver in a binary format on stream. |
514 |
This is an internal interface for binary storage mechanism." |
|
515 |
||
701 | 516 |
manager putIdOfClass:(self class) on:stream. |
517 |
Float storeBinaryIEEEDouble:self on:stream. |
|
1260 | 518 |
|
519 |
"Modified: 23.4.1996 / 09:29:48 / cg" |
|
701 | 520 |
! ! |
521 |
||
522 |
!Float methodsFor:'coercion and converting'! |
|
1 | 523 |
|
3014 | 524 |
asDouble |
525 |
"ST80 compatibility: return a float with same value - thats me" |
|
526 |
||
527 |
^ self |
|
528 |
! |
|
529 |
||
701 | 530 |
asFloat |
531 |
"return a float with same value - thats me" |
|
532 |
||
533 |
^ self |
|
534 |
! |
|
535 |
||
536 |
asInteger |
|
537 |
"return an integer with same value - might truncate" |
|
538 |
||
1 | 539 |
%{ /* NOCONTEXT */ |
1670 | 540 |
double dVal; |
13 | 541 |
|
1670 | 542 |
dVal = __floatVal(self); |
543 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
3139 | 544 |
RETURN ( __MKSMALLINT( (INT)dVal) ); |
701 | 545 |
} |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
546 |
%}. |
701 | 547 |
^ super asInteger |
548 |
||
549 |
"12345.0 asInteger" |
|
550 |
"1e15 asInteger" |
|
1 | 551 |
! |
552 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
553 |
asShortFloat |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
554 |
"return a shortFloat with same value as receiver" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
555 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
556 |
%{ /* NOCONTEXT */ |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
557 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
558 |
OBJ dummy = @global(ShortFloat); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
559 |
OBJ newFloat; |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
560 |
float fVal = (float)__floatVal(self); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
561 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
562 |
__qMKSFLOAT(newFloat, fVal); |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
563 |
RETURN ( newFloat ); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
564 |
%} |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
565 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
566 |
|
701 | 567 |
coerce:aNumber |
568 |
"return aNumber converted into receivers type" |
|
1 | 569 |
|
701 | 570 |
^ aNumber asFloat |
571 |
! |
|
13 | 572 |
|
701 | 573 |
generality |
574 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
575 |
||
576 |
^ 80 |
|
1 | 577 |
! ! |
578 |
||
579 |
!Float methodsFor:'comparing'! |
|
580 |
||
581 |
< aNumber |
|
582 |
"return true, if the argument is greater" |
|
583 |
||
584 |
%{ /* NOCONTEXT */ |
|
13 | 585 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
586 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
587 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
588 |
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
|
589 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
590 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
591 |
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
|
592 |
} |
1 | 593 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
594 |
%}. |
1 | 595 |
^ aNumber lessFromFloat:self |
596 |
! |
|
597 |
||
598 |
<= aNumber |
|
599 |
"return true, if the argument is greater or equal" |
|
600 |
||
601 |
%{ /* NOCONTEXT */ |
|
13 | 602 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
603 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
604 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
605 |
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
|
606 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
607 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
608 |
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
|
609 |
} |
1 | 610 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
611 |
%}. |
1 | 612 |
^ self retry:#<= coercing:aNumber |
613 |
! |
|
614 |
||
615 |
= aNumber |
|
175 | 616 |
"return true, if the arguments value are equal by value" |
1 | 617 |
|
618 |
%{ /* NOCONTEXT */ |
|
13 | 619 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
620 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
621 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
622 |
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
|
623 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
624 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
625 |
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
|
626 |
} |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
627 |
} else { |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
628 |
RETURN (false); |
1 | 629 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
630 |
%}. |
1 | 631 |
^ self retry:#= coercing:aNumber |
632 |
! |
|
633 |
||
701 | 634 |
> aNumber |
635 |
"return true, if the argument is less" |
|
1 | 636 |
|
637 |
%{ /* NOCONTEXT */ |
|
13 | 638 |
|
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
639 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
640 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
641 |
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
|
642 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
643 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
644 |
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
|
645 |
} |
1 | 646 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
647 |
%}. |
701 | 648 |
^ self retry:#> coercing:aNumber |
649 |
! |
|
650 |
||
651 |
>= aNumber |
|
652 |
"return true, if the argument is less or equal" |
|
653 |
||
654 |
%{ /* NOCONTEXT */ |
|
655 |
||
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
656 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
657 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
658 |
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
|
659 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
660 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
661 |
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
|
662 |
} |
701 | 663 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
664 |
%}. |
701 | 665 |
^ self retry:#>= coercing:aNumber |
92 | 666 |
! |
667 |
||
668 |
hash |
|
669 |
"return a number for hashing; redefined, since floats compare |
|
670 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
671 |
as 3 hash." |
|
672 |
||
305 | 673 |
|i| |
92 | 674 |
|
675 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
175 | 676 |
i := self asInteger. |
677 |
self = i ifTrue:[ |
|
678 |
^ i hash |
|
679 |
]. |
|
92 | 680 |
]. |
681 |
||
682 |
" |
|
305 | 683 |
mhmh take some of my value-bits to hash on |
92 | 684 |
" |
305 | 685 |
^ (((self basicAt:8) bitAnd:16r3F) bitShift:24) + |
686 |
((self basicAt:7) bitShift:16) + |
|
687 |
((self basicAt:6) bitShift:8) + |
|
688 |
(self basicAt:5) |
|
92 | 689 |
|
690 |
" |
|
691 |
3 hash |
|
692 |
3.0 hash |
|
693 |
3.1 hash |
|
694 |
3.14159 hash |
|
695 |
31.4159 hash |
|
696 |
3.141591 hash |
|
697 |
1.234567890123456 hash |
|
698 |
1.234567890123457 hash |
|
699 |
Set withAll:#(3 3.0 99 99.0 3.1415) |
|
700 |
" |
|
1 | 701 |
! |
702 |
||
701 | 703 |
~= aNumber |
704 |
"return true, if the arguments value are not equal" |
|
1 | 705 |
|
706 |
%{ /* NOCONTEXT */ |
|
707 |
||
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
708 |
if (aNumber != nil) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
709 |
if (__isSmallInteger(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
710 |
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
|
711 |
} |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
712 |
if (__qIsFloatLike(aNumber)) { |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
713 |
RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
714 |
} |
3115
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
715 |
} else { |
1ecfb9118163
dont check twice for nil (in compare ops)
Claus Gittinger <cg@exept.de>
parents:
3014
diff
changeset
|
716 |
RETURN (true); |
1 | 717 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
718 |
%}. |
701 | 719 |
^ self retry:#~= coercing:aNumber |
1 | 720 |
! ! |
721 |
||
722 |
!Float methodsFor:'mathematical functions'! |
|
723 |
||
701 | 724 |
arcCos |
725 |
"return the arccosine of myself as radians" |
|
726 |
||
727 |
%{ /* NOCONTEXT */ |
|
728 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
729 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
730 |
OBJ newFloat; |
701 | 731 |
|
732 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
733 |
rslt = acos(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
734 |
if (errno == 0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
735 |
__qMKFLOAT(newFloat, rslt); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
736 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
737 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
738 |
%}. |
701 | 739 |
^ DomainErrorSignal raise |
740 |
! |
|
741 |
||
742 |
arcSin |
|
743 |
"return the arcsine of myself as radians" |
|
744 |
||
745 |
%{ /* NOCONTEXT */ |
|
746 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
747 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
748 |
OBJ newFloat; |
701 | 749 |
|
750 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
751 |
rslt = asin(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
752 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
753 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
754 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
755 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
756 |
%}. |
701 | 757 |
^ DomainErrorSignal raise |
758 |
! |
|
759 |
||
760 |
arcTan |
|
761 |
"return the arctangent of myself as radians" |
|
762 |
||
763 |
%{ /* NOCONTEXT */ |
|
764 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
765 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
766 |
OBJ newFloat; |
701 | 767 |
|
768 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
769 |
rslt = atan(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
770 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
771 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
772 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
773 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
774 |
%}. |
701 | 775 |
^ DomainErrorSignal raise |
776 |
! |
|
777 |
||
778 |
cos |
|
779 |
"return the cosine of myself interpreted as radians" |
|
780 |
||
781 |
%{ /* NOCONTEXT */ |
|
782 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
783 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
784 |
OBJ newFloat; |
701 | 785 |
|
786 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
787 |
rslt = cos(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
788 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
789 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
790 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
791 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
792 |
%}. |
701 | 793 |
^ DomainErrorSignal raise |
794 |
! |
|
795 |
||
796 |
exp |
|
797 |
"return e raised to the power of the receiver" |
|
798 |
||
799 |
%{ /* NOCONTEXT */ |
|
800 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
801 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
802 |
OBJ newFloat; |
701 | 803 |
|
804 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
805 |
rslt = exp(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
806 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
807 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
808 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
809 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
810 |
%}. |
701 | 811 |
^ DomainErrorSignal raise |
812 |
! |
|
813 |
||
1 | 814 |
ln |
815 |
"return the natural logarithm of myself" |
|
816 |
||
817 |
%{ /* NOCONTEXT */ |
|
818 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
819 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
820 |
OBJ newFloat; |
1 | 821 |
|
822 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
823 |
rslt = log(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
824 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
825 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
826 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
827 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
828 |
%}. |
142 | 829 |
" |
830 |
an invalid value for logarithm |
|
831 |
" |
|
131 | 832 |
^ DomainErrorSignal raise |
1 | 833 |
! |
834 |
||
835 |
raisedTo:aNumber |
|
836 |
"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
|
837 |
|
1 | 838 |
|n| |
839 |
||
840 |
n := aNumber asFloat. |
|
841 |
%{ |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
842 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
843 |
OBJ newFloat; |
1 | 844 |
|
283 | 845 |
if (__isFloatLike(n)) { |
175 | 846 |
errno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
847 |
rslt = pow(__floatVal(self), __floatVal(n)); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
848 |
#if 0 |
175 | 849 |
errno = 0; /* XXXX */ |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
850 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
851 |
if (errno == 0) { |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
852 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
853 |
RETURN ( newFloat ); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
854 |
} |
1 | 855 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
856 |
%}. |
142 | 857 |
" |
858 |
an invalid argument (not convertable to float ?) |
|
859 |
" |
|
131 | 860 |
^ DomainErrorSignal raise |
1 | 861 |
! |
862 |
||
863 |
sin |
|
864 |
"return the sine of myself interpreted as radians" |
|
865 |
||
866 |
%{ /* NOCONTEXT */ |
|
867 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
868 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
869 |
OBJ newFloat; |
1 | 870 |
|
871 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
872 |
rslt = sin(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
873 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
874 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
875 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
876 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
877 |
%}. |
131 | 878 |
^ DomainErrorSignal raise |
1 | 879 |
! |
880 |
||
881 |
sqrt |
|
882 |
"return the square root of myself" |
|
883 |
||
884 |
%{ /* NOCONTEXT */ |
|
885 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
886 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
887 |
OBJ newFloat; |
1 | 888 |
|
889 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
890 |
rslt = sqrt(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
891 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
892 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
893 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
894 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
895 |
%}. |
131 | 896 |
^ DomainErrorSignal raise |
701 | 897 |
! |
258 | 898 |
|
701 | 899 |
tan |
900 |
"return the tangent of myself interpreted as radians" |
|
258 | 901 |
|
902 |
%{ /* NOCONTEXT */ |
|
903 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
904 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
905 |
OBJ newFloat; |
44 | 906 |
|
701 | 907 |
errno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
908 |
rslt = tan(__floatVal(self)); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
909 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
910 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
911 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
912 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
913 |
%}. |
701 | 914 |
^ DomainErrorSignal raise |
13 | 915 |
! ! |
916 |
||
92 | 917 |
!Float methodsFor:'printing & storing'! |
1 | 918 |
|
919 |
printString |
|
2358 | 920 |
"return a printed representation of the receiver; |
921 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
922 |
6 valid digits are printed." |
|
1 | 923 |
|
924 |
%{ /* NOCONTEXT */ |
|
925 |
||
13 | 926 |
char buffer[64]; |
1 | 927 |
REGISTER char *cp; |
314 | 928 |
OBJ s; |
2358 | 929 |
char *fmt; |
930 |
char fmtBuffer[20]; |
|
931 |
||
932 |
if (__isString(@global(DefaultPrintFormat))) { |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
933 |
fmt = (char *) __stringVal(@global(DefaultPrintFormat)); |
2358 | 934 |
} else { |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
935 |
/* |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
936 |
* in case we get called before #initialize ... |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
937 |
*/ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
938 |
fmt = ".6"; |
2358 | 939 |
} |
940 |
||
941 |
/* |
|
942 |
* build a printf format string |
|
943 |
*/ |
|
944 |
fmtBuffer[0] = '%'; |
|
945 |
strncpy(fmtBuffer+1, fmt, 10); |
|
946 |
#ifdef SYSV |
|
947 |
strcat(fmtBuffer, "lg"); |
|
948 |
#else |
|
949 |
strcat(fmtBuffer, "G"); |
|
950 |
#endif |
|
314 | 951 |
|
2358 | 952 |
sprintf(buffer, fmtBuffer, __floatVal(self)); |
1 | 953 |
|
954 |
/* |
|
13 | 955 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
1 | 956 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
957 |
*/ |
|
958 |
for (cp = buffer; *cp; cp++) { |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
959 |
if ((*cp == '.') || (*cp == 'e')) break; |
1 | 960 |
} |
961 |
if (! *cp) { |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
962 |
*cp++ = '.'; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
963 |
*cp++ = '0'; |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
964 |
*cp = '\0'; |
1 | 965 |
} |
966 |
||
1133 | 967 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 968 |
if (s != nil) { |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
969 |
RETURN (s); |
314 | 970 |
} |
971 |
%}. |
|
972 |
" |
|
973 |
memory allocation (for the new string) failed. |
|
974 |
When we arrive here, there was no memory, even after a garbage collect. |
|
975 |
This means, that the VM wanted to get some more memory from the |
|
976 |
OS, which was not kind enough to give it. |
|
977 |
Bad luck - you should increase the swap space on your machine. |
|
978 |
" |
|
979 |
^ ObjectMemory allocationFailureSignal raise. |
|
980 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
981 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
982 |
1.0 printString |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
983 |
1.234 printString |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
984 |
1e10 printString |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
985 |
1.2e3 printString |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
986 |
1.2e30 printString |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
987 |
(1.0 uncheckedDivide:0) printString |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
988 |
(0.0 uncheckedDivide:0) printString |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
989 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
990 |
|
1 | 991 |
! |
992 |
||
993 |
printfPrintString:formatString |
|
994 |
"non-portable: return a printed representation of the receiver |
|
995 |
as specified by formatString, which is defined by printf. |
|
31 | 996 |
If you use this, be aware, that specifying doubles differs on |
1 | 997 |
systems; on SYSV machines you have to give something like %lf, |
13 | 998 |
while on BSD systems the format string has to be %F. |
31 | 999 |
Also, the resulting string may not be longer than 255 bytes - |
54 | 1000 |
since thats the (static) size of the buffer. |
1001 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 1002 |
|
13 | 1003 |
%{ /* STACK: 400 */ |
1 | 1004 |
char buffer[256]; |
314 | 1005 |
OBJ s; |
1 | 1006 |
|
54 | 1007 |
if (__isString(formatString)) { |
1133 | 1008 |
sprintf(buffer, __stringVal(formatString), __floatVal(self)); |
369 | 1009 |
|
1133 | 1010 |
s = __MKSTRING(buffer COMMA_SND); |
343 | 1011 |
if (s != nil) { |
1012 |
RETURN (s); |
|
1013 |
} |
|
1 | 1014 |
} |
314 | 1015 |
%}. |
1 | 1016 |
self primitiveFailed |
1017 |
||
1018 |
"Float pi printfPrintString:'%%lg -> %lg'" |
|
1019 |
"Float pi printfPrintString:'%%lf -> %lf'" |
|
1020 |
"Float pi printfPrintString:'%%7.5lg -> %7.5lg'" |
|
1021 |
"Float pi printfPrintString:'%%7.5lf -> %7.5lf'" |
|
1022 |
"Float pi printfPrintString:'%%G -> %G'" |
|
1023 |
"Float pi printfPrintString:'%%F -> %F'" |
|
1024 |
"Float pi printfPrintString:'%%7.5G -> %7.5G'" |
|
1025 |
"Float pi printfPrintString:'%%7.5F -> %7.5F'" |
|
1026 |
! ! |
|
701 | 1027 |
|
1028 |
!Float methodsFor:'private accessing'! |
|
1029 |
||
1030 |
basicAt:index |
|
1031 |
"return an internal byte of the float. |
|
1032 |
The value returned here depends on byte order, float representation etc. |
|
1033 |
Therefore, this method should be used strictly private. |
|
1034 |
||
1035 |
Notice: |
|
1036 |
the need to redefine this method here is due to the |
|
1037 |
inability of many machines to store floats in non-double aligned memory. |
|
1038 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
1039 |
and the actual float is stored at index 5 .. 12. |
|
1040 |
To hide this at one place, this method knows about that, and returns |
|
1041 |
values as if this filler wasnt present." |
|
1042 |
||
1043 |
%{ /* NOCONTEXT */ |
|
1044 |
||
1045 |
register int indx; |
|
1046 |
unsigned char *cp; |
|
1047 |
||
1048 |
/* |
|
1049 |
* notice the missing test for self being a nonNilObject - |
|
1050 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1051 |
* and SmallInteger |
|
1052 |
*/ |
|
1053 |
if (__isSmallInteger(index)) { |
|
1133 | 1054 |
indx = __intVal(index) - 1; |
701 | 1055 |
if ((indx >= 0) && (indx < sizeof(double))) { |
1133 | 1056 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
1057 |
RETURN ( __MKSMALLINT(cp[indx] & 0xFF) ); |
|
701 | 1058 |
} |
1059 |
} |
|
1060 |
%}. |
|
1061 |
index isInteger ifFalse:[ |
|
1062 |
^ self indexNotInteger |
|
1063 |
]. |
|
1064 |
^ self subscriptBoundsError:index |
|
1065 |
! |
|
1066 |
||
1067 |
basicAt:index put:value |
|
1068 |
"set an internal byte of the float. |
|
1069 |
The value to be stored here depends on byte order, float representation etc. |
|
1070 |
Therefore, this method should be used strictly private. |
|
1071 |
||
1072 |
Notice: |
|
1073 |
the need to redefine this method here is due to the |
|
1074 |
inability of many machines to store floats in non-double aligned memory. |
|
1075 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
1076 |
and the actual float is stored at index 5 .. 12. |
|
1077 |
To hide this at one place, this method knows about that, and returns |
|
1078 |
values as if this filler wasnt present." |
|
1079 |
||
1080 |
%{ /* NOCONTEXT */ |
|
1081 |
register int indx, val; |
|
1082 |
unsigned char *cp; |
|
1083 |
||
1084 |
/* |
|
1085 |
* notice the missing test for self being a nonNilObject - |
|
1086 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1087 |
* and SmallInteger |
|
1088 |
*/ |
|
1089 |
if (__bothSmallInteger(index, value)) { |
|
1133 | 1090 |
val = __intVal(value); |
701 | 1091 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
1133 | 1092 |
indx = __intVal(index) - 1; |
701 | 1093 |
if ((indx >= 0) && (indx < sizeof(double))) { |
1133 | 1094 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
701 | 1095 |
cp[indx] = val; |
1096 |
RETURN ( value ); |
|
1097 |
} |
|
1098 |
} |
|
1099 |
} |
|
1100 |
%}. |
|
1101 |
index isInteger ifFalse:[ |
|
1102 |
^ self indexNotInteger |
|
1103 |
]. |
|
1104 |
value isInteger ifFalse:[ |
|
1105 |
" |
|
1106 |
the object to store should be an integer number |
|
1107 |
" |
|
1108 |
^ self elementNotInteger |
|
1109 |
]. |
|
1110 |
(value between:0 and:255) ifFalse:[ |
|
1111 |
" |
|
1112 |
the object to store must be a bytes value |
|
1113 |
" |
|
1114 |
^ self elementBoundsError |
|
1115 |
]. |
|
1116 |
^ self subscriptBoundsError:index |
|
1117 |
! ! |
|
1118 |
||
1119 |
!Float methodsFor:'testing'! |
|
1120 |
||
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1121 |
isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1122 |
"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
|
1123 |
i.e. not NaN and not infinite." |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1124 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1125 |
%{ /* NOCONTEXT */ |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1126 |
|
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1127 |
double dV = __floatVal(self); |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1128 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1129 |
if (finite(dV)) { RETURN (true); } |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1130 |
%}. |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1131 |
^false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1132 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1133 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1134 |
1.0 isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1135 |
(0.0 uncheckedDivide: 0.0) isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1136 |
(1.0 uncheckedDivide: 0.0) isFinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1137 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1138 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1139 |
! |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1140 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1141 |
isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1142 |
"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
|
1143 |
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
|
1144 |
however, inline C-code could produce them ... |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1145 |
Redefined here for speed" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1146 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1147 |
%{ /* NOCONTEXT */ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1148 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1149 |
double dV = __floatVal(self); |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1150 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1151 |
#if defined(isinf) || defined(LINUX) |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1152 |
if (isinf(dV)) { RETURN (true); } |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1153 |
#else |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1154 |
if (!finite(dV) && !isnan(dV)) { RETURN (true); } |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1155 |
#endif |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1156 |
%}. |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1157 |
^ false |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1158 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1159 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1160 |
1.0 isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1161 |
(0.0 uncheckedDivide: 0.0) isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1162 |
(1.0 uncheckedDivide: 0.0) isInfinite |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1163 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1164 |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1165 |
! |
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1166 |
|
2387 | 1167 |
isNaN |
1168 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
1169 |
These are not created by ST/X float operations (they raise an exception); |
|
1170 |
however, inline C-code could produce them ..." |
|
1171 |
||
1172 |
%{ /* NOCONTEXT */ |
|
1173 |
||
3139 | 1174 |
double dV = (__floatVal(self)); |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1175 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1176 |
if (isnan(dV)) { RETURN (true); } |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1177 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1178 |
#if 0 /* Currently all our systems support isnan() |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1179 |
* 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
|
1180 |
*/ |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1181 |
|
2395 | 1182 |
/* |
1183 |
* sigh - every vendor is playing its own game here ... |
|
1184 |
* Q: what are standards worth, anyway ? |
|
1185 |
*/ |
|
2392 | 1186 |
#ifdef IS_NAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1187 |
if (IS_NAN(dV)) { RETURN (true); } |
3139 | 1188 |
RETURN (false); |
2393 | 1189 |
#endif |
3139 | 1190 |
|
2393 | 1191 |
#ifdef IS_QNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1192 |
if (IS_QNAN(dV)) { RETURN (true); } |
3139 | 1193 |
RETURN (false); |
2393 | 1194 |
#endif |
2392 | 1195 |
|
2393 | 1196 |
#ifdef FLT_SNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1197 |
if (dV == FLT_SNAN) { RETURN (true); } |
3139 | 1198 |
RETURN (false); |
2393 | 1199 |
#endif |
3139 | 1200 |
|
2393 | 1201 |
#ifdef FLT_QNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1202 |
if (dV == FLT_QNAN) { RETURN (true); } |
3139 | 1203 |
RETURN (false); |
2393 | 1204 |
#endif |
1205 |
||
1206 |
#ifdef _SNANF |
|
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1207 |
if (dV == _SNAN) { RETURN (true); } |
3139 | 1208 |
RETURN (false); |
2393 | 1209 |
#endif |
3139 | 1210 |
|
2393 | 1211 |
#ifdef _QNANF |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1212 |
if (dV == _QNAN) { RETURN (true); } |
3139 | 1213 |
RETURN (false); |
2393 | 1214 |
#endif |
2392 | 1215 |
|
2395 | 1216 |
#ifdef IsPosNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1217 |
if IsPosNAN(dV) { RETURN (true); } |
3139 | 1218 |
RETURN (false); |
2395 | 1219 |
#endif |
3139 | 1220 |
|
2395 | 1221 |
#ifdef IsNegNAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1222 |
if IsNegNAN(dV) { RETURN (true); } |
3139 | 1223 |
RETURN (false); |
2395 | 1224 |
#endif |
1225 |
||
2393 | 1226 |
#ifdef NAN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1227 |
if (dV == NAN) { RETURN (true); } |
3139 | 1228 |
RETURN (false); |
2390 | 1229 |
#endif |
3139 | 1230 |
|
2399 | 1231 |
#ifdef NaN |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1232 |
if (NaN(dV)) { RETURN (true); } |
3139 | 1233 |
RETURN (false); |
2399 | 1234 |
#endif |
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1235 |
|
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1236 |
#endif /* 0 */ |
2392 | 1237 |
%}. |
1238 |
^ false |
|
3139 | 1239 |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1240 |
" |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1241 |
1.0 isNaN |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1242 |
(0.0 uncheckedDivide: 0.0) isNaN |
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1243 |
" |
3139 | 1244 |
|
2387 | 1245 |
! |
1246 |
||
701 | 1247 |
negative |
1248 |
"return true if the receiver is less than zero" |
|
1249 |
||
1250 |
%{ /* NOCONTEXT */ |
|
1251 |
||
1133 | 1252 |
RETURN ( (__floatVal(self) < 0.0) ? true : false ); |
701 | 1253 |
%} |
1254 |
! |
|
1255 |
||
1256 |
positive |
|
1257 |
"return true if the receiver is greater or equal to zero" |
|
1258 |
||
1259 |
%{ /* NOCONTEXT */ |
|
1260 |
||
1133 | 1261 |
RETURN ( (__floatVal(self) >= 0.0) ? true : false ); |
701 | 1262 |
%} |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1263 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1264 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1265 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1266 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1267 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1268 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1269 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1270 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1271 |
%} |
701 | 1272 |
! ! |
1273 |
||
1274 |
!Float methodsFor:'truncation and rounding'! |
|
1275 |
||
1276 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1277 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 1278 |
|
1279 |
|val| |
|
1280 |
||
1281 |
%{ |
|
1282 |
double ceil(); |
|
1283 |
double dVal; |
|
1284 |
||
1285 |
/* |
|
1286 |
* ST-80 (and X3J20) returns integer. |
|
1287 |
*/ |
|
1133 | 1288 |
dVal = ceil(__floatVal(self)); |
701 | 1289 |
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
|
1290 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1291 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1292 |
val = __MKFLOAT(dVal); |
701 | 1293 |
%}. |
1294 |
^ val asInteger |
|
1295 |
! |
|
1296 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1297 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1298 |
"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
|
1299 |
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
|
1300 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1301 |
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
|
1302 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1303 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1304 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1305 |
double ceil(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1306 |
double dVal; |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1307 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1308 |
/* |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1309 |
* ST-80 (and X3J20) returns integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1310 |
*/ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1311 |
dVal = ceil(__floatVal(self)); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1312 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1313 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1314 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1315 |
|
701 | 1316 |
floor |
1317 |
"return the integer nearest the receiver towards negative infinity." |
|
1318 |
||
1319 |
|val| |
|
1320 |
||
1321 |
%{ |
|
1322 |
double floor(); |
|
1323 |
double dVal; |
|
1324 |
||
1325 |
/* |
|
1326 |
* ST-80 (and X3J20) returns integer. |
|
1327 |
*/ |
|
1133 | 1328 |
dVal = floor(__floatVal(self)); |
701 | 1329 |
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
|
1330 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1331 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1332 |
val = __MKFLOAT(dVal); |
701 | 1333 |
%}. |
1334 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1335 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1336 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1337 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1338 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1339 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1340 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1341 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1342 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1343 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1344 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1345 |
floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1346 |
"return the integer nearest the receiver towards negative infinity |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1347 |
as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1348 |
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
|
1349 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1350 |
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
|
1351 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1352 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1353 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1354 |
double floor(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1355 |
double dVal; |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1356 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1357 |
dVal = floor(__floatVal(self)); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1358 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1359 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1360 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1361 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1362 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1363 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1364 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1365 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1366 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1367 |
|
701 | 1368 |
! |
1369 |
||
1370 |
rounded |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1371 |
"return the receiver rounded to the nearest integer" |
701 | 1372 |
|
1373 |
|val| |
|
1374 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1375 |
%{ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1376 |
double floor(), ceil(); |
701 | 1377 |
double dVal; |
1378 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1379 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1380 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1381 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1382 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1383 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1384 |
} |
701 | 1385 |
/* |
1386 |
* ST-80 (and X3J20) returns integer. |
|
1387 |
*/ |
|
1388 |
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
|
1389 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1390 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1391 |
val = __MKFLOAT(dVal); |
701 | 1392 |
%}. |
1393 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1394 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1395 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1396 |
0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1397 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1398 |
0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1399 |
-0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1400 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1401 |
-0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1402 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1403 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1404 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1405 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1406 |
"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
|
1407 |
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
|
1408 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1409 |
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
|
1410 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1411 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1412 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1413 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1414 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1415 |
double floor(), ceil(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1416 |
double dVal; |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1417 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1418 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1419 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1420 |
dVal = ceil(dVal - 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1421 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1422 |
dVal = floor(dVal + 0.5); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1423 |
} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1424 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1425 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1426 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1427 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1428 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1429 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1430 |
0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1431 |
-0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1432 |
" |
701 | 1433 |
! |
1434 |
||
1435 |
truncated |
|
1436 |
"return the receiver truncated towards zero as an integer" |
|
1437 |
||
1438 |
|val| |
|
1439 |
||
1440 |
%{ |
|
1441 |
double floor(), ceil(); |
|
1442 |
double dVal; |
|
1443 |
||
1133 | 1444 |
dVal = __floatVal(self); |
701 | 1445 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1446 |
dVal = ceil(dVal); |
701 | 1447 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1448 |
dVal = floor(dVal); |
701 | 1449 |
} |
1450 |
||
1451 |
/* |
|
1452 |
* ST-80 (and X3J20) returns integer. |
|
1453 |
*/ |
|
1454 |
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
|
1455 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1456 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1457 |
val = __MKFLOAT(dVal); |
701 | 1458 |
%}. |
1459 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1460 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1461 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1462 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1463 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1464 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1465 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1466 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1467 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1468 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1469 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1470 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1471 |
"return the receiver truncated towards zero as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1472 |
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
|
1473 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1474 |
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
|
1475 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1476 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1477 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1478 |
double floor(), ceil(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1479 |
double dVal; |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1480 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1481 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1482 |
if (dVal < 0.0) { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1483 |
dVal = ceil(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1484 |
} else { |
3127
590c7d2bb4b9
fixes isNAN (on linux); added #isInfinite
Claus Gittinger <cg@exept.de>
parents:
3118
diff
changeset
|
1485 |
dVal = floor(dVal); |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1486 |
} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1487 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1488 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1489 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1490 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1491 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1492 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1493 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1494 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1495 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1496 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1497 |
|
701 | 1498 |
! ! |
1499 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1500 |
!Float class methodsFor:'documentation'! |
701 | 1501 |
|
1502 |
version |
|
3146
4e46505d1d59
New #finite, fix #isNaN and #isInfinite.
Stefan Vogel <sv@exept.de>
parents:
3139
diff
changeset
|
1503 |
^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.69 1998-01-07 12:02:20 stefan Exp $' |
701 | 1504 |
! ! |
2387 | 1505 |
Float initialize! |