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