author | Claus Gittinger <cg@exept.de> |
Tue, 05 Nov 1996 19:25:59 +0100 | |
changeset 1889 | 304e3857f0d6 |
parent 1884 | abd423adeb94 |
child 1893 | c66af5c46272 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
214 | 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 |
||
13 |
Integer subclass:#SmallInteger |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
14 |
instanceVariableNames:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
15 |
classVariableNames:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
16 |
poolDictionaries:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
17 |
category:'Magnitude-Numbers' |
1 | 18 |
! |
19 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
20 |
!SmallInteger class methodsFor:'documentation'! |
1 | 21 |
|
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
214 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
68 | 36 |
documentation |
37 |
" |
|
88 | 38 |
SmallIntegers are Integers in the range of at least +/- 2^30 |
39 |
(i.e. 31 bits, which is not guaranteed; it could be more on 64 bit cpus). |
|
40 |
||
68 | 41 |
These are no real objects - they have no instances (not even storage !!) |
42 |
and cannot be subclassed. |
|
43 |
The reason is to save both storage and runtime by not collecting |
|
44 |
SmallIntegers in the system. SmallInts are marked by having the TAG_INT |
|
88 | 45 |
bit set, in contrast to all other objects which do not. |
46 |
Since this knowledge is hardwired into the system (and there is no |
|
47 |
class-field stored with SmallIntegers) there can be no subclass of |
|
48 |
SmallInteger (sorry). |
|
49 |
||
50 |
If you really need this kind of thing, create a subclass of Integer, |
|
51 |
with an instance variable holding the value. |
|
1295 | 52 |
|
53 |
[author:] |
|
54 |
Claus Gittinger |
|
1556 | 55 |
|
56 |
[see also:] |
|
57 |
Number |
|
58 |
Float Fraction |
|
59 |
LargeInteger |
|
68 | 60 |
" |
61 |
! ! |
|
1 | 62 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
63 |
!SmallInteger class methodsFor:'instance creation'! |
1 | 64 |
|
65 |
basicNew |
|
66 |
"catch instance creation |
|
67 |
- SmallIntegers cannot be created with new" |
|
68 |
||
69 |
self error:'instances of SmallInteger cannot be created with new' |
|
70 |
! |
|
71 |
||
72 |
basicNew:size |
|
73 |
"catch instance creation |
|
74 |
- SmallIntegers cannot be created with new" |
|
75 |
||
76 |
self error:'instances of SmallInteger cannot be created with new' |
|
77 |
! ! |
|
78 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
79 |
!SmallInteger class methodsFor:'bit mask constants'! |
701 | 80 |
|
81 |
bitMaskFor:index |
|
82 |
"return a bitmask for the index's bit (index starts at 1)" |
|
83 |
||
84 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
|
85 |
^ self error:'index out of bounds' |
|
86 |
]. |
|
87 |
^ 1 bitShift:(index - 1) |
|
88 |
! ! |
|
89 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
90 |
!SmallInteger class methodsFor:'constants'! |
1 | 91 |
|
92 |
maxBits |
|
68 | 93 |
"return the number of bits in instances of me. |
94 |
For very special uses only - not constant across implementations" |
|
1 | 95 |
|
96 |
%{ /* NOCONTEXT */ |
|
1133 | 97 |
RETURN ( __MKSMALLINT(N_INT_BITS) ); |
1 | 98 |
%} |
2 | 99 |
|
100 |
"SmallInteger maxBits" |
|
1 | 101 |
! |
102 |
||
103 |
maxBytes |
|
68 | 104 |
"return the number of bytes in instances of me. |
105 |
For very special uses only - not constant across implementations" |
|
1 | 106 |
|
107 |
%{ /* NOCONTEXT */ |
|
1133 | 108 |
RETURN ( __MKSMALLINT(N_INT_BITS / 8 + 1) ); |
1 | 109 |
%} |
2 | 110 |
|
111 |
"SmallInteger maxBytes" |
|
1 | 112 |
! |
113 |
||
114 |
maxVal |
|
68 | 115 |
"return the largest Integer representable as SmallInteger. |
116 |
For very special uses only - not constant across implementations" |
|
1 | 117 |
|
118 |
%{ /* NOCONTEXT */ |
|
1133 | 119 |
RETURN ( __MKSMALLINT(_MAX_INT) ); |
1 | 120 |
%} |
2 | 121 |
|
122 |
"SmallInteger maxVal" |
|
701 | 123 |
! |
124 |
||
125 |
minVal |
|
126 |
"return the smallest Integer representable as SmallInteger. |
|
127 |
For very special uses only - not constant across implementations" |
|
128 |
||
129 |
%{ /* NOCONTEXT */ |
|
1133 | 130 |
RETURN ( __MKSMALLINT(_MIN_INT) ); |
701 | 131 |
%} |
132 |
||
133 |
"SmallInteger minVal" |
|
1 | 134 |
! ! |
135 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
136 |
!SmallInteger class methodsFor:'queries'! |
3 | 137 |
|
50 | 138 |
canBeSubclassed |
139 |
"return true, if its allowed to create subclasses of the receiver. |
|
68 | 140 |
Return nil here - since it is NOT possible for SmallInteger" |
50 | 141 |
|
142 |
^ false |
|
1 | 143 |
! |
144 |
||
701 | 145 |
isBuiltInClass |
1264 | 146 |
"return true if this class is known by the run-time-system. |
147 |
Here, true is returned." |
|
1 | 148 |
|
149 |
^ true |
|
1264 | 150 |
|
151 |
"Modified: 23.4.1996 / 16:00:33 / cg" |
|
1 | 152 |
! ! |
153 |
||
154 |
!SmallInteger methodsFor:'arithmetic'! |
|
155 |
||
156 |
* aNumber |
|
157 |
"return the product of the receivers value and the arguments value" |
|
158 |
||
159 |
%{ /* NOCONTEXT */ |
|
160 |
||
68 | 161 |
INT myValue, otherValue; |
162 |
unsigned INT productLow, productHi; |
|
163 |
int negative; |
|
164 |
||
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
165 |
# define low16Bits(foo) ((foo) & 0xFFFF) |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
166 |
# define hi16Bits(foo) ((foo) >> 16) |
95 | 167 |
|
168 |
/* |
|
169 |
* can we use long long arithmetic ? |
|
170 |
*/ |
|
171 |
#if defined(__GNUC__) && (__GNUC__ >= 2) |
|
172 |
/* |
|
173 |
* commented, since long-long arithmetic seems to |
|
174 |
* be buggy in some implementations (sparc) ... |
|
175 |
* (took me a while to find this out :-( |
|
176 |
*/ |
|
177 |
# ifdef NOTDEF |
|
178 |
# define _LONGLONG |
|
179 |
# endif |
|
180 |
#endif |
|
1 | 181 |
|
252 | 182 |
if (__isSmallInteger(aNumber)) { |
1133 | 183 |
myValue = __intVal(self); |
184 |
otherValue = __intVal(aNumber); |
|
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
185 |
|
95 | 186 |
#if defined(_LONGLONG) |
214 | 187 |
{ |
188 |
long long product; |
|
13 | 189 |
|
214 | 190 |
product = (long long)myValue * (long long)otherValue; |
191 |
if ((product >= (long long)_MIN_INT) |
|
192 |
&& (product <= (long long)_MAX_INT)) { |
|
1133 | 193 |
RETURN ( __MKSMALLINT((int)product) ); |
214 | 194 |
} |
195 |
if (product < 0) { |
|
196 |
negative = 1; |
|
197 |
product = -product; |
|
198 |
} else { |
|
199 |
negative = 0; |
|
200 |
} |
|
201 |
productHi = product >> 32; |
|
202 |
productLow = product & 0xFFFFFFFF; |
|
203 |
} |
|
13 | 204 |
#else |
214 | 205 |
negative = 0; |
206 |
if (myValue < 0) { |
|
207 |
negative = 1; |
|
208 |
myValue = -myValue; |
|
209 |
} |
|
210 |
if (otherValue < 0) { |
|
211 |
negative = (1 - negative); |
|
212 |
otherValue = -otherValue; |
|
213 |
} |
|
68 | 214 |
|
215 |
# if defined(__GNUC__) && defined(mc68k) |
|
214 | 216 |
asm ("mulu%.l %3,%1:%0" |
217 |
: "=d" ((unsigned long)(productLow)), |
|
218 |
"=d" ((unsigned long)(productHi)) |
|
219 |
: "%0" ((unsigned long)(myValue)), |
|
220 |
"dmi" ((unsigned long)(otherValue))); |
|
68 | 221 |
# else |
222 |
# if defined (__GNUC__) && defined(i386) |
|
214 | 223 |
asm ("mull %3" |
224 |
: "=a" ((unsigned long)(productLow)), |
|
225 |
"=d" ((unsigned long)(productHi)) |
|
226 |
: "%0" ((unsigned long)(myValue)), |
|
227 |
"rm" ((unsigned long)(otherValue))); |
|
68 | 228 |
# else |
214 | 229 |
{ |
230 |
unsigned INT pHH, pHL, pLH, pLL; |
|
231 |
unsigned INT low1, low2, hi1, hi2; |
|
232 |
unsigned INT t; |
|
68 | 233 |
|
214 | 234 |
/* unsigned multiply myValue * otherValue -> productHi, productLow |
235 |
* |
|
236 |
* this is too slow: |
|
237 |
* since most machines can do 32*32 to 64 bit multiply, |
|
238 |
* (or at least 32*32 with Overflow check) |
|
239 |
* - need more assembler (inline) functions here |
|
240 |
*/ |
|
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
241 |
low1 = low16Bits(myValue); |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
242 |
hi1 = hi16Bits(myValue); |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
243 |
low2 = low16Bits(otherValue); |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
244 |
hi2 = hi16Bits(otherValue); |
68 | 245 |
|
214 | 246 |
pLH = low1 * hi2; |
247 |
pHL = hi1 * low2; |
|
248 |
pLL = low1 * low2; |
|
68 | 249 |
|
214 | 250 |
/* |
251 |
* the common case ... |
|
252 |
*/ |
|
253 |
if ((pHL == 0) |
|
254 |
&& (pLH == 0) |
|
255 |
&& ((pLL & 0xC0000000) == 0)) { |
|
256 |
if (negative) { |
|
1133 | 257 |
RETURN ( __MKSMALLINT(- ((INT)pLL)) ); |
214 | 258 |
} |
1133 | 259 |
RETURN ( __MKSMALLINT((INT)pLL) ); |
214 | 260 |
} |
68 | 261 |
|
214 | 262 |
pHH = hi1 * hi2; |
68 | 263 |
|
214 | 264 |
/* |
265 |
* pHH |--------|--------| |
|
266 |
* pLH |--------|--------| |
|
267 |
* pHL |--------|--------| |
|
268 |
* pLL |--------|--------| |
|
269 |
*/ |
|
68 | 270 |
|
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
271 |
t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
272 |
productLow = (t << 16) + low16Bits(pLL); |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
273 |
productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); |
214 | 274 |
} |
68 | 275 |
# endif |
276 |
# endif |
|
214 | 277 |
if (productHi == 0) { |
278 |
if (negative) { |
|
279 |
if (productLow <= -(_MIN_INT)) { |
|
1133 | 280 |
RETURN ( __MKSMALLINT(-((INT)productLow)) ); |
214 | 281 |
} |
282 |
} else { |
|
283 |
if (productLow <= _MAX_INT) { |
|
1133 | 284 |
RETURN ( __MKSMALLINT(productLow) ); |
214 | 285 |
} |
286 |
} |
|
287 |
} |
|
95 | 288 |
#endif |
289 |
||
214 | 290 |
{ |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
291 |
extern OBJ __MKLARGEINT64(); |
68 | 292 |
|
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
293 |
RETURN (__MKLARGEINT64(negative ? -1 : 1, productLow, productHi)); |
214 | 294 |
} |
283 | 295 |
} else if (__isFloatLike(aNumber)) { |
214 | 296 |
OBJ newFloat; |
1133 | 297 |
double val = (double)__intVal(self) * __floatVal(aNumber); |
1 | 298 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
299 |
__qMKFLOAT(newFloat, val); |
214 | 300 |
RETURN ( newFloat ); |
1 | 301 |
} |
302 |
%} |
|
303 |
. |
|
304 |
^ aNumber productFromInteger:self |
|
305 |
! |
|
306 |
||
701 | 307 |
+ aNumber |
308 |
"return the sum of the receivers value and the arguments value" |
|
309 |
||
310 |
%{ /* NOCONTEXT */ |
|
311 |
||
312 |
if (__isSmallInteger(aNumber)) { |
|
313 |
#ifdef _ADD_IO_IO |
|
314 |
RETURN ( _ADD_IO_IO(self, aNumber) ); |
|
315 |
#else |
|
316 |
REGISTER INT sum; |
|
317 |
||
1133 | 318 |
sum = __intVal(self) + __intVal(aNumber); |
701 | 319 |
if ((sum >= _MIN_INT) && (sum <= _MAX_INT)) { |
1133 | 320 |
RETURN ( __MKSMALLINT(sum) ); |
701 | 321 |
} |
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
322 |
RETURN ( __MKLARGEINT(sum) ); |
701 | 323 |
#endif |
324 |
} |
|
325 |
if (__isFloatLike(aNumber)) { |
|
326 |
OBJ newFloat; |
|
1133 | 327 |
double val = (double)__intVal(self) + __floatVal(aNumber); |
701 | 328 |
|
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, val); |
701 | 330 |
RETURN ( newFloat ); |
331 |
} |
|
332 |
%} |
|
333 |
. |
|
334 |
^ aNumber sumFromInteger:self |
|
335 |
! |
|
336 |
||
337 |
- aNumber |
|
338 |
"return the difference of the receivers value and the arguments value" |
|
339 |
||
340 |
%{ /* NOCONTEXT */ |
|
341 |
||
342 |
if (__isSmallInteger(aNumber)) { |
|
343 |
#ifdef _SUB_IO_IO |
|
344 |
RETURN ( _SUB_IO_IO(self, aNumber) ); |
|
345 |
#else |
|
346 |
REGISTER INT diff; |
|
347 |
||
1133 | 348 |
diff = __intVal(self) - __intVal(aNumber); |
701 | 349 |
if ((diff >= _MIN_INT) && (diff <= _MAX_INT)) { |
1133 | 350 |
RETURN ( __MKSMALLINT(diff) ); |
701 | 351 |
} |
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
352 |
RETURN ( __MKLARGEINT(diff) ); |
701 | 353 |
#endif |
354 |
} |
|
355 |
if (__isFloatLike(aNumber)) { |
|
356 |
OBJ newFloat; |
|
1133 | 357 |
double val = (double)__intVal(self) - __floatVal(aNumber); |
701 | 358 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
359 |
__qMKFLOAT(newFloat, val); |
701 | 360 |
RETURN ( newFloat ); |
361 |
} |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
362 |
%}. |
701 | 363 |
^ aNumber differenceFromInteger:self |
364 |
! |
|
365 |
||
1 | 366 |
/ aNumber |
367 |
"return the quotient of the receivers value and the arguments value" |
|
368 |
||
369 |
%{ /* NOCONTEXT */ |
|
370 |
||
371 |
INT me, t, val; |
|
372 |
double dval; |
|
373 |
||
252 | 374 |
if (__isSmallInteger(aNumber)) { |
1133 | 375 |
val = __intVal(aNumber); |
214 | 376 |
if (val != 0) { |
1133 | 377 |
me = __intVal(self); |
214 | 378 |
t = me / val; |
1 | 379 |
#ifdef GOOD_OPTIMIZER |
214 | 380 |
if (me % val) { |
1 | 381 |
#else |
214 | 382 |
/* this is stupid - all I want is to look for a remainder ... |
383 |
but most compilers are too stupid and generate an extra modulu |
|
384 |
instruction for "if (me % val)". |
|
385 |
Even if most divide instructions already leave the remainder in |
|
386 |
some register. |
|
387 |
Therefore I use a multiplication which is faster than a modulu |
|
388 |
on most machines. Hint to GNU people :-) |
|
389 |
*/ |
|
390 |
if ((t * val) == me) { |
|
1 | 391 |
#endif |
1133 | 392 |
RETURN ( __MKSMALLINT(t) ); |
214 | 393 |
} |
394 |
} |
|
1 | 395 |
} else { |
283 | 396 |
if (__isFloatLike(aNumber)) { |
1133 | 397 |
dval = __floatVal(aNumber); |
214 | 398 |
if (dval != 0.0) { |
399 |
OBJ newFloat; |
|
1133 | 400 |
double val = (double)__intVal(self) / dval; |
62 | 401 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
402 |
__qMKFLOAT(newFloat, val); |
214 | 403 |
RETURN ( newFloat ); |
404 |
} |
|
405 |
} |
|
1 | 406 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
407 |
%}. |
1 | 408 |
aNumber isInteger ifTrue:[ |
324 | 409 |
aNumber == 0 ifTrue:[ |
214 | 410 |
^ DivisionByZeroSignal raise. |
411 |
]. |
|
412 |
^ Fraction numerator:self denominator:aNumber |
|
1 | 413 |
]. |
414 |
^ aNumber quotientFromInteger:self |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
415 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
416 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
417 |
8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
418 |
9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
419 |
9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
420 |
9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
421 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
422 |
-8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
423 |
-9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
424 |
-9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
425 |
-9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
426 |
" |
1 | 427 |
! |
428 |
||
2 | 429 |
// aNumber |
1 | 430 |
"return the integer part of the quotient of the receivers value |
1884 | 431 |
and the arguments value. The result is truncated toward negative infinity |
432 |
and negative, if the operands signs differ. |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
433 |
Be careful with negative results: 9 // 4 = 2, |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
434 |
while -9 // 4 = -3. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
435 |
See #quo: which returns -2 in the latter." |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
436 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
437 |
%{ /* NOCONTEXT */ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
438 |
INT val, rslt; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
439 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
440 |
if (__isSmallInteger(aNumber)) { |
1884 | 441 |
val = __intVal(aNumber); |
442 |
if (val != 0) { |
|
443 |
rslt = __intVal(self) / val; |
|
444 |
if (rslt < 0) { |
|
445 |
if (__intVal(self) % val) |
|
446 |
rslt--; |
|
447 |
} |
|
448 |
RETURN ( __MKSMALLINT(rslt) ); |
|
449 |
} |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
450 |
} else { |
1884 | 451 |
if (__isFraction(aNumber)) { |
452 |
OBJ t; |
|
453 |
INT num, den; |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
454 |
|
1884 | 455 |
t = __FractionInstPtr(aNumber)->f_numerator; |
456 |
if (__isSmallInteger(t)) { |
|
457 |
num = __intVal(t); |
|
458 |
t = __FractionInstPtr(aNumber)->f_denominator; |
|
459 |
if (__isSmallInteger(t)) { |
|
460 |
den = __intVal(t); |
|
461 |
RETURN ( __MKSMALLINT(__intVal(self) * den / num )); |
|
462 |
} |
|
463 |
} |
|
464 |
} |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
465 |
} |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
466 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
467 |
(aNumber = 0) ifTrue:[ |
1884 | 468 |
^ DivisionByZeroSignal raise. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
469 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
470 |
^ self retry:#// coercing:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
471 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
472 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
473 |
9 // 4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
474 |
-9 // 4 => -3 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
475 |
9 // -4 => -3 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
476 |
-9 // -4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
477 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
478 |
9 quo:4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
479 |
-9 quo:4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
480 |
9 quo:-4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
481 |
-9 quo:-4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
482 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
483 |
! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
484 |
|
2 | 485 |
\\ aNumber |
1 | 486 |
"return the integer rest of the receivers value |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
487 |
divided by the arguments value. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
488 |
This is not always the same as the result as obtained from #rem:" |
1 | 489 |
|
490 |
%{ /* NOCONTEXT */ |
|
491 |
INT mySelf, val; |
|
492 |
||
252 | 493 |
if (__isSmallInteger(aNumber)) { |
1133 | 494 |
mySelf = __intVal(self); |
214 | 495 |
if (mySelf < 0) mySelf = -mySelf; |
1133 | 496 |
val = __intVal(aNumber); |
214 | 497 |
if (val != 0) { |
498 |
if (val < 0) { |
|
1133 | 499 |
RETURN ( __MKSMALLINT(-(mySelf % -val)) ); |
214 | 500 |
} |
1133 | 501 |
RETURN ( __MKSMALLINT(mySelf % val) ); |
214 | 502 |
} |
1 | 503 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
504 |
%}. |
2 | 505 |
(aNumber = 0) ifTrue:[ |
214 | 506 |
^ DivisionByZeroSignal raise. |
1 | 507 |
]. |
2 | 508 |
^ self retry:#\\ coercing:aNumber |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
509 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
510 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
511 |
9 \\ 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
512 |
-9 \\ 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
513 |
9 rem:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
514 |
-9 rem:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
515 |
" |
1 | 516 |
! |
517 |
||
518 |
abs |
|
519 |
"return the absolute value of the receiver |
|
520 |
reimplemented here for speed" |
|
521 |
||
522 |
%{ /* NOCONTEXT */ |
|
523 |
||
1133 | 524 |
INT val = __intVal(self); |
1 | 525 |
|
62 | 526 |
if (val >= 0) { |
214 | 527 |
RETURN (self); |
62 | 528 |
} |
1 | 529 |
if (val != _MIN_INT) { |
1133 | 530 |
RETURN ( __MKSMALLINT(-val) ); |
1 | 531 |
} |
324 | 532 |
%}. |
1 | 533 |
"only reached for minVal" |
534 |
^ self negated |
|
535 |
! |
|
536 |
||
537 |
negated |
|
538 |
"return the negative value of the receiver |
|
539 |
reimplemented here for speed" |
|
540 |
||
541 |
%{ /* NOCONTEXT */ |
|
542 |
||
1133 | 543 |
INT val = __intVal(self); |
1 | 544 |
|
545 |
if (val != _MIN_INT) { |
|
1133 | 546 |
RETURN ( __MKSMALLINT(- val) ); |
1 | 547 |
} |
324 | 548 |
%}. |
549 |
"only reached for minVal" |
|
1 | 550 |
^ (LargeInteger value:(SmallInteger maxVal)) + 1 |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
551 |
! |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
552 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
553 |
quo:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
554 |
"return the integer part of the quotient of the receivers value |
1884 | 555 |
and the arguments value. The result is truncated towards zero |
556 |
and negative, if the operands signs differ.. |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
557 |
For positive results, this is the same as #//, |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
558 |
for negative results, the remainder is ignored. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
559 |
I.e.: '9 // 4 = 2' and '-9 // 4 = -3' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
560 |
in contrast: '9 quo: 4 = 2' and '-9 quo: 4 = -2'" |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
561 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
562 |
%{ /* NOCONTEXT */ |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
563 |
INT val; |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
564 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
565 |
if (__isSmallInteger(aNumber)) { |
1884 | 566 |
val = __intVal(aNumber); |
567 |
if (val != 0) { |
|
568 |
RETURN ( __MKSMALLINT(__intVal(self) / val) ); |
|
569 |
} |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
570 |
} else { |
1884 | 571 |
if (__isFraction(aNumber)) { |
572 |
OBJ t; |
|
573 |
INT num, den; |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
574 |
|
1884 | 575 |
t = __FractionInstPtr(aNumber)->f_numerator; |
576 |
if (__isSmallInteger(t)) { |
|
577 |
num = __intVal(t); |
|
578 |
t = __FractionInstPtr(aNumber)->f_denominator; |
|
579 |
if (__isSmallInteger(t)) { |
|
580 |
den = __intVal(t); |
|
581 |
RETURN ( __MKSMALLINT(__intVal(self) * den / num )); |
|
582 |
} |
|
583 |
} |
|
584 |
} |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
585 |
} |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
586 |
%}. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
587 |
(aNumber = 0) ifTrue:[ |
1884 | 588 |
^ DivisionByZeroSignal raise. |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
589 |
]. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
590 |
^ self retry:#quo: coercing:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
591 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
592 |
" |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
593 |
9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
594 |
-9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
595 |
9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
596 |
-9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
597 |
" |
1 | 598 |
! ! |
599 |
||
600 |
!SmallInteger methodsFor:'bit operators'! |
|
601 |
||
602 |
allMask:anInteger |
|
62 | 603 |
"return true if all 1-bits in anInteger are also 1 in the receiver" |
604 |
||
605 |
^ (self bitAnd:anInteger) == anInteger |
|
1 | 606 |
|
62 | 607 |
"2r00001111 allMask:2r00000001" |
608 |
"2r00001111 allMask:2r00011110" |
|
609 |
"2r00001111 allMask:2r00000000" |
|
1 | 610 |
! |
611 |
||
612 |
anyMask:anInteger |
|
62 | 613 |
"return true if any 1-bits in anInteger is also 1 in the receiver. |
614 |
(somewhat incorrect, if the mask is zero)" |
|
1 | 615 |
|
62 | 616 |
^ (self bitAnd:anInteger) ~~ 0 |
617 |
||
618 |
"2r00001111 anyMask:2r00000001" |
|
619 |
"2r00001111 anyMask:2r11110000" |
|
1 | 620 |
! |
621 |
||
701 | 622 |
bitAnd:anInteger |
623 |
"return the bitwise-and of the receiver and the argument, anInteger" |
|
1 | 624 |
|
625 |
%{ /* NOCONTEXT */ |
|
626 |
||
701 | 627 |
/* anding the tags doesn't change it */ |
628 |
if (__isSmallInteger(anInteger)) { |
|
629 |
RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) ); |
|
1 | 630 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
631 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
632 |
^ self retry:#bitAnd: coercing:anInteger |
701 | 633 |
|
634 |
"(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2" |
|
1 | 635 |
! |
636 |
||
701 | 637 |
bitAt:index |
638 |
"return the value of the index's bit (index starts at 1). |
|
639 |
Notice: the result of bitAt: on negative receivers is not |
|
640 |
defined in the language standard (since the implementation |
|
641 |
is free to choose any internal representation for integers)" |
|
642 |
||
643 |
|mask| |
|
644 |
||
645 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
|
646 |
^ self error:'index out of bounds' |
|
647 |
]. |
|
648 |
mask := 1 bitShift:(index - 1). |
|
649 |
((self bitAnd:mask) == 0) ifTrue:[^ 0]. |
|
650 |
^ 1 |
|
651 |
! |
|
652 |
||
653 |
bitInvert |
|
654 |
"return the value of the receiver with all bits inverted" |
|
62 | 655 |
|
1 | 656 |
%{ /* NOCONTEXT */ |
657 |
||
701 | 658 |
/* invert anything except tag bits */ |
659 |
RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) ); |
|
660 |
%} |
|
661 |
! |
|
1 | 662 |
|
701 | 663 |
bitOr:anInteger |
664 |
"return the bitwise-or of the receiver and the argument, anInteger" |
|
665 |
||
666 |
%{ /* NOCONTEXT */ |
|
667 |
||
668 |
/* oring the tags doesn't change it */ |
|
669 |
if (__isSmallInteger(anInteger)) { |
|
670 |
RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) ); |
|
1 | 671 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
672 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
673 |
^ self retry:#bitOr: coercing:anInteger |
701 | 674 |
|
675 |
"(2r000000100 bitOr:2r00000011) radixPrintStringRadix:2" |
|
1 | 676 |
! |
677 |
||
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
678 |
bitShift32:shiftCount |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
679 |
"return the value of the receiver shifted by shiftCount bits, |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
680 |
but only within 32 bits, shifting into/out-of the sign bit. |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
681 |
May be useful for communication interfaces, to create ST-numbers |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
682 |
from a signed 32bit int value given as individual bytes." |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
683 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
684 |
%{ /* NOCONTEXT */ |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
685 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
686 |
INT bits, count; |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
687 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
688 |
if (__isSmallInteger(shiftCount)) { |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
689 |
count = __intVal(shiftCount); |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
690 |
bits = __intVal(self); |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
691 |
if (count > 0) { |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
692 |
bits = bits << count; |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
693 |
} else { |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
694 |
bits = bits >> (-count); |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
695 |
} |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
696 |
RETURN (__MKINT(bits)); |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
697 |
} |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
698 |
%}. |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
699 |
^ self primitiveFailed |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
700 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
701 |
" |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
702 |
128 bitShift:24 |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
703 |
128 bitShift32:24 |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
704 |
" |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
705 |
! |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
706 |
|
1 | 707 |
bitShift:shiftCount |
708 |
"return the value of the receiver shifted by shiftCount bits; |
|
62 | 709 |
leftShift if shiftCount > 0; rightShift otherwise. |
95 | 710 |
Notice: the result of bitShift: on negative receivers is not |
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
711 |
defined in the language standard (since the implementation |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
712 |
is free to choose any internal representation for integers)" |
1 | 713 |
|
714 |
%{ /* NOCONTEXT */ |
|
715 |
||
716 |
INT bits, count; |
|
717 |
||
252 | 718 |
if (__isSmallInteger(shiftCount)) { |
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
719 |
count = __intVal(shiftCount); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
720 |
bits = __intVal(self); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
721 |
if (bits == 0) { |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
722 |
RETURN (self); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
723 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
724 |
|
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
725 |
if (count > 0) { |
95 | 726 |
#if defined(_LONGLONG) |
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
727 |
unsigned long long result; |
95 | 728 |
|
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
729 |
result = bits; |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
730 |
if (count <= N_INT_BITS) { |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
731 |
result <<= count; |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
732 |
if (result <= _MAX_INT) { |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
733 |
RETURN ( __MKSMALLINT(result) ); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
734 |
} |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
735 |
{ |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
736 |
extern OBJ __MKLARGEINT64(); |
95 | 737 |
|
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
738 |
RETURN (__MKLARGEINT64(1, (int)(result >> 32), (int)(result & 0xFFFFFFFF))); |
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
739 |
} |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
740 |
} |
95 | 741 |
#else |
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
742 |
/* |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
743 |
* check for overflow |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
744 |
*/ |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
745 |
if (count < (N_INT_BITS-1)) { |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
746 |
if (! (bits >> (N_INT_BITS - 1 - count))) { |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
747 |
RETURN ( __MKSMALLINT(bits << count) ); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
748 |
} |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
749 |
/* |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
750 |
* so, there is an overflow ... |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
751 |
* handle it as largeInteger |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
752 |
*/ |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
753 |
/* FALL THROUGH */ |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
754 |
} |
95 | 755 |
#endif |
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
756 |
} else { |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
757 |
/* |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
758 |
* right shifts cannot overflow |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
759 |
*/ |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
760 |
if (count < 0) { |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
761 |
/* |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
762 |
* some machines ignore shifts bigger than |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
763 |
* the number of bits in an int ... |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
764 |
*/ |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
765 |
if (count < (-N_INT_BITS-1)) |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
766 |
RETURN (__MKSMALLINT(0)); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
767 |
RETURN ( __MKSMALLINT(bits >> -count) ); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
768 |
} |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
769 |
RETURN (self ); |
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
770 |
} |
1 | 771 |
} |
85 | 772 |
%}. |
773 |
(shiftCount isMemberOf:SmallInteger) ifTrue:[ |
|
1208
f4db36c78a6f
oops - shifting 0 by 32 did not work
Claus Gittinger <cg@exept.de>
parents:
1199
diff
changeset
|
774 |
^ (LargeInteger value:self) bitShift:shiftCount |
85 | 775 |
]. |
1 | 776 |
^ self bitShift:(shiftCount coerce:1) |
777 |
! |
|
778 |
||
701 | 779 |
bitTest:aMask |
780 |
"return true, if any bit from aMask is set in the receiver" |
|
1 | 781 |
|
782 |
%{ /* NOCONTEXT */ |
|
783 |
||
701 | 784 |
/* and all bits except tag */ |
785 |
if (__isSmallInteger(aMask)) { |
|
786 |
RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false ); |
|
1 | 787 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
788 |
%}. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
789 |
^ self retry:#bitTest: coercing:aMask |
1 | 790 |
! |
791 |
||
792 |
bitXor:anInteger |
|
13 | 793 |
"return the bitwise-exclusive-or of the receiver and the argument, anInteger" |
1 | 794 |
|
795 |
%{ /* NOCONTEXT */ |
|
796 |
||
797 |
/* xoring the tags turns it off - or it in again */ |
|
252 | 798 |
if (__isSmallInteger(anInteger)) { |
214 | 799 |
RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) ); |
1 | 800 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
801 |
%}. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
802 |
^ self retry:#bitXor: coercing:anInteger |
1 | 803 |
! |
804 |
||
701 | 805 |
highBit |
806 |
"return the bitIndex of the highest bit set. The returned bitIndex |
|
807 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
1 | 808 |
|
809 |
%{ /* NOCONTEXT */ |
|
810 |
||
701 | 811 |
INT mask, index, bits; |
812 |
||
1133 | 813 |
bits = __intVal(self); |
701 | 814 |
if (bits == 0) { |
1133 | 815 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 816 |
} |
817 |
#ifdef alpha |
|
818 |
mask = 0x2000000000000000; |
|
819 |
index = 62; |
|
820 |
#else |
|
821 |
mask = 0x20000000; |
|
822 |
index = 30; |
|
823 |
#endif |
|
824 |
while (index) { |
|
825 |
if (bits & mask) break; |
|
826 |
mask = mask >> 1; |
|
827 |
index--; |
|
1 | 828 |
} |
1133 | 829 |
RETURN ( __MKSMALLINT(index) ); |
1 | 830 |
%} |
701 | 831 |
"2r000100 highBit" |
832 |
"2r010100 highBit" |
|
833 |
"2r000001 highBit" |
|
834 |
"0 highBit" |
|
835 |
"SmallInteger maxVal highBit" |
|
836 |
! |
|
837 |
||
838 |
lowBit |
|
839 |
"return the bitIndex of the lowest bit set. The returned bitIndex |
|
840 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
841 |
||
842 |
%{ /* NOCONTEXT */ |
|
843 |
||
844 |
INT mask, index, bits; |
|
845 |
||
1133 | 846 |
bits = __intVal(self); |
701 | 847 |
if (bits == 0) { |
1133 | 848 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 849 |
} |
850 |
mask = 1; |
|
851 |
index = 1; |
|
852 |
#ifdef alpha |
|
853 |
while (index != 63) { |
|
854 |
#else |
|
855 |
while (index != 31) { |
|
856 |
#endif |
|
857 |
if (bits & mask) { |
|
1133 | 858 |
RETURN ( __MKSMALLINT(index) ); |
701 | 859 |
} |
860 |
mask = mask << 1; |
|
861 |
index++; |
|
862 |
} |
|
1133 | 863 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 864 |
%} |
865 |
"2r000100 lowBit" |
|
866 |
"2r010010 lowBit" |
|
867 |
"2r100001 lowBit" |
|
868 |
"0 lowBit" |
|
869 |
! |
|
870 |
||
871 |
noMask:anInteger |
|
872 |
"return true if no 1-bit in anInteger is 1 in the receiver" |
|
873 |
||
874 |
^ (self bitAnd:anInteger) == 0 |
|
875 |
||
876 |
"2r00001111 noMask:2r00000001" |
|
877 |
"2r00001111 noMask:2r11110000" |
|
1 | 878 |
! ! |
879 |
||
880 |
!SmallInteger methodsFor:'byte access'! |
|
881 |
||
882 |
digitAt:index |
|
883 |
"return 8 bits of value, starting at byte index" |
|
884 |
||
885 |
%{ /* NOCONTEXT */ |
|
886 |
||
357 | 887 |
REGISTER INT val; |
888 |
INT idx; |
|
1 | 889 |
|
252 | 890 |
if (__isSmallInteger(index)) { |
1133 | 891 |
val = __intVal(self); |
214 | 892 |
if (val < 0) |
893 |
val = -val; |
|
1133 | 894 |
switch (idx = __intVal(index)) { |
214 | 895 |
case 1: |
357 | 896 |
break; |
214 | 897 |
case 2: |
357 | 898 |
val = (val >> 8); |
899 |
break; |
|
214 | 900 |
case 3: |
357 | 901 |
val = (val >> 16); |
902 |
break; |
|
214 | 903 |
case 4: |
357 | 904 |
val = (val >> 24); |
905 |
break; |
|
1 | 906 |
#ifdef alpha |
214 | 907 |
case 5: |
357 | 908 |
val = (val >> 32); |
909 |
break; |
|
214 | 910 |
case 6: |
357 | 911 |
val = (val >> 40); |
912 |
break; |
|
214 | 913 |
case 7: |
357 | 914 |
val = (val >> 48); |
915 |
break; |
|
214 | 916 |
case 8: |
357 | 917 |
val = (val >> 56); |
918 |
break; |
|
1 | 919 |
#endif |
357 | 920 |
default: |
921 |
if (idx < 1) |
|
922 |
goto bad; /* sorry */ |
|
923 |
val = 0; |
|
924 |
break; |
|
214 | 925 |
} |
1133 | 926 |
RETURN ( __MKSMALLINT( val & 0xFF) ); |
1 | 927 |
} |
357 | 928 |
bad: ; |
77 | 929 |
%}. |
930 |
index > 0 ifFalse:[ |
|
357 | 931 |
" |
932 |
index less than 1 - not allowed |
|
933 |
" |
|
934 |
^ self primitiveFailed |
|
77 | 935 |
]. |
936 |
^ 0 |
|
62 | 937 |
|
357 | 938 |
" |
939 |
(16r12345678 digitAt:1) printStringRadix:16 |
|
940 |
(16r12345678 digitAt:3) printStringRadix:16 |
|
941 |
(16r12345678 digitAt:15) printStringRadix:16 |
|
942 |
(16r12345678 digitAt:0) printStringRadix:16 |
|
943 |
(16r12345678 digitAt:-10) printStringRadix:16 |
|
944 |
" |
|
701 | 945 |
! |
946 |
||
947 |
digitLength |
|
948 |
"return the number bytes used by this Integer" |
|
949 |
||
950 |
^ self abs highBit - 1 // 8 + 1 |
|
1 | 951 |
! ! |
952 |
||
701 | 953 |
!SmallInteger methodsFor:'catching messages'! |
1 | 954 |
|
701 | 955 |
basicAt:index |
956 |
"catch indexed access - report an error |
|
957 |
defined here since basicAt: in Object ommits the SmallInteger check." |
|
958 |
||
959 |
self notIndexed |
|
1 | 960 |
! |
961 |
||
701 | 962 |
basicAt:index put:anObject |
963 |
"catch indexed access - report an error |
|
964 |
defined here since basicAt:put: in Object ommits the SmallInteger check." |
|
965 |
||
966 |
self notIndexed |
|
967 |
! |
|
1 | 968 |
|
701 | 969 |
basicSize |
970 |
"return the number of indexed instvars - SmallIntegers have none. |
|
971 |
Defined here since basicSize in Object ommits the SmallInteger check." |
|
972 |
||
973 |
^ 0 |
|
974 |
! |
|
975 |
||
976 |
size |
|
977 |
"return the number of indexed instvars - SmallIntegers have none." |
|
978 |
||
979 |
^ 0 |
|
1 | 980 |
! ! |
981 |
||
982 |
!SmallInteger methodsFor:'coercing and converting'! |
|
983 |
||
701 | 984 |
asCharacter |
985 |
"Return a character with the receiver as ascii value" |
|
41 | 986 |
|
701 | 987 |
^ Character value:self |
1 | 988 |
! |
989 |
||
990 |
asFloat |
|
991 |
"return a Float with same value as receiver" |
|
992 |
||
993 |
%{ /* NOCONTEXT */ |
|
994 |
||
995 |
OBJ newFloat; |
|
1133 | 996 |
double dVal = (double)__intVal(self); |
1 | 997 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
998 |
__qMKFLOAT(newFloat, dVal); |
1 | 999 |
RETURN ( newFloat ); |
1000 |
%} |
|
1001 |
! |
|
1002 |
||
1003 |
asLargeInteger |
|
1004 |
"return a LargeInteger with same value as receiver" |
|
1005 |
||
1006 |
^ LargeInteger value:self |
|
1007 |
! |
|
1008 |
||
1199 | 1009 |
asShortFloat |
1010 |
"return a ShortFloat with same value as receiver" |
|
1011 |
||
1012 |
%{ /* NOCONTEXT */ |
|
1013 |
||
1014 |
OBJ dummy = @global(ShortFloat); |
|
1015 |
OBJ newFloat; |
|
1016 |
float fVal = (float)__intVal(self); |
|
1017 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1018 |
__qMKSFLOAT(newFloat, fVal); |
1199 | 1019 |
RETURN ( newFloat ); |
1020 |
%} |
|
1021 |
! |
|
1022 |
||
701 | 1023 |
coerce:aNumber |
1024 |
"return aNumber converted into receivers type" |
|
1025 |
||
1026 |
^ aNumber asInteger |
|
1027 |
! |
|
1028 |
||
1029 |
generality |
|
1030 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
1031 |
||
1032 |
^ 20 |
|
1336 | 1033 |
! |
1034 |
||
1035 |
signExtendedByteValue |
|
1036 |
"return a smallInteger from sign-extending the 8'th bit. |
|
1037 |
May be useful for communication interfaces" |
|
1038 |
||
1039 |
%{ /* NOCONTEXT */ |
|
1040 |
int i = __intVal(self); |
|
1041 |
||
1042 |
if (i & 0x80) { |
|
1043 |
i = i | 0x7FFFFF00; |
|
1044 |
} else { |
|
1045 |
i = i & 0x7F; |
|
1046 |
} |
|
1047 |
||
1048 |
RETURN (__MKSMALLINT(i)); |
|
1049 |
%} |
|
1050 |
||
1051 |
" |
|
1052 |
16rFF signExtendedByteValue |
|
1053 |
16r7F signExtendedByteValue |
|
1054 |
" |
|
1055 |
! |
|
1056 |
||
1057 |
signExtendedShortValue |
|
1058 |
"return a smallInteger from sign-extending the 16'th bit. |
|
1059 |
May be useful for communication interfaces" |
|
1060 |
||
1061 |
%{ /* NOCONTEXT */ |
|
1062 |
int i = __intVal(self); |
|
1063 |
||
1064 |
if (i & 0x8000) { |
|
1065 |
i = i | 0x7FFF0000; |
|
1066 |
} else { |
|
1067 |
i = i & 0x7FFF; |
|
1068 |
} |
|
1069 |
||
1070 |
RETURN (__MKSMALLINT(i)); |
|
1071 |
%} |
|
1072 |
||
1073 |
" |
|
1074 |
16rFFFF signExtendedShortValue |
|
1075 |
16r7FFF signExtendedShortValue |
|
1076 |
" |
|
701 | 1077 |
! ! |
1078 |
||
1079 |
!SmallInteger methodsFor:'comparing'! |
|
1080 |
||
1081 |
< aNumber |
|
1082 |
"return true, if the argument is greater than the receiver" |
|
1083 |
||
1084 |
%{ /* NOCONTEXT */ |
|
1085 |
||
1086 |
if (__isSmallInteger(aNumber)) { |
|
1087 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1088 |
RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false ); |
701 | 1089 |
#else |
1090 |
/* tag bit does not change ordering */ |
|
1091 |
RETURN ( ((INT)self < (INT)aNumber) ? true : false ); |
|
1092 |
#endif |
|
1093 |
} |
|
1094 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1095 |
RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false ); |
701 | 1096 |
} |
1097 |
%} |
|
1098 |
. |
|
1099 |
^ aNumber lessFromInteger:self |
|
1100 |
"^ self retry:#< coercing:aNumber" |
|
1101 |
! |
|
1102 |
||
1103 |
<= aNumber |
|
1104 |
"return true, if the argument is greater or equal" |
|
1105 |
||
1106 |
%{ /* NOCONTEXT */ |
|
1107 |
||
1108 |
if (__isSmallInteger(aNumber)) { |
|
1109 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1110 |
RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false ); |
701 | 1111 |
#else |
1112 |
/* tag bit does not change ordering */ |
|
1113 |
RETURN ( ((INT)self <= (INT)aNumber) ? true : false ); |
|
1114 |
#endif |
|
1115 |
} |
|
1116 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1117 |
RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false ); |
701 | 1118 |
} |
1119 |
%} |
|
1120 |
. |
|
1121 |
^ self retry:#<= coercing:aNumber |
|
1122 |
! |
|
1123 |
||
1124 |
= aNumber |
|
1125 |
"return true, if the arguments value is equal to mine" |
|
1126 |
||
1127 |
%{ /* NOCONTEXT */ |
|
1128 |
||
1129 |
if (aNumber == self) { |
|
1130 |
RETURN ( true ); |
|
1131 |
} |
|
1132 |
if (! __isNonNilObject(aNumber)) { |
|
1133 |
/* a smallint or nil */ |
|
1134 |
RETURN ( false ); |
|
1135 |
} |
|
1136 |
||
1137 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1138 |
RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false ); |
701 | 1139 |
} |
1140 |
%} |
|
1141 |
. |
|
1142 |
aNumber respondsToArithmetic ifFalse:[^ false]. |
|
1143 |
^ self retry:#= coercing:aNumber |
|
1144 |
! |
|
1145 |
||
1146 |
> aNumber |
|
1147 |
"return true, if the argument is less than the receiver" |
|
1148 |
||
1149 |
%{ /* NOCONTEXT */ |
|
1150 |
||
1151 |
if (__isSmallInteger(aNumber)) { |
|
1152 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1153 |
RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false ); |
701 | 1154 |
#else |
1155 |
/* tag bit does not change ordering */ |
|
1156 |
RETURN ( ((INT)self > (INT)aNumber) ? true : false ); |
|
1157 |
#endif |
|
1158 |
} |
|
1159 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1160 |
RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false ); |
701 | 1161 |
} |
1162 |
%} |
|
1163 |
. |
|
1164 |
^ self retry:#> coercing:aNumber |
|
1165 |
! |
|
1166 |
||
1167 |
>= aNumber |
|
1168 |
"return true, if the argument is less or equal" |
|
1169 |
||
1170 |
%{ /* NOCONTEXT */ |
|
1171 |
||
1172 |
if (__isSmallInteger(aNumber)) { |
|
1173 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1174 |
RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false ); |
701 | 1175 |
#else |
1176 |
/* tag bit does not change ordering */ |
|
1177 |
RETURN ( ((INT)self >= (INT)aNumber) ? true : false ); |
|
1178 |
#endif |
|
1179 |
} |
|
1180 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1181 |
RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false ); |
701 | 1182 |
} |
1183 |
%} |
|
1184 |
. |
|
1185 |
^ self retry:#>= coercing:aNumber |
|
1186 |
! |
|
1 | 1187 |
|
701 | 1188 |
hash |
1189 |
"return an integer useful for hashing on value" |
|
1190 |
||
1191 |
self >= 0 ifTrue:[^ self]. |
|
1192 |
^ self negated |
|
1193 |
! |
|
1194 |
||
1195 |
identityHash |
|
1196 |
"return an integer useful for hashing on identity" |
|
1197 |
||
1198 |
self >= 0 ifTrue:[^ self]. |
|
1199 |
^ self negated |
|
1200 |
! |
|
1201 |
||
1202 |
max:aNumber |
|
1203 |
"return the receiver or the argument, whichever is greater" |
|
1204 |
||
1205 |
%{ /* NOCONTEXT */ |
|
1206 |
||
1207 |
if (__isSmallInteger(aNumber)) { |
|
1208 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1209 |
if (__intVal(self) > __intVal(aNumber)) { |
701 | 1210 |
#else |
1211 |
/* tag bit does not change ordering */ |
|
1212 |
if ((INT)(self) > (INT)(aNumber)) { |
|
1213 |
#endif |
|
1214 |
RETURN ( self ); |
|
1215 |
} |
|
1216 |
RETURN ( aNumber ); |
|
1217 |
} |
|
1218 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1219 |
if ( (double)__intVal(self) > __floatVal(aNumber) ) { |
701 | 1220 |
RETURN ( self ); |
1221 |
} |
|
1222 |
RETURN ( aNumber ); |
|
1223 |
} |
|
1224 |
%} |
|
1225 |
. |
|
1226 |
(self > aNumber) ifTrue:[^ self]. |
|
1227 |
^ aNumber |
|
1228 |
! |
|
1229 |
||
1230 |
min:aNumber |
|
1231 |
"return the receiver or the argument, whichever is smaller" |
|
1232 |
||
1233 |
%{ /* NOCONTEXT */ |
|
1234 |
||
1235 |
if (__isSmallInteger(aNumber)) { |
|
1236 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1237 |
if (__intVal(self) < __intVal(aNumber)) { |
701 | 1238 |
#else |
1239 |
/* tag bit does not change ordering */ |
|
1240 |
if ((INT)(self) < (INT)(aNumber)) { |
|
1241 |
#endif |
|
1242 |
RETURN ( self ); |
|
1243 |
} |
|
1244 |
RETURN ( aNumber ); |
|
1245 |
} |
|
1246 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1247 |
if ( (double)__intVal(self) < __floatVal(aNumber) ) { |
701 | 1248 |
RETURN ( self ); |
1249 |
} |
|
1250 |
RETURN ( aNumber ); |
|
1251 |
} |
|
1252 |
%} |
|
1253 |
. |
|
1254 |
(self < aNumber) ifTrue:[^ self]. |
|
1255 |
^ aNumber |
|
1256 |
! |
|
1257 |
||
1258 |
~= aNumber |
|
1259 |
"return true, if the arguments value is not equal to mine" |
|
1260 |
||
1261 |
%{ /* NOCONTEXT */ |
|
1262 |
||
1263 |
if (aNumber == self) { |
|
1264 |
RETURN ( false ); |
|
1265 |
} |
|
1266 |
if (! __isNonNilObject(aNumber)) { |
|
1267 |
/* a smallint or nil */ |
|
1268 |
RETURN ( true ); |
|
1269 |
} |
|
1270 |
||
1271 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1272 |
RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? false : true ); |
701 | 1273 |
} |
1274 |
%} |
|
1275 |
. |
|
1276 |
aNumber respondsToArithmetic ifFalse:[^ true]. |
|
1277 |
^ self retry:#~= coercing:aNumber |
|
1278 |
! ! |
|
1279 |
||
1280 |
!SmallInteger methodsFor:'copying'! |
|
1281 |
||
1282 |
deepCopy |
|
1283 |
"return a deep copy of myself |
|
1284 |
- reimplemented here since smallintegers are unique" |
|
1285 |
||
1286 |
^ self |
|
1287 |
! |
|
1288 |
||
1289 |
deepCopyUsing:aDictionary |
|
1290 |
"return a deep copy of myself |
|
1291 |
- reimplemented here since smallintegers are unique" |
|
1292 |
||
1293 |
^ self |
|
1294 |
! |
|
1295 |
||
1296 |
shallowCopy |
|
1297 |
"return a shallow copy of myself |
|
1298 |
- reimplemented here since smallintegers are unique" |
|
1299 |
||
1300 |
^ self |
|
1301 |
! |
|
1302 |
||
1303 |
simpleDeepCopy |
|
1304 |
"return a deep copy of myself |
|
1305 |
- reimplemented here since smallintegers are unique" |
|
1306 |
||
1307 |
^ self |
|
1 | 1308 |
! ! |
1309 |
||
214 | 1310 |
!SmallInteger methodsFor:'iteration'! |
1 | 1311 |
|
1312 |
timesRepeat:aBlock |
|
357 | 1313 |
"evaluate the argument, aBlock self times. |
1314 |
Reimplemented as primitive for speed" |
|
1 | 1315 |
|
357 | 1316 |
|home| |
1317 |
%{ |
|
1318 |
REGISTER INT tmp; |
|
1319 |
REGISTER OBJFUNC code; |
|
1320 |
static struct inlineCache blockVal = __ILC0(0); |
|
1321 |
REGISTER OBJ rHome; |
|
1 | 1322 |
|
357 | 1323 |
tmp = __intVal(self); |
1324 |
if (tmp > 0) { |
|
1325 |
if (__isBlockLike(aBlock) |
|
1133 | 1326 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(0))) { |
1327 |
if ((code = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
357 | 1328 |
#ifdef NEW_BLOCK_CALL |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1329 |
do { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1330 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1331 |
(*code)(aBlock); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1332 |
} while(--tmp); |
394 | 1333 |
RETURN (self); |
357 | 1334 |
#else /* old BLOCK_CALL */ |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1335 |
/* |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1336 |
* arg is a compiled block - |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1337 |
* directly call it without going through "Block-value" |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1338 |
*/ |
1133 | 1339 |
rHome = __BlockInstPtr(aBlock)->b_home; |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1340 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
394 | 1341 |
/* |
1342 |
* home will not move - keep in in a register |
|
1343 |
*/ |
|
1344 |
# if defined(UNROLL_LOOPS) |
|
1345 |
while (tmp > 4) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1346 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1347 |
(*code)(rHome); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1348 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1349 |
(*code)(rHome); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1350 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1351 |
(*code)(rHome); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1352 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1353 |
(*code)(rHome); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1354 |
tmp -= 4; |
394 | 1355 |
} |
1356 |
# endif |
|
1357 |
do { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1358 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1359 |
(*code)(rHome); |
394 | 1360 |
} while(--tmp); |
1361 |
RETURN (self); |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1362 |
} |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1363 |
home = rHome; |
357 | 1364 |
do { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1365 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1366 |
(*code)(home); |
357 | 1367 |
} while(--tmp); |
394 | 1368 |
RETURN (self); |
357 | 1369 |
#endif /* NEW_BLOCK_CALL */ |
394 | 1370 |
} |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1371 |
|
1133 | 1372 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
394 | 1373 |
/* |
1374 |
* an interpreted block |
|
1375 |
*/ |
|
1133 | 1376 |
home = __BlockInstPtr(aBlock)->b_home; |
400 | 1377 |
#if defined(mips) || defined(rs6000) |
1378 |
# define INDIRECT_CALL_IS_FASTER |
|
1379 |
#endif |
|
1380 |
||
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1381 |
#ifdef INDIRECT_CALL_IS_FASTER |
400 | 1382 |
code = __interpret; |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1383 |
# define INTERPRET (*code) |
400 | 1384 |
#else |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1385 |
# define INTERPRET __interpret |
400 | 1386 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1387 |
|
400 | 1388 |
#ifdef NEW_BLOCK_CALL |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1389 |
# define HOME nil |
400 | 1390 |
#else |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1391 |
# define HOME home |
400 | 1392 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1393 |
|
400 | 1394 |
#if defined(UNROLL_LOOPS) |
1395 |
while (tmp > 4) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1396 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1397 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil, nil); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1398 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1399 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil, nil); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1400 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1401 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil, nil); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1402 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1403 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil, nil); |
400 | 1404 |
tmp -= 4; |
1405 |
} |
|
1406 |
#endif |
|
394 | 1407 |
do { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1408 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1409 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil, nil); |
394 | 1410 |
} while(--tmp); |
1411 |
RETURN (self); |
|
1412 |
} |
|
357 | 1413 |
} |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1414 |
|
394 | 1415 |
/* |
1416 |
* arg is something else - call it with value" |
|
1417 |
*/ |
|
1418 |
do { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1419 |
if (InterruptPending != nil) __interrupt__(CONARG); |
394 | 1420 |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1421 |
(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal); |
394 | 1422 |
} while(--tmp); |
357 | 1423 |
} |
400 | 1424 |
#undef INTERPRET |
1425 |
#undef HOME |
|
357 | 1426 |
%} |
1427 |
||
1428 |
"/ |count "{ Class: SmallInteger }" | |
|
1429 |
"/ |
|
1430 |
"/ count := self. |
|
1431 |
"/ [count > 0] whileTrue:[ |
|
1432 |
"/ aBlock value. |
|
1433 |
"/ count := count - 1 |
|
1434 |
"/ ] |
|
1 | 1435 |
! |
1436 |
||
701 | 1437 |
to:stop by:incr do:aBlock |
1438 |
"reimplemented as primitive for speed" |
|
1439 |
||
1440 |
|home| |
|
1441 |
%{ |
|
1442 |
REGISTER INT tmp, step; |
|
1443 |
REGISTER INT final; |
|
1444 |
REGISTER OBJFUNC code; |
|
1445 |
static struct inlineCache blockVal = __ILC1(0); |
|
1446 |
REGISTER OBJ rHome; |
|
1447 |
||
1448 |
if (__bothSmallInteger(incr, stop)) { |
|
1133 | 1449 |
tmp = __intVal(self); |
1450 |
final = __intVal(stop); |
|
1451 |
step = __intVal(incr); |
|
701 | 1452 |
if (__isBlockLike(aBlock) |
1133 | 1453 |
&& ((code = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
1454 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
|
701 | 1455 |
#ifdef NEW_BLOCK_CALL |
1456 |
if (step < 0) { |
|
1457 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1458 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1459 |
(*code)(aBlock, __MKSMALLINT(tmp)); |
701 | 1460 |
tmp += step; |
1461 |
} |
|
1462 |
} else { |
|
1463 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1464 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1465 |
(*code)(aBlock, __MKSMALLINT(tmp)); |
701 | 1466 |
tmp += step; |
1467 |
} |
|
1468 |
} |
|
1469 |
#else |
|
1470 |
/* |
|
1471 |
* arg is a compiled block - |
|
1472 |
* directly call it without going through "Block-value" |
|
1473 |
*/ |
|
1133 | 1474 |
home = __BlockInstPtr(aBlock)->b_home; |
701 | 1475 |
rHome = home; |
1476 |
if (step < 0) { |
|
1477 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
|
1478 |
/* |
|
1479 |
* home is on stack - will not move |
|
1480 |
*/ |
|
1481 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1482 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1483 |
(*code)(rHome, __MKSMALLINT(tmp)); |
701 | 1484 |
tmp += step; |
1485 |
} |
|
1486 |
} else { |
|
1487 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1488 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1489 |
(*code)(home, __MKSMALLINT(tmp)); |
701 | 1490 |
tmp += step; |
1491 |
} |
|
1492 |
} |
|
1493 |
} else { |
|
1494 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
|
1495 |
/* |
|
1496 |
* home is on stack - will not move |
|
1497 |
*/ |
|
1498 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1499 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1500 |
(*code)(rHome, __MKSMALLINT(tmp)); |
701 | 1501 |
tmp += step; |
1502 |
} |
|
1503 |
} else { |
|
1504 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1505 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1506 |
(*code)(home, __MKSMALLINT(tmp)); |
701 | 1507 |
tmp += step; |
1508 |
} |
|
1509 |
} |
|
1510 |
} |
|
1511 |
#endif |
|
1512 |
} else { |
|
1513 |
/* |
|
1514 |
* arg is something else - call it with value" |
|
1515 |
*/ |
|
1516 |
if (step < 0) { |
|
1517 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1518 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1519 |
|
1520 |
(*blockVal.ilc_func)(aBlock, |
|
1521 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1522 |
nil, &blockVal, |
1133 | 1523 |
__MKSMALLINT(tmp)); |
701 | 1524 |
tmp += step; |
1525 |
} |
|
1526 |
} else { |
|
1527 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1528 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1529 |
|
1530 |
(*blockVal.ilc_func)(aBlock, |
|
1531 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1532 |
nil, &blockVal, |
1133 | 1533 |
__MKSMALLINT(tmp)); |
701 | 1534 |
tmp += step; |
1535 |
} |
|
1536 |
} |
|
1537 |
} |
|
1538 |
RETURN ( self ); |
|
1539 |
} |
|
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1540 |
%}. |
701 | 1541 |
^ super to:stop by:incr do:aBlock |
1542 |
||
1543 |
" |
|
1544 |
1 to:10 by:3 do:[:i | i printNewline] |
|
1545 |
" |
|
1546 |
! |
|
1547 |
||
1 | 1548 |
to:stop do:aBlock |
62 | 1549 |
"evaluate aBlock for every integer between (and including) the receiver |
1550 |
and the argument, stop. |
|
357 | 1551 |
Reimplemented as primitive for speed" |
1 | 1552 |
|
77 | 1553 |
|home| |
1 | 1554 |
%{ |
1555 |
REGISTER INT tmp; |
|
1556 |
INT final; |
|
1557 |
REGISTER OBJFUNC code; |
|
216 | 1558 |
static struct inlineCache blockVal = __ILC1(0); |
2 | 1559 |
REGISTER OBJ rHome; |
1 | 1560 |
|
252 | 1561 |
if (__isSmallInteger(stop)) { |
1133 | 1562 |
tmp = __intVal(self); |
1563 |
final = __intVal(stop); |
|
214 | 1564 |
if (__isBlockLike(aBlock) |
1133 | 1565 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
1566 |
if ((code = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
13 | 1567 |
#ifdef NEW_BLOCK_CALL |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1568 |
while (tmp <= final) { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1569 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1570 |
(*code)(aBlock, __MKSMALLINT(tmp)); |
400 | 1571 |
tmp++; |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1572 |
} |
77 | 1573 |
#else /* old BLOCK_CALL */ |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1574 |
/* |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1575 |
* arg is a compiled block - |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1576 |
* directly call it without going through "Block-value" |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1577 |
*/ |
1133 | 1578 |
rHome = __BlockInstPtr(aBlock)->b_home; |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1579 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
400 | 1580 |
/* |
1581 |
* home will not move - keep in in a register |
|
1582 |
* since this is also the most common case, |
|
1583 |
* its worth trading a bit memory for speed here ... |
|
1584 |
*/ |
|
394 | 1585 |
# if defined(UNROLL_LOOPS) |
400 | 1586 |
{ |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1587 |
int t4; |
370 | 1588 |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1589 |
while ((t4 = tmp+4) < final) { |
1133 | 1590 |
OBJ idx = __MKSMALLINT(tmp); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1591 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1592 |
(*code)(rHome, idx); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1593 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1594 |
(*code)(rHome, _ADD_INT(idx, 1)); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1595 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1596 |
(*code)(rHome, _ADD_INT(idx,2)); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1597 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1598 |
(*code)(rHome, _ADD_INT(idx,3)); |
400 | 1599 |
tmp = t4; |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1600 |
} |
400 | 1601 |
} |
1602 |
# endif |
|
1603 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1604 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1605 |
(*code)(rHome, __MKSMALLINT(tmp)); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1606 |
tmp++; |
400 | 1607 |
} |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1608 |
} else { |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1609 |
home = rHome; |
400 | 1610 |
while (tmp <= final) { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1611 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1612 |
(*code)(home, __MKSMALLINT(tmp)); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1613 |
tmp++; |
370 | 1614 |
} |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1615 |
} |
400 | 1616 |
RETURN (self); |
1617 |
#endif /* NEW_BLOCK_CALL */ |
|
1618 |
} |
|
1133 | 1619 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
400 | 1620 |
/* |
1621 |
* an interpreted block |
|
1622 |
*/ |
|
1133 | 1623 |
home = __BlockInstPtr(aBlock)->b_home; |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1624 |
#ifdef INDIRECT_CALL_IS_FASTER |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1625 |
code = __interpret; |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1626 |
# define INTERPRET (*code) |
400 | 1627 |
#else |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1628 |
# define INTERPRET __interpret |
400 | 1629 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1630 |
|
400 | 1631 |
#ifdef NEW_BLOCK_CALL |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1632 |
# define HOME nil |
400 | 1633 |
#else |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1634 |
# define HOME home |
400 | 1635 |
#endif |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1636 |
while (tmp <= final) { |
400 | 1637 |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1638 |
if (InterruptPending != nil) __interrupt__(CONARG); |
400 | 1639 |
#ifdef PASS_ARG_POINTER |
1640 |
{ |
|
1641 |
OBJ idx; |
|
1642 |
idx = __MKSMALLINT(tmp); |
|
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1643 |
INTERPRET(aBlock, 1, nil, HOME COMMA_SND, nil, nil, &idx); |
400 | 1644 |
} |
1645 |
#else |
|
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1646 |
INTERPRET(aBlock, 1, nil, HOME COMMA_SND, nil, nil, __MKSMALLINT(tmp)); |
400 | 1647 |
#endif |
214 | 1648 |
tmp++; |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1649 |
} |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1650 |
RETURN (self); |
214 | 1651 |
} |
400 | 1652 |
} |
1653 |
/* |
|
1654 |
* arg is something else - call it with value" |
|
1655 |
*/ |
|
1656 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1657 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1 | 1658 |
|
400 | 1659 |
(*blockVal.ilc_func)(aBlock, |
214 | 1660 |
@symbol(value:), |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1661 |
nil, &blockVal, |
1133 | 1662 |
__MKSMALLINT(tmp)); |
400 | 1663 |
tmp++; |
214 | 1664 |
} |
1665 |
RETURN ( self ); |
|
1 | 1666 |
} |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1667 |
#undef INTERPRET |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1668 |
#undef HOME |
400 | 1669 |
%}. |
1670 |
"/ |
|
1671 |
"/ arrive here if stop is not a smallInteger |
|
1672 |
"/ |
|
1673 |
||
62 | 1674 |
^ super to:stop do:aBlock |
1675 |
||
216 | 1676 |
" |
1677 |
1 to:10 do:[:i | i printNewline] |
|
1678 |
" |
|
701 | 1679 |
! ! |
1 | 1680 |
|
701 | 1681 |
!SmallInteger methodsFor:'misc math'! |
1 | 1682 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1683 |
divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1684 |
"return an array filled with self // aNumber and |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1685 |
self \\ aNumber. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1686 |
The result is only defined for positive receiver and |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1687 |
argument." |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1688 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1689 |
%{ /* NOCONTEXT */ |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1690 |
INT val, div, mod, mySelf; |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1691 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1692 |
if (__isSmallInteger(aNumber)) { |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1693 |
val = __intVal(aNumber); |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1694 |
if (val != 0) { |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1695 |
mySelf = __intVal(self); |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1696 |
div = mySelf / val; |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1697 |
mod = mySelf % val; |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1698 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1699 |
RETURN (__ARRAY_WITH2( __MKSMALLINT(div), |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1700 |
__MKSMALLINT(mod))); |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1701 |
} |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1702 |
} |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1703 |
%}. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1704 |
^ super divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1705 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1706 |
" |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1707 |
10 // 3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1708 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1709 |
10 \\ 3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1710 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1711 |
10 divMod:3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1712 |
" |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1713 |
! |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
1714 |
|
701 | 1715 |
gcd:anInteger |
1716 |
"return the greatest common divisor (Euclid's algorithm). |
|
1717 |
This has been redefined here for more speed since due to the |
|
1718 |
use of gcd in Fraction code, it has become time-critical for |
|
1719 |
some code. (thanx to MessageTally)" |
|
1720 |
||
1721 |
%{ /* NOCONTEXT */ |
|
1 | 1722 |
|
701 | 1723 |
if (__isSmallInteger(anInteger)) { |
1889 | 1724 |
INT orgArg, ttt, selfInt, temp; |
701 | 1725 |
|
1889 | 1726 |
ttt = orgArg = __intVal(anInteger); |
1727 |
if (ttt) { |
|
1728 |
selfInt = __intVal(self); |
|
1729 |
while (ttt != 0) { |
|
1730 |
temp = selfInt % ttt; |
|
1731 |
selfInt = ttt; |
|
1732 |
ttt = temp; |
|
1733 |
} |
|
1734 |
/* |
|
1735 |
* since its not defined in what the sign of |
|
1736 |
* a modulu result is when the arg is negative, |
|
1737 |
* change it explicitely here ... |
|
1738 |
*/ |
|
1739 |
if (orgArg < 0) { |
|
1740 |
/* result should be negative */ |
|
1741 |
if (selfInt > 0) selfInt = -selfInt; |
|
1742 |
} else { |
|
1743 |
/* result should be positive */ |
|
1744 |
if (selfInt < 0) selfInt = -selfInt; |
|
1745 |
} |
|
1746 |
RETURN ( __MKSMALLINT(selfInt) ); |
|
1747 |
} |
|
1 | 1748 |
} |
1749 |
%} |
|
1750 |
. |
|
701 | 1751 |
^ super gcd:anInteger |
1752 |
! |
|
62 | 1753 |
|
701 | 1754 |
intlog10 |
1755 |
"return the truncation of log10 of the receiver - |
|
1756 |
stupid implementation; used to find out the number of digits needed |
|
1757 |
to print a number/and for conversion to a LargeInteger. |
|
1758 |
Implemented that way, to allow for tiny systems without a Float class |
|
1759 |
(i.e. without log)." |
|
2 | 1760 |
|
701 | 1761 |
self <= 0 ifTrue:[ |
1762 |
self error:'logarithm of negative integer' |
|
2 | 1763 |
]. |
701 | 1764 |
self < 10 ifTrue:[^ 1]. |
1765 |
self < 100 ifTrue:[^ 2]. |
|
1766 |
self < 1000 ifTrue:[^ 3]. |
|
1767 |
self < 10000 ifTrue:[^ 4]. |
|
1768 |
self < 100000 ifTrue:[^ 5]. |
|
1769 |
self < 1000000 ifTrue:[^ 6]. |
|
1770 |
self < 10000000 ifTrue:[^ 7]. |
|
1771 |
self < 100000000 ifTrue:[^ 8]. |
|
1772 |
self < 1000000000 ifTrue:[^ 9]. |
|
1773 |
^ 10 |
|
2 | 1774 |
! ! |
1775 |
||
701 | 1776 |
!SmallInteger methodsFor:'modulu arithmetic'! |
2 | 1777 |
|
701 | 1778 |
plus:aNumber |
1779 |
"return the sum of the receiver and the argument, as SmallInteger. |
|
1780 |
The argument must be another SmallInteger. |
|
1781 |
If the result overflows the smallInteger range, the value modulu the |
|
1782 |
smallInteger range is returned (i.e. the low bits of the sum). |
|
1783 |
This is of course not always correct, but some code does a modulu anyway |
|
1784 |
and can therefore speed things up by not going through LargeIntegers." |
|
41 | 1785 |
|
701 | 1786 |
%{ /* NOCONTEXT */ |
1787 |
||
1788 |
if (__isSmallInteger(aNumber)) { |
|
1133 | 1789 |
RETURN ( __MKSMALLINT((__intVal(self) + __intVal(aNumber)) & 0x7FFFFFFF) ); |
701 | 1790 |
} |
1791 |
%} |
|
1792 |
. |
|
1793 |
self primitiveFailed |
|
2 | 1794 |
! |
1795 |
||
701 | 1796 |
subtract:aNumber |
1797 |
"return the difference of the receiver and the argument, as SmallInteger. |
|
1798 |
The argument must be another SmallInteger. |
|
1799 |
If the result overflows the smallInteger range, the value modulu the |
|
1800 |
smallInteger range is returned (i.e. the low bits of the sum). |
|
1801 |
This is of course not always correct, but some code does a modulu anyway |
|
1802 |
and can therefore speed things up by not going through LargeIntegers." |
|
1803 |
||
1804 |
%{ /* NOCONTEXT */ |
|
2 | 1805 |
|
701 | 1806 |
if (__isSmallInteger(aNumber)) { |
1133 | 1807 |
RETURN ( __MKSMALLINT((__intVal(self) - __intVal(aNumber)) & 0x7FFFFFFF) ); |
701 | 1808 |
} |
1809 |
%} |
|
1810 |
. |
|
1811 |
self primitiveFailed |
|
1812 |
! |
|
1813 |
||
1814 |
times:aNumber |
|
1815 |
"return the product of the receiver and the argument, as SmallInteger. |
|
1816 |
The argument must be another SmallInteger. |
|
1817 |
If the result overflows the smallInteger range, the value modulu the |
|
1818 |
smallInteger range is returned (i.e. the low bits of the product). |
|
1819 |
This is of course not always correct, but some code does a modulu anyway |
|
1820 |
and can therefore speed things up by not going through LargeIntegers." |
|
1821 |
||
1822 |
%{ /* NOCONTEXT */ |
|
1823 |
||
1824 |
if (__isSmallInteger(aNumber)) { |
|
1133 | 1825 |
RETURN ( __MKSMALLINT((__intVal(self) * __intVal(aNumber)) & 0x7FFFFFFF) ); |
701 | 1826 |
} |
1827 |
%} |
|
1828 |
. |
|
1829 |
self primitiveFailed |
|
1 | 1830 |
! ! |
1831 |
||
1832 |
!SmallInteger methodsFor:'printing & storing'! |
|
1833 |
||
62 | 1834 |
printOn:aStream |
68 | 1835 |
"append my printstring (base 10) to aStream." |
62 | 1836 |
|
1837 |
aStream nextPutAll:(self printString) |
|
1838 |
! |
|
1839 |
||
701 | 1840 |
printOn:aStream base:radix |
1841 |
"append my printstring in any number base to aStream. |
|
1842 |
The radix argument should be between 2 and 36." |
|
1843 |
||
1844 |
aStream nextPutAll:(self printStringRadix:radix) |
|
1845 |
! |
|
1846 |
||
1 | 1847 |
printString |
1848 |
"return my printstring (base 10)" |
|
1849 |
||
68 | 1850 |
"since printf knows pretty good how to do this, |
1851 |
here is an exception to the rule of basing printString |
|
1852 |
upon the printOn: method." |
|
1853 |
||
1 | 1854 |
%{ /* NOCONTEXT */ |
1855 |
||
1856 |
char buffer[30]; |
|
1857 |
OBJ newString; |
|
369 | 1858 |
/* |
1859 |
* actually only needed on sparc: since thisContext is |
|
1860 |
* in a global register, which gets destroyed by printf, |
|
1861 |
* manually save it here - very stupid ... |
|
1862 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1863 |
__BEGIN_PROTECT_REGISTERS__ |
1 | 1864 |
|
1133 | 1865 |
sprintf(buffer, "%d", __intVal(self)); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1866 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1867 |
__END_PROTECT_REGISTERS__ |
369 | 1868 |
|
1133 | 1869 |
newString = __MKSTRING(buffer COMMA_SND); |
282 | 1870 |
if (newString != nil) { |
305 | 1871 |
RETURN (newString); |
282 | 1872 |
} |
1873 |
%}. |
|
1874 |
^ super printString |
|
1 | 1875 |
! |
1876 |
||
1877 |
printStringRadix:radix |
|
62 | 1878 |
"return my printstring (optimized for bases 16, 10 and 8)" |
1 | 1879 |
|
1880 |
%{ /* NOCONTEXT */ |
|
1881 |
||
1882 |
char *format = (char *)0; |
|
1883 |
char buffer[30]; |
|
1884 |
OBJ newString; |
|
1885 |
||
252 | 1886 |
if (__isSmallInteger(radix)) { |
1133 | 1887 |
switch (__intVal(radix)) { |
214 | 1888 |
case 10: |
1889 |
format = "%d"; |
|
1890 |
break; |
|
1891 |
case 16: |
|
1892 |
format = "%x"; |
|
1893 |
break; |
|
1894 |
case 8: |
|
1895 |
format = "%o"; |
|
1896 |
break; |
|
1897 |
} |
|
1 | 1898 |
} |
1899 |
||
1900 |
if (format) { |
|
379 | 1901 |
/* |
1902 |
* actually only needed on sparc: since thisContext is |
|
1903 |
* in a global register, which gets destroyed by printf, |
|
1904 |
* manually save it here - very stupid ... |
|
1905 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1906 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1907 |
|
1133 | 1908 |
sprintf(buffer, format, __intVal(self)); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1909 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1910 |
__END_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1911 |
|
1133 | 1912 |
newString = __MKSTRING(buffer COMMA_SND); |
324 | 1913 |
if (newString != nil) { |
282 | 1914 |
RETURN (newString); |
324 | 1915 |
} |
1 | 1916 |
} |
314 | 1917 |
%}. |
1918 |
" |
|
1919 |
fall back for seldom used bases |
|
1920 |
" |
|
1 | 1921 |
^ super printStringRadix:radix |
62 | 1922 |
|
1923 |
"123 printStringRadix:16" |
|
1924 |
"123 printStringRadix:8" |
|
1925 |
"123 printStringRadix:2" |
|
1926 |
"123 printStringRadix:3" |
|
1927 |
"123 printStringRadix:1" |
|
1 | 1928 |
! |
1929 |
||
1930 |
printfPrintString:formatString |
|
1931 |
"non-portable, but sometimes useful. |
|
1932 |
return a printed representation of the receiver |
|
62 | 1933 |
as specified by formatString, which is defined by the C- |
1934 |
function 'printf'. |
|
1935 |
No checking for string overrun - the resulting string |
|
1936 |
must be shorter than 256 chars or else ... |
|
1937 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 1938 |
|
13 | 1939 |
%{ /* STACK: 400 */ |
1 | 1940 |
|
1941 |
char buffer[256]; |
|
314 | 1942 |
OBJ s; |
1 | 1943 |
|
62 | 1944 |
if (__isString(formatString)) { |
379 | 1945 |
/* |
1946 |
* actually only needed on sparc: since thisContext is |
|
1947 |
* in a global register, which gets destroyed by printf, |
|
1948 |
* manually save it here - very stupid ... |
|
1949 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1950 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1951 |
|
1133 | 1952 |
sprintf(buffer, __stringVal(formatString), __intVal(self)); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1953 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1954 |
__END_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1955 |
|
1133 | 1956 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 1957 |
if (s != nil) { |
1958 |
RETURN (s); |
|
1959 |
} |
|
1 | 1960 |
} |
314 | 1961 |
%}. |
1 | 1962 |
self primitiveFailed |
1963 |
||
1964 |
"123 printfPrintString:'%%d -> %d'" |
|
1965 |
"123 printfPrintString:'%%6d -> %6d'" |
|
1966 |
"123 printfPrintString:'%%x -> %x'" |
|
1967 |
"123 printfPrintString:'%%4x -> %4x'" |
|
1968 |
"123 printfPrintString:'%%04x -> %04x'" |
|
1969 |
! ! |
|
701 | 1970 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1971 |
!SmallInteger methodsFor:'private'! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1972 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1973 |
sign:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1974 |
"private: for protocol completeness with LargeIntegers" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1975 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1976 |
|absVal| |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1977 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1978 |
absVal := self abs. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1979 |
aNumber < 0 ifTrue:[ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1980 |
^ absVal negated |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1981 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1982 |
aNumber == 0 ifTrue:[^ 0]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1983 |
^ absVal |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1984 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1985 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1986 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1987 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1988 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1989 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1990 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1991 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1992 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1993 |
! ! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1994 |
|
701 | 1995 |
!SmallInteger methodsFor:'testing'! |
1996 |
||
1997 |
between:min and:max |
|
1998 |
"return true if the receiver is less than or equal to the argument max |
|
1999 |
and greater than or equal to the argument min. |
|
2000 |
- reimplemented here for speed" |
|
2001 |
||
2002 |
%{ /* NOCONTEXT */ |
|
2003 |
||
2004 |
if (__bothSmallInteger(min, max)) { |
|
2005 |
REGISTER INT selfVal; |
|
2006 |
||
1133 | 2007 |
selfVal = __intVal(self); |
2008 |
if (selfVal < __intVal(min)) { |
|
701 | 2009 |
RETURN ( false ); |
2010 |
} |
|
1133 | 2011 |
if (selfVal > __intVal(max)) { |
701 | 2012 |
RETURN ( false ); |
2013 |
} |
|
2014 |
RETURN ( true ); |
|
2015 |
} |
|
2016 |
%} |
|
2017 |
. |
|
2018 |
(self < min) ifTrue:[^ false]. |
|
2019 |
(self > max) ifTrue:[^ false]. |
|
2020 |
^ true |
|
2021 |
! |
|
2022 |
||
2023 |
even |
|
2024 |
"return true, if the receiver is even" |
|
2025 |
||
2026 |
%{ /* NOCONTEXT */ |
|
2027 |
||
2028 |
#ifdef POSITIVE_ADDRESSES |
|
2029 |
RETURN ( ((INT)self & 1) ? false : true ); |
|
2030 |
#else |
|
1133 | 2031 |
RETURN ( ((INT)self & ((INT)__MKSMALLINT(1) & ~TAG_INT)) ? false : true ); |
701 | 2032 |
#endif |
2033 |
%} |
|
2034 |
! |
|
2035 |
||
2036 |
negative |
|
2037 |
"return true, if the receiver is less than zero |
|
2038 |
reimplemented here for speed" |
|
2039 |
||
2040 |
%{ /* NOCONTEXT */ |
|
2041 |
||
2042 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 2043 |
RETURN ( (__intVal(self) < 0) ? true : false ); |
701 | 2044 |
#else |
2045 |
/* tag bit does not change sign */ |
|
2046 |
RETURN ( ((INT)(self) < 0) ? true : false ); |
|
2047 |
#endif |
|
2048 |
%} |
|
2049 |
! |
|
2050 |
||
2051 |
odd |
|
2052 |
"return true, if the receiver is odd" |
|
2053 |
||
2054 |
%{ /* NOCONTEXT */ |
|
2055 |
||
2056 |
#ifdef POSITIVE_ADDRESSES |
|
2057 |
RETURN ( ((INT)self & 1) ? true : false ); |
|
2058 |
#else |
|
1133 | 2059 |
RETURN ( ((INT)self & ((INT)__MKSMALLINT(1) & ~TAG_INT)) ? true : false ); |
701 | 2060 |
#endif |
2061 |
%} |
|
2062 |
! |
|
2063 |
||
2064 |
positive |
|
2065 |
"return true, if the receiver is not negative |
|
2066 |
reimplemented here for speed" |
|
2067 |
||
2068 |
%{ /* NOCONTEXT */ |
|
2069 |
||
2070 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 2071 |
RETURN ( (__intVal(self) >= 0) ? true : false ); |
701 | 2072 |
#else |
2073 |
/* tag bit does not change sign */ |
|
2074 |
RETURN ( ((INT)(self) >= 0) ? true : false ); |
|
2075 |
#endif |
|
2076 |
%} |
|
2077 |
! |
|
2078 |
||
2079 |
sign |
|
2080 |
"return the sign of the receiver |
|
2081 |
reimplemented here for speed" |
|
2082 |
||
2083 |
%{ /* NOCONTEXT */ |
|
2084 |
||
1133 | 2085 |
INT val = __intVal(self); |
701 | 2086 |
|
2087 |
if (val < 0) { |
|
1133 | 2088 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 2089 |
} |
2090 |
if (val > 0) { |
|
1133 | 2091 |
RETURN ( __MKSMALLINT(1) ); |
701 | 2092 |
} |
1133 | 2093 |
RETURN ( __MKSMALLINT(0) ); |
701 | 2094 |
%} |
2095 |
! |
|
2096 |
||
2097 |
strictlyPositive |
|
2098 |
"return true, if the receiver is greater than zero |
|
2099 |
reimplemented here for speed" |
|
2100 |
||
2101 |
%{ /* NOCONTEXT */ |
|
2102 |
||
2103 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 2104 |
RETURN ( (__intVal(self) > 0) ? true : false ); |
701 | 2105 |
#else |
2106 |
/* tag bit does not change sign */ |
|
2107 |
RETURN ( ((INT)(self) > 0) ? true : false ); |
|
2108 |
#endif |
|
2109 |
%} |
|
2110 |
! ! |
|
2111 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2112 |
!SmallInteger class methodsFor:'documentation'! |
701 | 2113 |
|
2114 |
version |
|
1889 | 2115 |
^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.61 1996-11-05 18:25:59 cg Exp $' |
701 | 2116 |
! ! |