author | ca |
Fri, 10 Oct 1997 15:00:18 +0200 | |
changeset 3014 | 9934bb63d455 |
parent 2892 | 1695b2af0ae2 |
child 3115 | 1ecfb9118163 |
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 |
|
3014 | 449 |
asDouble |
450 |
"ST80 compatibility: return a float with same value - thats me" |
|
451 |
||
452 |
^ self |
|
453 |
! |
|
454 |
||
701 | 455 |
asFloat |
456 |
"return a float with same value - thats me" |
|
457 |
||
458 |
^ self |
|
459 |
! |
|
460 |
||
461 |
asInteger |
|
462 |
"return an integer with same value - might truncate" |
|
463 |
||
1 | 464 |
%{ /* NOCONTEXT */ |
1670 | 465 |
double dVal; |
13 | 466 |
|
1670 | 467 |
dVal = __floatVal(self); |
468 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
469 |
RETURN ( __MKSMALLINT( (INT)dVal) ); |
|
701 | 470 |
} |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
471 |
%}. |
701 | 472 |
^ super asInteger |
473 |
||
474 |
"12345.0 asInteger" |
|
475 |
"1e15 asInteger" |
|
1 | 476 |
! |
477 |
||
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
478 |
asShortFloat |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
479 |
"return a shortFloat with same value as receiver" |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
480 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
481 |
%{ /* NOCONTEXT */ |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
482 |
|
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
483 |
OBJ dummy = @global(ShortFloat); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
484 |
OBJ newFloat; |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
485 |
float fVal = (float)__floatVal(self); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
486 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
487 |
__qMKSFLOAT(newFloat, fVal); |
1198
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
488 |
RETURN ( newFloat ); |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
489 |
%} |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
490 |
! |
284eeba6b719
docu & limited shortFloat support
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
491 |
|
701 | 492 |
coerce:aNumber |
493 |
"return aNumber converted into receivers type" |
|
1 | 494 |
|
701 | 495 |
^ aNumber asFloat |
496 |
! |
|
13 | 497 |
|
701 | 498 |
generality |
499 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
500 |
||
501 |
^ 80 |
|
1 | 502 |
! ! |
503 |
||
504 |
!Float methodsFor:'comparing'! |
|
505 |
||
506 |
< aNumber |
|
507 |
"return true, if the argument is greater" |
|
508 |
||
509 |
%{ /* NOCONTEXT */ |
|
13 | 510 |
|
250 | 511 |
if (__isSmallInteger(aNumber)) { |
1133 | 512 |
RETURN ( (__floatVal(self) < (double)(__intVal(aNumber))) ? true : false ); |
1 | 513 |
} |
283 | 514 |
if (__isFloatLike(aNumber)) { |
1133 | 515 |
RETURN ( (__floatVal(self) < __floatVal(aNumber)) ? true : false ); |
1 | 516 |
} |
517 |
%} |
|
518 |
. |
|
519 |
^ aNumber lessFromFloat:self |
|
520 |
! |
|
521 |
||
522 |
<= aNumber |
|
523 |
"return true, if the argument is greater or equal" |
|
524 |
||
525 |
%{ /* NOCONTEXT */ |
|
13 | 526 |
|
250 | 527 |
if (__isSmallInteger(aNumber)) { |
1133 | 528 |
RETURN ( (__floatVal(self) <= (double)(__intVal(aNumber))) ? true : false ); |
1 | 529 |
} |
283 | 530 |
if (__isFloatLike(aNumber)) { |
1133 | 531 |
RETURN ( (__floatVal(self) <= __floatVal(aNumber)) ? true : false ); |
1 | 532 |
} |
533 |
%} |
|
534 |
. |
|
535 |
^ self retry:#<= coercing:aNumber |
|
536 |
! |
|
537 |
||
538 |
= aNumber |
|
175 | 539 |
"return true, if the arguments value are equal by value" |
1 | 540 |
|
541 |
%{ /* NOCONTEXT */ |
|
13 | 542 |
|
250 | 543 |
if (__isSmallInteger(aNumber)) { |
1133 | 544 |
RETURN ( (__floatVal(self) == (double)(__intVal(aNumber))) ? true : false ); |
1 | 545 |
} |
283 | 546 |
if (__isFloatLike(aNumber)) { |
1133 | 547 |
RETURN ( (__floatVal(self) == __floatVal(aNumber)) ? true : false ); |
1 | 548 |
} |
549 |
%} |
|
550 |
. |
|
551 |
^ self retry:#= coercing:aNumber |
|
552 |
! |
|
553 |
||
701 | 554 |
> aNumber |
555 |
"return true, if the argument is less" |
|
1 | 556 |
|
557 |
%{ /* NOCONTEXT */ |
|
13 | 558 |
|
250 | 559 |
if (__isSmallInteger(aNumber)) { |
1133 | 560 |
RETURN ( (__floatVal(self) > (double)(__intVal(aNumber))) ? true : false ); |
1 | 561 |
} |
283 | 562 |
if (__isFloatLike(aNumber)) { |
1133 | 563 |
RETURN ( (__floatVal(self) > __floatVal(aNumber)) ? true : false ); |
1 | 564 |
} |
565 |
%} |
|
566 |
. |
|
701 | 567 |
^ self retry:#> coercing:aNumber |
568 |
! |
|
569 |
||
570 |
>= aNumber |
|
571 |
"return true, if the argument is less or equal" |
|
572 |
||
573 |
%{ /* NOCONTEXT */ |
|
574 |
||
575 |
if (__isSmallInteger(aNumber)) { |
|
1133 | 576 |
RETURN ( (__floatVal(self) >= (double)(__intVal(aNumber))) ? true : false ); |
701 | 577 |
} |
578 |
if (__isFloatLike(aNumber)) { |
|
1133 | 579 |
RETURN ( (__floatVal(self) >= __floatVal(aNumber)) ? true : false ); |
701 | 580 |
} |
581 |
%} |
|
582 |
. |
|
583 |
^ self retry:#>= coercing:aNumber |
|
92 | 584 |
! |
585 |
||
586 |
hash |
|
587 |
"return a number for hashing; redefined, since floats compare |
|
588 |
by numeric value (i.e. 3.0 = 3), therefore 3.0 hash must be the same |
|
589 |
as 3 hash." |
|
590 |
||
305 | 591 |
|i| |
92 | 592 |
|
593 |
(self >= SmallInteger minVal and:[self <= SmallInteger maxVal]) ifTrue:[ |
|
175 | 594 |
i := self asInteger. |
595 |
self = i ifTrue:[ |
|
596 |
^ i hash |
|
597 |
]. |
|
92 | 598 |
]. |
599 |
||
600 |
" |
|
305 | 601 |
mhmh take some of my value-bits to hash on |
92 | 602 |
" |
305 | 603 |
^ (((self basicAt:8) bitAnd:16r3F) bitShift:24) + |
604 |
((self basicAt:7) bitShift:16) + |
|
605 |
((self basicAt:6) bitShift:8) + |
|
606 |
(self basicAt:5) |
|
92 | 607 |
|
608 |
" |
|
609 |
3 hash |
|
610 |
3.0 hash |
|
611 |
3.1 hash |
|
612 |
3.14159 hash |
|
613 |
31.4159 hash |
|
614 |
3.141591 hash |
|
615 |
1.234567890123456 hash |
|
616 |
1.234567890123457 hash |
|
617 |
Set withAll:#(3 3.0 99 99.0 3.1415) |
|
618 |
" |
|
1 | 619 |
! |
620 |
||
701 | 621 |
~= aNumber |
622 |
"return true, if the arguments value are not equal" |
|
1 | 623 |
|
624 |
%{ /* NOCONTEXT */ |
|
625 |
||
701 | 626 |
if (__isSmallInteger(aNumber)) { |
1133 | 627 |
RETURN ( (__floatVal(self) != (double)(__intVal(aNumber))) ? true : false ); |
701 | 628 |
} |
629 |
if (__isFloatLike(aNumber)) { |
|
1133 | 630 |
RETURN ( (__floatVal(self) != __floatVal(aNumber)) ? true : false ); |
1 | 631 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
632 |
%}. |
701 | 633 |
^ self retry:#~= coercing:aNumber |
1 | 634 |
! ! |
635 |
||
636 |
!Float methodsFor:'mathematical functions'! |
|
637 |
||
701 | 638 |
arcCos |
639 |
"return the arccosine of myself as radians" |
|
640 |
||
641 |
%{ /* NOCONTEXT */ |
|
642 |
||
643 |
double acos(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
644 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
645 |
OBJ newFloat; |
701 | 646 |
|
647 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
648 |
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
|
649 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
650 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
651 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
652 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
653 |
%}. |
701 | 654 |
^ DomainErrorSignal raise |
655 |
! |
|
656 |
||
657 |
arcSin |
|
658 |
"return the arcsine of myself as radians" |
|
659 |
||
660 |
%{ /* NOCONTEXT */ |
|
661 |
||
662 |
double asin(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
663 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
664 |
OBJ newFloat; |
701 | 665 |
|
666 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
667 |
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
|
668 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
669 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
670 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
671 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
672 |
%}. |
701 | 673 |
^ DomainErrorSignal raise |
674 |
! |
|
675 |
||
676 |
arcTan |
|
677 |
"return the arctangent of myself as radians" |
|
678 |
||
679 |
%{ /* NOCONTEXT */ |
|
680 |
||
681 |
double atan(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
682 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
683 |
OBJ newFloat; |
701 | 684 |
|
685 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
686 |
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
|
687 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
688 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
689 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
690 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
691 |
%}. |
701 | 692 |
^ DomainErrorSignal raise |
693 |
! |
|
694 |
||
695 |
cos |
|
696 |
"return the cosine of myself interpreted as radians" |
|
697 |
||
698 |
%{ /* NOCONTEXT */ |
|
699 |
||
700 |
double cos(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
701 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
702 |
OBJ newFloat; |
701 | 703 |
|
704 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
705 |
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
|
706 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
707 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
708 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
709 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
710 |
%}. |
701 | 711 |
^ DomainErrorSignal raise |
712 |
! |
|
713 |
||
714 |
exp |
|
715 |
"return e raised to the power of the receiver" |
|
716 |
||
717 |
%{ /* NOCONTEXT */ |
|
718 |
||
719 |
double exp(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
720 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
721 |
OBJ newFloat; |
701 | 722 |
|
723 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
724 |
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
|
725 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
726 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
727 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
728 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
729 |
%}. |
701 | 730 |
^ DomainErrorSignal raise |
731 |
! |
|
732 |
||
1 | 733 |
ln |
734 |
"return the natural logarithm of myself" |
|
735 |
||
736 |
%{ /* NOCONTEXT */ |
|
737 |
||
738 |
double log(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
739 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
740 |
OBJ newFloat; |
1 | 741 |
|
742 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
743 |
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
|
744 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
745 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
746 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
747 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
748 |
%}. |
142 | 749 |
" |
750 |
an invalid value for logarithm |
|
751 |
" |
|
131 | 752 |
^ DomainErrorSignal raise |
1 | 753 |
! |
754 |
||
755 |
raisedTo:aNumber |
|
756 |
"return self raised to the power of aNumber" |
|
757 |
|n| |
|
758 |
||
759 |
n := aNumber asFloat. |
|
760 |
%{ |
|
761 |
double pow(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
762 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
763 |
OBJ newFloat; |
1 | 764 |
|
283 | 765 |
if (__isFloatLike(n)) { |
175 | 766 |
errno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
767 |
rslt = pow(__floatVal(self), __floatVal(n)); |
175 | 768 |
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
|
769 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
770 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
771 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
772 |
} |
1 | 773 |
} |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
774 |
%}. |
142 | 775 |
" |
776 |
an invalid argument (not convertable to float ?) |
|
777 |
" |
|
131 | 778 |
^ DomainErrorSignal raise |
1 | 779 |
! |
780 |
||
781 |
sin |
|
782 |
"return the sine of myself interpreted as radians" |
|
783 |
||
784 |
%{ /* NOCONTEXT */ |
|
785 |
||
786 |
double sin(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
787 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
788 |
OBJ newFloat; |
1 | 789 |
|
790 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
791 |
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
|
792 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
793 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
794 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
795 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
796 |
%}. |
131 | 797 |
^ DomainErrorSignal raise |
1 | 798 |
! |
799 |
||
800 |
sqrt |
|
801 |
"return the square root of myself" |
|
802 |
||
803 |
%{ /* NOCONTEXT */ |
|
804 |
||
805 |
double sqrt(); |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
806 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
807 |
OBJ newFloat; |
1 | 808 |
|
809 |
errno = 0; |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
810 |
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
|
811 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
812 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
813 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
814 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
815 |
%}. |
131 | 816 |
^ DomainErrorSignal raise |
701 | 817 |
! |
258 | 818 |
|
701 | 819 |
tan |
820 |
"return the tangent of myself interpreted as radians" |
|
258 | 821 |
|
822 |
%{ /* NOCONTEXT */ |
|
823 |
||
701 | 824 |
double tan(); |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
825 |
double rslt; |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
826 |
OBJ newFloat; |
44 | 827 |
|
701 | 828 |
errno = 0; |
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
829 |
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
|
830 |
if (errno == 0) { |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
831 |
__qMKFLOAT(newFloat, rslt); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
832 |
RETURN ( newFloat ); |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
833 |
} |
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
834 |
%}. |
701 | 835 |
^ DomainErrorSignal raise |
13 | 836 |
! ! |
837 |
||
92 | 838 |
!Float methodsFor:'printing & storing'! |
1 | 839 |
|
840 |
printString |
|
2358 | 841 |
"return a printed representation of the receiver; |
842 |
if not specified otherwise (by setting DefaultPrintFormat), |
|
843 |
6 valid digits are printed." |
|
1 | 844 |
|
845 |
%{ /* NOCONTEXT */ |
|
846 |
||
13 | 847 |
char buffer[64]; |
1 | 848 |
REGISTER char *cp; |
314 | 849 |
OBJ s; |
2358 | 850 |
char *fmt; |
851 |
char fmtBuffer[20]; |
|
852 |
||
853 |
if (__isString(@global(DefaultPrintFormat))) { |
|
2892 | 854 |
fmt = (char *) __stringVal(@global(DefaultPrintFormat)); |
2358 | 855 |
} else { |
856 |
/* |
|
857 |
* in case we get called before #initialize ... |
|
858 |
*/ |
|
859 |
fmt = ".6"; |
|
860 |
} |
|
861 |
||
862 |
/* |
|
863 |
* build a printf format string |
|
864 |
*/ |
|
865 |
fmtBuffer[0] = '%'; |
|
866 |
strncpy(fmtBuffer+1, fmt, 10); |
|
867 |
#ifdef SYSV |
|
868 |
strcat(fmtBuffer, "lg"); |
|
869 |
#else |
|
870 |
strcat(fmtBuffer, "G"); |
|
871 |
#endif |
|
314 | 872 |
|
31 | 873 |
/* |
874 |
* actually only needed on sparc: since thisContext is |
|
875 |
* in a global register, which gets destroyed by printf, |
|
876 |
* manually save it here - very stupid ... |
|
877 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
878 |
__BEGIN_PROTECT_REGISTERS__ |
1 | 879 |
|
2358 | 880 |
sprintf(buffer, fmtBuffer, __floatVal(self)); |
1 | 881 |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
882 |
__END_PROTECT_REGISTERS__ |
1133 | 883 |
|
1 | 884 |
/* |
13 | 885 |
* kludge to make integral float f prints as "f.0" (not as "f" as printf does) |
1 | 886 |
* (i.e. look if string contains '.' or 'e' and append '.0' if not) |
887 |
*/ |
|
888 |
for (cp = buffer; *cp; cp++) { |
|
175 | 889 |
if ((*cp == '.') || (*cp == 'e')) break; |
1 | 890 |
} |
891 |
if (! *cp) { |
|
175 | 892 |
*cp++ = '.'; |
893 |
*cp++ = '0'; |
|
894 |
*cp = '\0'; |
|
1 | 895 |
} |
896 |
||
1133 | 897 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 898 |
if (s != nil) { |
343 | 899 |
RETURN (s); |
314 | 900 |
} |
901 |
%}. |
|
902 |
" |
|
903 |
memory allocation (for the new string) failed. |
|
904 |
When we arrive here, there was no memory, even after a garbage collect. |
|
905 |
This means, that the VM wanted to get some more memory from the |
|
906 |
OS, which was not kind enough to give it. |
|
907 |
Bad luck - you should increase the swap space on your machine. |
|
908 |
" |
|
909 |
^ ObjectMemory allocationFailureSignal raise. |
|
910 |
||
1 | 911 |
"1.0 printString" |
912 |
"1.234 printString" |
|
913 |
"1e10 printString" |
|
914 |
"1.2e3 printString" |
|
915 |
"1.2e30 printString" |
|
916 |
! |
|
917 |
||
918 |
printfPrintString:formatString |
|
919 |
"non-portable: return a printed representation of the receiver |
|
920 |
as specified by formatString, which is defined by printf. |
|
31 | 921 |
If you use this, be aware, that specifying doubles differs on |
1 | 922 |
systems; on SYSV machines you have to give something like %lf, |
13 | 923 |
while on BSD systems the format string has to be %F. |
31 | 924 |
Also, the resulting string may not be longer than 255 bytes - |
54 | 925 |
since thats the (static) size of the buffer. |
926 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 927 |
|
13 | 928 |
%{ /* STACK: 400 */ |
1 | 929 |
char buffer[256]; |
314 | 930 |
OBJ s; |
1 | 931 |
|
54 | 932 |
if (__isString(formatString)) { |
175 | 933 |
/* |
934 |
* actually only needed on sparc: since thisContext is |
|
935 |
* in a global register, which gets destroyed by printf, |
|
936 |
* manually save it here - very stupid ... |
|
937 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
938 |
__BEGIN_PROTECT_REGISTERS__ |
31 | 939 |
|
1133 | 940 |
sprintf(buffer, __stringVal(formatString), __floatVal(self)); |
369 | 941 |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
942 |
__END_PROTECT_REGISTERS__ |
369 | 943 |
|
1133 | 944 |
s = __MKSTRING(buffer COMMA_SND); |
343 | 945 |
if (s != nil) { |
946 |
RETURN (s); |
|
947 |
} |
|
1 | 948 |
} |
314 | 949 |
%}. |
1 | 950 |
self primitiveFailed |
951 |
||
952 |
"Float pi printfPrintString:'%%lg -> %lg'" |
|
953 |
"Float pi printfPrintString:'%%lf -> %lf'" |
|
954 |
"Float pi printfPrintString:'%%7.5lg -> %7.5lg'" |
|
955 |
"Float pi printfPrintString:'%%7.5lf -> %7.5lf'" |
|
956 |
"Float pi printfPrintString:'%%G -> %G'" |
|
957 |
"Float pi printfPrintString:'%%F -> %F'" |
|
958 |
"Float pi printfPrintString:'%%7.5G -> %7.5G'" |
|
959 |
"Float pi printfPrintString:'%%7.5F -> %7.5F'" |
|
960 |
! ! |
|
701 | 961 |
|
962 |
!Float methodsFor:'private accessing'! |
|
963 |
||
964 |
basicAt:index |
|
965 |
"return an internal byte of the float. |
|
966 |
The value returned here depends on byte order, float representation etc. |
|
967 |
Therefore, this method should be used strictly private. |
|
968 |
||
969 |
Notice: |
|
970 |
the need to redefine this method here is due to the |
|
971 |
inability of many machines to store floats in non-double aligned memory. |
|
972 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
973 |
and the actual float is stored at index 5 .. 12. |
|
974 |
To hide this at one place, this method knows about that, and returns |
|
975 |
values as if this filler wasnt present." |
|
976 |
||
977 |
%{ /* NOCONTEXT */ |
|
978 |
||
979 |
register int indx; |
|
980 |
unsigned char *cp; |
|
981 |
||
982 |
/* |
|
983 |
* notice the missing test for self being a nonNilObject - |
|
984 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
985 |
* and SmallInteger |
|
986 |
*/ |
|
987 |
if (__isSmallInteger(index)) { |
|
1133 | 988 |
indx = __intVal(index) - 1; |
701 | 989 |
if ((indx >= 0) && (indx < sizeof(double))) { |
1133 | 990 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
991 |
RETURN ( __MKSMALLINT(cp[indx] & 0xFF) ); |
|
701 | 992 |
} |
993 |
} |
|
994 |
%}. |
|
995 |
index isInteger ifFalse:[ |
|
996 |
^ self indexNotInteger |
|
997 |
]. |
|
998 |
^ self subscriptBoundsError:index |
|
999 |
! |
|
1000 |
||
1001 |
basicAt:index put:value |
|
1002 |
"set an internal byte of the float. |
|
1003 |
The value to be stored here depends on byte order, float representation etc. |
|
1004 |
Therefore, this method should be used strictly private. |
|
1005 |
||
1006 |
Notice: |
|
1007 |
the need to redefine this method here is due to the |
|
1008 |
inability of many machines to store floats in non-double aligned memory. |
|
1009 |
Therefore, on some machines, the first 4 bytes of a float are left unused, |
|
1010 |
and the actual float is stored at index 5 .. 12. |
|
1011 |
To hide this at one place, this method knows about that, and returns |
|
1012 |
values as if this filler wasnt present." |
|
1013 |
||
1014 |
%{ /* NOCONTEXT */ |
|
1015 |
register int indx, val; |
|
1016 |
unsigned char *cp; |
|
1017 |
||
1018 |
/* |
|
1019 |
* notice the missing test for self being a nonNilObject - |
|
1020 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
1021 |
* and SmallInteger |
|
1022 |
*/ |
|
1023 |
if (__bothSmallInteger(index, value)) { |
|
1133 | 1024 |
val = __intVal(value); |
701 | 1025 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
1133 | 1026 |
indx = __intVal(index) - 1; |
701 | 1027 |
if ((indx >= 0) && (indx < sizeof(double))) { |
1133 | 1028 |
cp = (unsigned char *)(& (__FloatInstPtr(self)->f_floatvalue)); |
701 | 1029 |
cp[indx] = val; |
1030 |
RETURN ( value ); |
|
1031 |
} |
|
1032 |
} |
|
1033 |
} |
|
1034 |
%}. |
|
1035 |
index isInteger ifFalse:[ |
|
1036 |
^ self indexNotInteger |
|
1037 |
]. |
|
1038 |
value isInteger ifFalse:[ |
|
1039 |
" |
|
1040 |
the object to store should be an integer number |
|
1041 |
" |
|
1042 |
^ self elementNotInteger |
|
1043 |
]. |
|
1044 |
(value between:0 and:255) ifFalse:[ |
|
1045 |
" |
|
1046 |
the object to store must be a bytes value |
|
1047 |
" |
|
1048 |
^ self elementBoundsError |
|
1049 |
]. |
|
1050 |
^ self subscriptBoundsError:index |
|
1051 |
! ! |
|
1052 |
||
1053 |
!Float methodsFor:'testing'! |
|
1054 |
||
2387 | 1055 |
isNaN |
1056 |
"return true, if the receiver is an invalid float (NaN - not a number). |
|
1057 |
These are not created by ST/X float operations (they raise an exception); |
|
1058 |
however, inline C-code could produce them ..." |
|
1059 |
||
1060 |
%{ /* NOCONTEXT */ |
|
1061 |
||
2395 | 1062 |
/* |
1063 |
* sigh - every vendor is playing its own game here ... |
|
1064 |
* Q: what are standards worth, anyway ? |
|
1065 |
*/ |
|
2392 | 1066 |
#ifdef IS_NAN |
1067 |
if (IS_NAN(__floatVal(self))) { RETURN (true); } |
|
2393 | 1068 |
#endif |
1069 |
#ifdef IS_QNAN |
|
2392 | 1070 |
if (IS_QNAN(__floatVal(self))) { RETURN (true); } |
2393 | 1071 |
#endif |
2392 | 1072 |
|
2393 | 1073 |
#ifdef FLT_SNAN |
1074 |
if (__floatVal(self) == FLT_SNAN) { RETURN (true); } |
|
1075 |
#endif |
|
1076 |
#ifdef FLT_QNAN |
|
1077 |
if (__floatVal(self) == FLT_QNAN) { RETURN (true); } |
|
1078 |
#endif |
|
1079 |
||
1080 |
#ifdef _SNANF |
|
2390 | 1081 |
if (__floatVal(self) == _SNAN) { RETURN (true); } |
2393 | 1082 |
#endif |
1083 |
#ifdef _QNANF |
|
2390 | 1084 |
if (__floatVal(self) == _QNAN) { RETURN (true); } |
2393 | 1085 |
#endif |
2392 | 1086 |
|
2395 | 1087 |
#ifdef IsPosNAN |
1088 |
if IsPosNAN(__floatVal(self)) { RETURN (true); } |
|
1089 |
#endif |
|
1090 |
#ifdef IsNegNAN |
|
1091 |
if IsNegNAN(__floatVal(self)) { RETURN (true); } |
|
1092 |
#endif |
|
1093 |
||
2393 | 1094 |
#ifdef NAN |
2392 | 1095 |
if (__floatVal(self) == NAN) { RETURN (true); } |
2390 | 1096 |
#endif |
2399 | 1097 |
#ifdef NaN |
2401 | 1098 |
if (NaN(__shortFloatVal(self))) { RETURN (true); } |
2399 | 1099 |
#endif |
2390 | 1100 |
|
2392 | 1101 |
%}. |
1102 |
^ false |
|
2387 | 1103 |
|
2390 | 1104 |
|
2387 | 1105 |
! |
1106 |
||
701 | 1107 |
negative |
1108 |
"return true if the receiver is less than zero" |
|
1109 |
||
1110 |
%{ /* NOCONTEXT */ |
|
1111 |
||
1133 | 1112 |
RETURN ( (__floatVal(self) < 0.0) ? true : false ); |
701 | 1113 |
%} |
1114 |
! |
|
1115 |
||
1116 |
positive |
|
1117 |
"return true if the receiver is greater or equal to zero" |
|
1118 |
||
1119 |
%{ /* NOCONTEXT */ |
|
1120 |
||
1133 | 1121 |
RETURN ( (__floatVal(self) >= 0.0) ? true : false ); |
701 | 1122 |
%} |
1879
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 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1125 |
strictlyPositive |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1126 |
"return true if the receiver is greater than zero" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1127 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1128 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1129 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1130 |
RETURN ( (__floatVal(self) > 0.0) ? true : false ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1131 |
%} |
701 | 1132 |
! ! |
1133 |
||
1134 |
!Float methodsFor:'truncation and rounding'! |
|
1135 |
||
1136 |
ceiling |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1137 |
"return the smallest integer which is greater or equal to the receiver." |
701 | 1138 |
|
1139 |
|val| |
|
1140 |
||
1141 |
%{ |
|
1142 |
double ceil(); |
|
1143 |
double dVal; |
|
1144 |
||
1145 |
/* |
|
1146 |
* ST-80 (and X3J20) returns integer. |
|
1147 |
*/ |
|
1133 | 1148 |
dVal = ceil(__floatVal(self)); |
701 | 1149 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1150 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1151 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1152 |
val = __MKFLOAT(dVal); |
701 | 1153 |
%}. |
1154 |
^ val asInteger |
|
1155 |
! |
|
1156 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1157 |
ceilingAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1158 |
"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
|
1159 |
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
|
1160 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1161 |
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
|
1162 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1163 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1164 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1165 |
double ceil(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1166 |
double 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 |
* ST-80 (and X3J20) returns integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1170 |
*/ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1171 |
dVal = ceil(__floatVal(self)); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1172 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1173 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1174 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1175 |
|
701 | 1176 |
floor |
1177 |
"return the integer nearest the receiver towards negative infinity." |
|
1178 |
||
1179 |
|val| |
|
1180 |
||
1181 |
%{ |
|
1182 |
double floor(); |
|
1183 |
double dVal; |
|
1184 |
||
1185 |
/* |
|
1186 |
* ST-80 (and X3J20) returns integer. |
|
1187 |
*/ |
|
1133 | 1188 |
dVal = floor(__floatVal(self)); |
701 | 1189 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1190 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1191 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1192 |
val = __MKFLOAT(dVal); |
701 | 1193 |
%}. |
1194 |
^ val asInteger |
|
1879
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 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1198 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1199 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1200 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1201 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1202 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1203 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1204 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1205 |
floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1206 |
"return the integer nearest the receiver towards negative infinity |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1207 |
as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1208 |
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
|
1209 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1210 |
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
|
1211 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1212 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1213 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1214 |
double floor(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1215 |
double dVal; |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1216 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1217 |
dVal = floor(__floatVal(self)); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1218 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1219 |
%} |
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 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1222 |
0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1223 |
0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1224 |
-0.5 floor |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1225 |
-0.5 floorAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1226 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1227 |
|
701 | 1228 |
! |
1229 |
||
1230 |
rounded |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1231 |
"return the receiver rounded to the nearest integer" |
701 | 1232 |
|
1233 |
|val| |
|
1234 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1235 |
%{ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1236 |
double floor(), ceil(); |
701 | 1237 |
double dVal; |
1238 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1239 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1240 |
if (dVal < 0.0) { |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1241 |
dVal = ceil(dVal - 0.5); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1242 |
} else { |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1243 |
dVal = floor(dVal + 0.5); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1244 |
} |
701 | 1245 |
/* |
1246 |
* ST-80 (and X3J20) returns integer. |
|
1247 |
*/ |
|
1248 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1249 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1250 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1251 |
val = __MKFLOAT(dVal); |
701 | 1252 |
%}. |
1253 |
^ val asInteger |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1254 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1255 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1256 |
0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1257 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1258 |
0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1259 |
-0.4 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1260 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1261 |
-0.6 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1262 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1263 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1264 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1265 |
roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1266 |
"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
|
1267 |
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
|
1268 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1269 |
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
|
1270 |
float-operation." |
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 |
|val| |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1273 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1274 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1275 |
double floor(), ceil(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1276 |
double dVal; |
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 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1279 |
if (dVal < 0.0) { |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1280 |
dVal = ceil(dVal - 0.5); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1281 |
} else { |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1282 |
dVal = floor(dVal + 0.5); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1283 |
} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1284 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1285 |
%} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1286 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1287 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1288 |
0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1289 |
-0.5 rounded |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1290 |
0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1291 |
-0.5 roundedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1292 |
" |
701 | 1293 |
! |
1294 |
||
1295 |
truncated |
|
1296 |
"return the receiver truncated towards zero as an integer" |
|
1297 |
||
1298 |
|val| |
|
1299 |
||
1300 |
%{ |
|
1301 |
double floor(), ceil(); |
|
1302 |
double dVal; |
|
1303 |
||
1133 | 1304 |
dVal = __floatVal(self); |
701 | 1305 |
if (dVal < 0.0) { |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1306 |
dVal = ceil(dVal); |
701 | 1307 |
} else { |
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1308 |
dVal = floor(dVal); |
701 | 1309 |
} |
1310 |
||
1311 |
/* |
|
1312 |
* ST-80 (and X3J20) returns integer. |
|
1313 |
*/ |
|
1314 |
if ((dVal >= (double)_MIN_INT) && (dVal <= (double)_MAX_INT)) { |
|
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1315 |
RETURN ( __MKSMALLINT( (INT) dVal ) ); |
701 | 1316 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1670
diff
changeset
|
1317 |
val = __MKFLOAT(dVal); |
701 | 1318 |
%}. |
1319 |
^ val asInteger |
|
1879
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 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1323 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1324 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1325 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1326 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1327 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1328 |
! |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1329 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1330 |
truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1331 |
"return the receiver truncated towards zero as a float. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1332 |
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
|
1333 |
of the result to an integer. |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1334 |
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
|
1335 |
float-operation." |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1336 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1337 |
%{ /* NOCONTEXT */ |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1338 |
double floor(), ceil(); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1339 |
double 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 |
dVal = __floatVal(self); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1342 |
if (dVal < 0.0) { |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1343 |
dVal = ceil(dVal); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1344 |
} else { |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1345 |
dVal = floor(dVal); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1346 |
} |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1347 |
|
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1348 |
RETURN ( __MKFLOAT(dVal) ); |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1349 |
%} |
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 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1352 |
0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1353 |
-0.5 truncated |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1354 |
0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1355 |
-0.5 truncatedAsFloat |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1356 |
" |
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1357 |
|
701 | 1358 |
! ! |
1359 |
||
1879
26df273349c4
added ceilingAsFloat, floorAsFloat, truncatedAsFloat
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
1360 |
!Float class methodsFor:'documentation'! |
701 | 1361 |
|
1362 |
version |
|
3014 | 1363 |
^ '$Header: /cvs/stx/stx/libbasic/Float.st,v 1.62 1997-10-10 13:00:02 ca Exp $' |
701 | 1364 |
! ! |
2387 | 1365 |
Float initialize! |