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