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