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