SmallInteger.st
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--
*** empty log message ***
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
 COPYRIGHT (c) 1988 by Claus Gittinger
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    36
documentation
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    37
"
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
    SmallIntegers are Integers in the range of at least +/- 2^30 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
    (i.e. 31 bits, which is not guaranteed; it could be more on 64 bit cpus).
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    41
    These are no real objects - they have no instances (not even storage !!)
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    42
    and cannot be subclassed.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    43
    The reason is to save both storage and runtime by not collecting
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    44
    SmallIntegers in the system. SmallInts are marked by having the TAG_INT 
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    45
    bit set, in contrast to all other objects which do not. 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    46
    Since this knowledge is hardwired into the system (and there is no 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
    class-field stored with SmallIntegers) there can be no subclass of 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    48
    SmallInteger (sorry).
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    49
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    50
    If you really need this kind of thing, create a subclass of Integer,
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    51
    with an instance variable holding the value.
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    52
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    53
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1264
diff changeset
    54
        Claus Gittinger
1556
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    55
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    56
    [see also:]
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    57
        Number
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    58
        Float Fraction 
134d96466f5a commentary
Claus Gittinger <cg@exept.de>
parents: 1506
diff changeset
    59
        LargeInteger
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    60
"
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    61
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    64
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
basicNew
a27a279701f8 Initial revision
claus
parents:
diff changeset
    66
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    68
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
    self error:'instances of SmallInteger cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
basicNew:size
a27a279701f8 Initial revision
claus
parents:
diff changeset
    73
    "catch instance creation
a27a279701f8 Initial revision
claus
parents:
diff changeset
    74
     - SmallIntegers cannot be created with new"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
a27a279701f8 Initial revision
claus
parents:
diff changeset
    76
    self error:'instances of SmallInteger cannot be created with new'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    80
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    81
bitMaskFor:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    82
    "return a bitmask for the index's bit (index starts at 1)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    83
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    84
    (index between:1 and:SmallInteger maxBits) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    85
	^ self error:'index out of bounds'
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    86
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    87
    ^ 1 bitShift:(index - 1)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    88
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
    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
a27a279701f8 Initial revision
claus
parents:
diff changeset
    91
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
maxBits
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    93
    "return the number of bits in instances of me.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
    94
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
%{  /* NOCONTEXT */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
    97
    RETURN ( __MKSMALLINT(N_INT_BITS) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    98
%}
2
claus
parents: 1
diff changeset
    99
claus
parents: 1
diff changeset
   100
    "SmallInteger maxBits"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   101
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   102
a27a279701f8 Initial revision
claus
parents:
diff changeset
   103
maxBytes
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   104
    "return the number of bytes in instances of me.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   105
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
a27a279701f8 Initial revision
claus
parents:
diff changeset
   107
%{  /* NOCONTEXT */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   108
    RETURN ( __MKSMALLINT(N_INT_BITS / 8 + 1) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   109
%}
2
claus
parents: 1
diff changeset
   110
claus
parents: 1
diff changeset
   111
    "SmallInteger maxBytes"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   112
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
a27a279701f8 Initial revision
claus
parents:
diff changeset
   114
maxVal
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   115
    "return the largest Integer representable as SmallInteger.
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   116
     For very special uses only - not constant across implementations"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
%{  /* NOCONTEXT */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   119
    RETURN ( __MKSMALLINT(_MAX_INT) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
%}
2
claus
parents: 1
diff changeset
   121
claus
parents: 1
diff changeset
   122
    "SmallInteger maxVal"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   123
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   124
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   125
minVal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   126
    "return the smallest Integer representable as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   127
     For very special uses only - not constant across implementations"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   128
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   129
%{  /* NOCONTEXT */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   130
    RETURN ( __MKSMALLINT(_MIN_INT) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   131
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   132
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   133
    "SmallInteger minVal"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
24d81bf47225 *** empty log message ***
claus
parents: 2
diff changeset
   137
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   138
canBeSubclassed
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   139
    "return true, if its allowed to create subclasses of the receiver.
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   140
     Return nil here - since it is NOT possible for SmallInteger"
50
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   141
71f3b9444905 *** empty log message ***
claus
parents: 44
diff changeset
   142
    ^ false
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   145
isBuiltInClass
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   146
    "return true if this class is known by the run-time-system.
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   147
     Here, true is returned."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   148
a27a279701f8 Initial revision
claus
parents:
diff changeset
   149
    ^ true
1264
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   150
8d916aa63bce commentary
Claus Gittinger <cg@exept.de>
parents: 1208
diff changeset
   151
    "Modified: 23.4.1996 / 16:00:33 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
!SmallInteger methodsFor:'arithmetic'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
a27a279701f8 Initial revision
claus
parents:
diff changeset
   156
* aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   157
    "return the product of the receivers value and the arguments value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   158
a27a279701f8 Initial revision
claus
parents:
diff changeset
   159
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   160
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   161
    INT myValue, otherValue;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   162
    unsigned INT productLow, productHi;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   163
    int negative;
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   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
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   167
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   168
    /*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   169
     * can we use long long arithmetic ?
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   170
     */
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   171
#if defined(__GNUC__) && (__GNUC__ >= 2)
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   172
    /*
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   173
     * commented, since long-long arithmetic seems to
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   174
     * be buggy in some implementations (sparc) ...
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   175
     * (took me a while to find this out :-(
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   176
     */
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   177
# ifdef NOTDEF
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   178
#   define _LONGLONG
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   179
# endif
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   180
#endif
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   181
252
   182
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   183
	myValue = __intVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   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
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   186
#if defined(_LONGLONG)
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   187
	{
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   188
	    long long product;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   189
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   190
	    product = (long long)myValue * (long long)otherValue;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   191
	    if ((product >= (long long)_MIN_INT) 
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   192
	     && (product <= (long long)_MAX_INT)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   193
		RETURN ( __MKSMALLINT((int)product) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   194
	    }
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   195
	    if (product < 0) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   196
		negative = 1;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   197
		product = -product;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   198
	    } else {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   199
		negative = 0;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   200
	    }
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   201
	    productHi = product >> 32;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   202
	    productLow = product & 0xFFFFFFFF;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   203
	}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   204
#else
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   205
	negative = 0;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   206
	if (myValue < 0) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   207
	    negative = 1;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   208
	    myValue = -myValue;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   209
	}
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   210
	if (otherValue < 0) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   211
	    negative = (1 - negative);
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   212
	    otherValue = -otherValue;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   213
	}
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   214
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   215
# if defined(__GNUC__) && defined(mc68k)
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   216
	asm ("mulu%.l %3,%1:%0"
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   217
		: "=d"  ((unsigned long)(productLow)),
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   218
		  "=d"  ((unsigned long)(productHi))
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   219
		: "%0"  ((unsigned long)(myValue)),
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   220
		  "dmi" ((unsigned long)(otherValue)));
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   221
# else
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   222
#  if defined (__GNUC__) && defined(i386)
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   223
	asm ("mull %3"
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   224
		: "=a"  ((unsigned long)(productLow)),
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   225
		  "=d"  ((unsigned long)(productHi))
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   226
		: "%0"  ((unsigned long)(myValue)),
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   227
		  "rm"  ((unsigned long)(otherValue)));
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   228
#  else
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   229
	{
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   230
	    unsigned INT pHH, pHL, pLH, pLL;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   231
	    unsigned INT low1, low2, hi1, hi2;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   232
	    unsigned INT t;
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   233
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   234
	    /* unsigned multiply myValue * otherValue -> productHi, productLow
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   235
	     *
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   236
	     * this is too slow:
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   237
	     * since most machines can do 32*32 to 64 bit multiply,
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   238
	     * (or at least 32*32 with Overflow check)
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   239
	     * - need more assembler (inline) functions here 
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   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
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   245
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   246
	    pLH = low1 * hi2;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   247
	    pHL = hi1 * low2;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   248
	    pLL = low1 * low2;
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   249
        
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   250
	    /*
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   251
	     * the common case ...
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   252
	     */
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   253
	    if ((pHL == 0)
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   254
	     && (pLH == 0)
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   255
	     && ((pLL & 0xC0000000) == 0)) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   256
		if (negative) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   257
		    RETURN ( __MKSMALLINT(- ((INT)pLL)) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   258
		}
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   259
		RETURN ( __MKSMALLINT((INT)pLL) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   260
	    }
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   261
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   262
	    pHH = hi1 * hi2;
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   263
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   264
	    /*
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   265
	     *   pHH |--------|--------|
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   266
	     *   pLH          |--------|--------|
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   267
	     *   pHL          |--------|--------|
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   268
	     *   pLL                   |--------|--------|
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   269
	     */
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   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
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   274
	}
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   275
#  endif
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   276
# endif
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   277
	if (productHi == 0) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   278
	    if (negative) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   279
		if (productLow <= -(_MIN_INT)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   280
		    RETURN ( __MKSMALLINT(-((INT)productLow)) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   281
		}
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   282
	    } else {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   283
		if (productLow <= _MAX_INT) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   284
		    RETURN ( __MKSMALLINT(productLow) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   285
		}
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   286
	    }
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   287
	}
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   288
#endif
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   289
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   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
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
   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
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   294
	}
283
a897d331b4c1 *** empty log message ***
claus
parents: 282
diff changeset
   295
    } else if (__isFloatLike(aNumber)) {
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   296
	OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   297
	double val = (double)__intVal(self) * __floatVal(aNumber);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   300
	RETURN ( newFloat );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   301
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   302
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   303
.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   304
    ^ aNumber productFromInteger:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   305
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   306
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   307
+ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   308
    "return the sum of the receivers value and the arguments value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   309
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   310
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   311
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   312
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   313
#ifdef _ADD_IO_IO
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   314
	RETURN ( _ADD_IO_IO(self, aNumber) );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   315
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   316
	REGISTER INT sum;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   317
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   318
	sum =  __intVal(self) + __intVal(aNumber);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   319
	if ((sum >= _MIN_INT) && (sum <= _MAX_INT)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   320
	    RETURN ( __MKSMALLINT(sum) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   323
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   324
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   325
    if (__isFloatLike(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   326
	OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   327
	double val = (double)__intVal(self) + __floatVal(aNumber);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   330
	RETURN ( newFloat );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   331
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   332
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   333
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   334
    ^ aNumber sumFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   335
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   336
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   337
- aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   338
    "return the difference of the receivers value and the arguments value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   339
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   340
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   341
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   342
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   343
#ifdef _SUB_IO_IO
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   344
	RETURN ( _SUB_IO_IO(self, aNumber) );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   345
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   346
	REGISTER INT diff;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   347
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   348
	diff =  __intVal(self) - __intVal(aNumber);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   349
	if ((diff >= _MIN_INT) && (diff <= _MAX_INT)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   350
	    RETURN ( __MKSMALLINT(diff) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   353
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   354
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   355
    if (__isFloatLike(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   356
	OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   357
	double val = (double)__intVal(self) - __floatVal(aNumber);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   360
	RETURN ( newFloat );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   361
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   362
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   363
    ^ aNumber differenceFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   364
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   365
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
/ aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
    "return the quotient of the receivers value and the arguments value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   368
a27a279701f8 Initial revision
claus
parents:
diff changeset
   369
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   370
a27a279701f8 Initial revision
claus
parents:
diff changeset
   371
    INT me, t, val;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   372
    double dval;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   373
252
   374
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   375
	val = __intVal(aNumber);
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   376
	if (val != 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   377
	    me = __intVal(self);
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   378
	    t = me / val;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   379
#ifdef GOOD_OPTIMIZER
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   380
	    if (me % val) {
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   381
#else
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   382
	    /* this is stupid - all I want is to look for a remainder ... 
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   383
	       but most compilers are too stupid and generate an extra modulu
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   384
	       instruction for "if (me % val)".
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   385
	       Even if most divide instructions already leave the remainder in
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   386
	       some register.
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   387
	       Therefore I use a multiplication which is faster than a modulu
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   388
	       on most machines. Hint to GNU people :-)
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   389
	    */
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   390
	    if ((t * val) == me) {
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   391
#endif
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   392
		RETURN ( __MKSMALLINT(t) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   393
	    }
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   394
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
    } else {
283
a897d331b4c1 *** empty log message ***
claus
parents: 282
diff changeset
   396
	if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   397
	    dval = __floatVal(aNumber);
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   398
	    if (dval != 0.0) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   399
		OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   400
		double val = (double)__intVal(self) / dval;
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   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
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   403
		RETURN ( newFloat );
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   404
	    }
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   405
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   406
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   407
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   408
    aNumber isInteger ifTrue:[
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   409
	aNumber == 0 ifTrue:[
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   410
	    ^ DivisionByZeroSignal raise.
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   411
	].
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   412
	^ Fraction numerator:self denominator:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   413
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   427
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
2
claus
parents: 1
diff changeset
   429
// aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   430
    "return the integer part of the quotient of the receivers value
1884
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   431
     and the arguments value. The result is truncated toward negative infinity
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   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
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   441
        val = __intVal(aNumber);
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   442
        if (val != 0) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   443
            rslt = __intVal(self) / val;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   444
            if (rslt < 0) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   445
                if (__intVal(self) % val)
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   446
                    rslt--;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   447
            }
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   448
            RETURN ( __MKSMALLINT(rslt) );
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   449
        }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   450
    } else {
1884
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   451
        if (__isFraction(aNumber)) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   452
            OBJ t;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   453
            INT num, den;
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   454
1884
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   455
            t = __FractionInstPtr(aNumber)->f_numerator;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   456
            if (__isSmallInteger(t)) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   457
                num = __intVal(t);
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   458
                t = __FractionInstPtr(aNumber)->f_denominator;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   459
                if (__isSmallInteger(t)) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   460
                    den = __intVal(t);
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   461
                    RETURN ( __MKSMALLINT(__intVal(self) * den / num ));
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   462
                }
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   463
            }
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   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
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   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
claus
parents: 1
diff changeset
   485
\\ aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   489
a27a279701f8 Initial revision
claus
parents:
diff changeset
   490
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   491
    INT mySelf, val;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   492
252
   493
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   494
	mySelf = __intVal(self);
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   495
	if (mySelf < 0) mySelf = -mySelf;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   496
	val = __intVal(aNumber);
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   497
	if (val != 0) {
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   498
	    if (val < 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   499
		RETURN ( __MKSMALLINT(-(mySelf % -val)) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   500
	    }
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   501
	    RETURN ( __MKSMALLINT(mySelf % val) );
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   502
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   503
    }
927
8d8edf9df0ae fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents: 829
diff changeset
   504
%}.
2
claus
parents: 1
diff changeset
   505
    (aNumber = 0) ifTrue:[
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   506
	^ DivisionByZeroSignal raise.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   507
    ].
2
claus
parents: 1
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   516
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   517
a27a279701f8 Initial revision
claus
parents:
diff changeset
   518
abs
a27a279701f8 Initial revision
claus
parents:
diff changeset
   519
    "return the absolute value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   520
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   521
a27a279701f8 Initial revision
claus
parents:
diff changeset
   522
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   523
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   524
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   525
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   526
    if (val >= 0) {
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   527
	RETURN (self);
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   528
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   529
    if (val != _MIN_INT) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   530
	RETURN ( __MKSMALLINT(-val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   531
    }
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   532
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   533
    "only reached for minVal"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   534
    ^ self negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   535
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   536
a27a279701f8 Initial revision
claus
parents:
diff changeset
   537
negated
a27a279701f8 Initial revision
claus
parents:
diff changeset
   538
    "return the negative value of the receiver
a27a279701f8 Initial revision
claus
parents:
diff changeset
   539
     reimplemented here for speed"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   540
a27a279701f8 Initial revision
claus
parents:
diff changeset
   541
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   542
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   543
    INT val = __intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   544
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
    if (val != _MIN_INT) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   546
	RETURN ( __MKSMALLINT(- val) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
    }
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   548
%}.
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
   549
    "only reached for minVal"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   555
     and the arguments value. The result is truncated towards zero
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   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
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   566
        val = __intVal(aNumber);
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   567
        if (val != 0) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   568
            RETURN ( __MKSMALLINT(__intVal(self) / val) );
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   569
        }
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   570
    } else {
1884
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   571
        if (__isFraction(aNumber)) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   572
            OBJ t;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   573
            INT num, den;
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   574
1884
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   575
            t = __FractionInstPtr(aNumber)->f_numerator;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   576
            if (__isSmallInteger(t)) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   577
                num = __intVal(t);
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   578
                t = __FractionInstPtr(aNumber)->f_denominator;
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   579
                if (__isSmallInteger(t)) {
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   580
                    den = __intVal(t);
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   581
                    RETURN ( __MKSMALLINT(__intVal(self) * den / num ));
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   582
                }
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   583
            }
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   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
abd423adeb94 commentary
Claus Gittinger <cg@exept.de>
parents: 1842
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   599
a27a279701f8 Initial revision
claus
parents:
diff changeset
   600
!SmallInteger methodsFor:'bit operators'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   601
a27a279701f8 Initial revision
claus
parents:
diff changeset
   602
allMask:anInteger
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   603
    "return true if all 1-bits in anInteger are also 1 in the receiver"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   604
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   605
    ^ (self bitAnd:anInteger) == anInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   606
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   607
    "2r00001111 allMask:2r00000001"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   608
    "2r00001111 allMask:2r00011110"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   609
    "2r00001111 allMask:2r00000000"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   610
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   611
a27a279701f8 Initial revision
claus
parents:
diff changeset
   612
anyMask:anInteger
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   613
    "return true if any 1-bits in anInteger is also 1 in the receiver.
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   614
     (somewhat incorrect, if the mask is zero)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   615
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   616
    ^ (self bitAnd:anInteger) ~~ 0
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   617
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   618
    "2r00001111 anyMask:2r00000001"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   619
    "2r00001111 anyMask:2r11110000"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   620
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   621
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   622
bitAnd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   623
    "return the bitwise-and of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   624
a27a279701f8 Initial revision
claus
parents:
diff changeset
   625
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   626
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   627
    /* anding the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   628
    if (__isSmallInteger(anInteger)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   629
	RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   633
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   634
    "(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   635
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   636
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   637
bitAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   638
    "return the value of the index's bit (index starts at 1).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   639
     Notice: the result of bitAt: on negative receivers is not 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   640
	     defined in the language standard (since the implementation
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   641
	     is free to choose any internal representation for integers)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   642
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   643
    |mask|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   644
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   645
    (index between:1 and:SmallInteger maxBits) ifFalse:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   646
	^ self error:'index out of bounds'
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   647
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   648
    mask := 1 bitShift:(index - 1).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   649
    ((self bitAnd:mask) == 0) ifTrue:[^ 0].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   650
    ^ 1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   651
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   652
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   653
bitInvert
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   654
    "return the value of the receiver with all bits inverted"
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   655
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   656
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   657
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   658
    /* invert anything except tag bits */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   659
    RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   660
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   661
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   662
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   663
bitOr:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   664
    "return the bitwise-or of the receiver and the argument, anInteger"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   665
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   666
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   667
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   668
    /* oring the tags doesn't change it */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   669
    if (__isSmallInteger(anInteger)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   670
	RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   674
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   675
    "(2r000000100 bitOr:2r00000011) radixPrintStringRadix:2"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   676
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   707
bitShift:shiftCount
a27a279701f8 Initial revision
claus
parents:
diff changeset
   708
    "return the value of the receiver shifted by shiftCount bits;
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   709
     leftShift if shiftCount > 0; rightShift otherwise.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   713
a27a279701f8 Initial revision
claus
parents:
diff changeset
   714
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   715
a27a279701f8 Initial revision
claus
parents:
diff changeset
   716
    INT bits, count;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   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
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   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
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   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
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   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
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   771
    }
85
claus
parents: 77
diff changeset
   772
%}.
claus
parents: 77
diff changeset
   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
claus
parents: 77
diff changeset
   775
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   776
    ^ self bitShift:(shiftCount coerce:1)
a27a279701f8 Initial revision
claus
parents:
diff changeset
   777
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   778
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   779
bitTest:aMask
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   780
    "return true, if any bit from aMask is set in the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   781
a27a279701f8 Initial revision
claus
parents:
diff changeset
   782
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   783
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   784
    /* and all bits except tag */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   785
    if (__isSmallInteger(aMask)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   786
	RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   790
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   791
a27a279701f8 Initial revision
claus
parents:
diff changeset
   792
bitXor:anInteger
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   793
    "return the bitwise-exclusive-or of the receiver and the argument, anInteger"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   794
a27a279701f8 Initial revision
claus
parents:
diff changeset
   795
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   796
a27a279701f8 Initial revision
claus
parents:
diff changeset
   797
    /* xoring the tags turns it off - or it in again */
252
   798
    if (__isSmallInteger(anInteger)) {
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   799
	RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   803
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   804
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   805
highBit
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   806
    "return the bitIndex of the highest bit set. The returned bitIndex
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   807
     starts at 1 for the least significant bit. Returns -1 if no bit is set."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   808
a27a279701f8 Initial revision
claus
parents:
diff changeset
   809
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   810
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   811
    INT mask, index, bits;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   812
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   813
    bits = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   814
    if (bits == 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   815
	RETURN ( __MKSMALLINT(-1) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   816
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   817
#ifdef alpha
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   818
    mask = 0x2000000000000000;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   819
    index = 62;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   820
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   821
    mask = 0x20000000;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   822
    index = 30;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   823
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   824
    while (index) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   825
	if (bits & mask) break;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   826
	mask = mask >> 1;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   827
	index--;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   828
    }
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   829
    RETURN ( __MKSMALLINT(index) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   830
%}
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   831
    "2r000100 highBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   832
    "2r010100 highBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   833
    "2r000001 highBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   834
    "0 highBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   835
    "SmallInteger maxVal highBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   836
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   837
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   838
lowBit
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   839
    "return the bitIndex of the lowest bit set. The returned bitIndex
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   840
     starts at 1 for the least significant bit. Returns -1 if no bit is set."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   841
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   842
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   843
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   844
    INT mask, index, bits;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   845
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   846
    bits = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   847
    if (bits == 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   848
	RETURN ( __MKSMALLINT(-1) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   849
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   850
    mask = 1;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   851
    index = 1;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   852
#ifdef alpha
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   853
    while (index != 63) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   854
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   855
    while (index != 31) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   856
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   857
	if (bits & mask) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   858
	    RETURN ( __MKSMALLINT(index) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   859
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   860
	mask = mask << 1;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   861
	index++;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   862
    }
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   863
    RETURN ( __MKSMALLINT(-1) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   864
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   865
    "2r000100 lowBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   866
    "2r010010 lowBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   867
    "2r100001 lowBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   868
    "0 lowBit"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   869
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   870
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   871
noMask:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   872
    "return true if no 1-bit in anInteger is 1 in the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   873
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   874
    ^ (self bitAnd:anInteger) == 0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   875
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   876
    "2r00001111 noMask:2r00000001"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   877
    "2r00001111 noMask:2r11110000"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   878
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   879
a27a279701f8 Initial revision
claus
parents:
diff changeset
   880
!SmallInteger methodsFor:'byte access'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   881
a27a279701f8 Initial revision
claus
parents:
diff changeset
   882
digitAt:index
a27a279701f8 Initial revision
claus
parents:
diff changeset
   883
    "return 8 bits of value, starting at byte index"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   884
a27a279701f8 Initial revision
claus
parents:
diff changeset
   885
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   886
357
claus
parents: 329
diff changeset
   887
    REGISTER INT val;
claus
parents: 329
diff changeset
   888
    INT idx;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   889
252
   890
    if (__isSmallInteger(index)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   891
	val = __intVal(self);
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   892
	if (val < 0)
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   893
	    val = -val;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   894
	switch (idx = __intVal(index)) {
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   895
	    case 1:
357
claus
parents: 329
diff changeset
   896
		break;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   897
	    case 2:
357
claus
parents: 329
diff changeset
   898
		val = (val >> 8);
claus
parents: 329
diff changeset
   899
		break;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   900
	    case 3:
357
claus
parents: 329
diff changeset
   901
		val = (val >> 16);
claus
parents: 329
diff changeset
   902
		break;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   903
	    case 4:
357
claus
parents: 329
diff changeset
   904
		val = (val >> 24);
claus
parents: 329
diff changeset
   905
		break;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   906
#ifdef alpha
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   907
	    case 5:
357
claus
parents: 329
diff changeset
   908
		val = (val >> 32);
claus
parents: 329
diff changeset
   909
		break;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   910
	    case 6:
357
claus
parents: 329
diff changeset
   911
		val = (val >> 40);
claus
parents: 329
diff changeset
   912
		break;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   913
	    case 7:
357
claus
parents: 329
diff changeset
   914
		val = (val >> 48);
claus
parents: 329
diff changeset
   915
		break;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   916
	    case 8:
357
claus
parents: 329
diff changeset
   917
		val = (val >> 56);
claus
parents: 329
diff changeset
   918
		break;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   919
#endif
357
claus
parents: 329
diff changeset
   920
	    default:
claus
parents: 329
diff changeset
   921
		if (idx < 1)
claus
parents: 329
diff changeset
   922
		    goto bad;   /* sorry */
claus
parents: 329
diff changeset
   923
		val = 0;
claus
parents: 329
diff changeset
   924
		break;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
   925
	}
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   926
	RETURN ( __MKSMALLINT( val & 0xFF) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   927
    }
357
claus
parents: 329
diff changeset
   928
  bad: ;
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   929
%}.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   930
    index > 0 ifFalse:[
357
claus
parents: 329
diff changeset
   931
	"
claus
parents: 329
diff changeset
   932
	 index less than 1 - not allowed
claus
parents: 329
diff changeset
   933
	"
claus
parents: 329
diff changeset
   934
	^ self primitiveFailed
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   935
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   936
    ^ 0
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
   937
357
claus
parents: 329
diff changeset
   938
    "
claus
parents: 329
diff changeset
   939
     (16r12345678 digitAt:1) printStringRadix:16
claus
parents: 329
diff changeset
   940
     (16r12345678 digitAt:3) printStringRadix:16
claus
parents: 329
diff changeset
   941
     (16r12345678 digitAt:15) printStringRadix:16
claus
parents: 329
diff changeset
   942
     (16r12345678 digitAt:0) printStringRadix:16
claus
parents: 329
diff changeset
   943
     (16r12345678 digitAt:-10) printStringRadix:16
claus
parents: 329
diff changeset
   944
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   945
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   946
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   947
digitLength
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   948
    "return the number bytes used by this Integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   949
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   950
    ^ self abs highBit - 1 // 8 + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   951
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   952
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   953
!SmallInteger methodsFor:'catching messages'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   954
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   955
basicAt:index
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   956
    "catch indexed access - report an error
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   957
     defined here since basicAt: in Object ommits the SmallInteger check."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   958
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   959
    self notIndexed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   960
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   961
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   962
basicAt:index put:anObject
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   963
    "catch indexed access - report an error
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   964
     defined here since basicAt:put: in Object ommits the SmallInteger check."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   965
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   966
    self notIndexed
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   967
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   968
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   969
basicSize
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   970
    "return the number of indexed instvars - SmallIntegers have none.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   971
     Defined here since basicSize in Object ommits the SmallInteger check."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   972
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   973
    ^ 0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   974
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   975
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   976
size
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   977
    "return the number of indexed instvars - SmallIntegers have none."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   978
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   979
    ^ 0
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   980
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   981
a27a279701f8 Initial revision
claus
parents:
diff changeset
   982
!SmallInteger methodsFor:'coercing and converting'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   983
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   984
asCharacter
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   985
    "Return a character with the receiver as ascii value"
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
   986
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
   987
    ^ Character value:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   988
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   989
a27a279701f8 Initial revision
claus
parents:
diff changeset
   990
asFloat
a27a279701f8 Initial revision
claus
parents:
diff changeset
   991
    "return a Float with same value as receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   992
a27a279701f8 Initial revision
claus
parents:
diff changeset
   993
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   994
a27a279701f8 Initial revision
claus
parents:
diff changeset
   995
    OBJ newFloat;
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
   996
    double dVal = (double)__intVal(self);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   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
a27a279701f8 Initial revision
claus
parents:
diff changeset
   999
    RETURN ( newFloat );
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1000
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1001
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1002
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1003
asLargeInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1004
    "return a LargeInteger with same value as receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1005
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1006
    ^ LargeInteger value:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1007
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1008
1199
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1009
asShortFloat
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1010
    "return a ShortFloat with same value as receiver"
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1011
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1012
%{  /* NOCONTEXT */
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1013
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1014
    OBJ dummy = @global(ShortFloat);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1015
    OBJ newFloat;
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1016
    float fVal = (float)__intVal(self);
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  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
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1019
    RETURN ( newFloat );
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1020
%}
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1021
!
c37d927155e2 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1137
diff changeset
  1022
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1023
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1024
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1025
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1026
    ^ aNumber asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1027
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1028
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1029
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1030
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1031
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1032
    ^ 20
1336
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1033
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1034
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1035
signExtendedByteValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1036
    "return a smallInteger from sign-extending the 8'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1037
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1038
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1039
%{  /* NOCONTEXT */
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1040
    int i = __intVal(self);
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1041
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1042
    if (i & 0x80) {
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1043
        i = i | 0x7FFFFF00;
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1044
    } else {
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1045
        i = i & 0x7F;
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1046
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1047
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1048
    RETURN (__MKSMALLINT(i));
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1049
%}
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1050
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1051
    "
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1052
     16rFF signExtendedByteValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1053
     16r7F signExtendedByteValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1054
    "
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1055
!
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1056
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1057
signExtendedShortValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1058
    "return a smallInteger from sign-extending the 16'th bit.
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1059
     May be useful for communication interfaces"
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1060
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1061
%{  /* NOCONTEXT */
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1062
    int i = __intVal(self);
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1063
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1064
    if (i & 0x8000) {
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1065
        i = i | 0x7FFF0000;
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1066
    } else {
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1067
        i = i & 0x7FFF;
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1068
    }
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1069
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1070
    RETURN (__MKSMALLINT(i));
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1071
%}
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1072
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1073
    "
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1074
     16rFFFF signExtendedShortValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1075
     16r7FFF signExtendedShortValue
041485f6757a sign extension support
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1076
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1077
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1078
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1079
!SmallInteger methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1080
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1081
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1082
    "return true, if the argument is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1083
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1084
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1085
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1086
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1087
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1088
	RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1089
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1090
	/* tag bit does not change ordering */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1091
	RETURN ( ((INT)self < (INT)aNumber) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1092
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1093
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1094
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1095
	RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1096
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1097
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1098
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1099
    ^ aNumber lessFromInteger:self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1100
    "^ self retry:#< coercing:aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1101
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1102
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1103
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1104
    "return true, if the argument is greater or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1105
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1106
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1107
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1108
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1109
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1110
	RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1111
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1112
	/* tag bit does not change ordering */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1113
	RETURN ( ((INT)self <= (INT)aNumber) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1114
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1115
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1116
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1117
	RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1118
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1119
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1120
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1121
    ^ self retry:#<= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1122
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1123
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1124
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1125
    "return true, if the arguments value is equal to mine"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1126
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1127
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1128
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1129
    if (aNumber == self) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1130
	RETURN ( true );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1131
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1132
    if (! __isNonNilObject(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1133
	/* a smallint or nil */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1134
	RETURN ( false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1135
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1136
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1137
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1138
	RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1139
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1140
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1141
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1142
    aNumber respondsToArithmetic ifFalse:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1143
    ^ self retry:#= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1144
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1145
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1146
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1147
    "return true, if the argument is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1148
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1149
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1150
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1151
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1152
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1153
	RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1154
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1155
	/* tag bit does not change ordering */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1156
	RETURN ( ((INT)self > (INT)aNumber) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1157
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1158
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1159
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1160
	RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1161
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1162
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1163
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1164
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1165
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1166
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1167
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1168
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1169
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1170
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1171
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1172
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1173
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1174
	RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1175
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1176
	/* tag bit does not change ordering */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1177
	RETURN ( ((INT)self >= (INT)aNumber) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1178
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1179
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1180
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1181
	RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1182
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1183
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1184
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1185
    ^ self retry:#>= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1186
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1187
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1188
hash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1189
    "return an integer useful for hashing on value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1190
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1191
    self >= 0 ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1192
    ^ self negated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1193
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1194
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1195
identityHash
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1196
    "return an integer useful for hashing on identity"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1197
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1198
    self >= 0 ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1199
    ^ self negated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1200
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1201
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1202
max:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1203
    "return the receiver or the argument, whichever is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1204
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1205
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1206
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1207
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1208
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1209
	if (__intVal(self) > __intVal(aNumber)) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1210
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1211
	/* tag bit does not change ordering */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1212
	if ((INT)(self) > (INT)(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1213
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1214
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1215
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1216
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1217
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1218
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1219
	if ( (double)__intVal(self) > __floatVal(aNumber) ) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1220
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1221
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1222
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1223
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1224
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1225
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1226
    (self > aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1227
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1228
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1229
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1230
min:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1231
    "return the receiver or the argument, whichever is smaller"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1232
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1233
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1234
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1235
    if (__isSmallInteger(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1236
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1237
	if (__intVal(self) < __intVal(aNumber)) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1238
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1239
	/* tag bit does not change ordering */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1240
	if ((INT)(self) < (INT)(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1241
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1242
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1243
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1244
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1245
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1246
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1247
	if ( (double)__intVal(self) < __floatVal(aNumber) ) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1248
	    RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1249
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1250
	RETURN ( aNumber );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1251
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1252
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1253
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1254
    (self < aNumber) ifTrue:[^ self].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1255
    ^ aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1256
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1257
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1258
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1259
    "return true, if the arguments value is not equal to mine"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1260
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1261
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1262
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1263
    if (aNumber == self) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1264
	RETURN ( false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1265
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1266
    if (! __isNonNilObject(aNumber)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1267
	/* a smallint or nil */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1268
	RETURN ( true );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1269
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1270
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1271
    if (__isFloatLike(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1272
	RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? false : true );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1273
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1274
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1275
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1276
    aNumber respondsToArithmetic ifFalse:[^ true].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1277
    ^ self retry:#~= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1278
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1279
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1280
!SmallInteger methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1281
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1282
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1283
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1284
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1285
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1286
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1287
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1288
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1289
deepCopyUsing:aDictionary
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1290
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1291
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1292
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1293
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1294
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1295
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1296
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1297
    "return a shallow copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1298
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1299
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1300
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1301
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1302
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1303
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1304
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1305
     - reimplemented here since smallintegers are unique"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1306
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1307
    ^ self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1308
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1309
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1310
!SmallInteger methodsFor:'iteration'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1311
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1312
timesRepeat:aBlock
357
claus
parents: 329
diff changeset
  1313
    "evaluate the argument, aBlock self times.
claus
parents: 329
diff changeset
  1314
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1315
357
claus
parents: 329
diff changeset
  1316
    |home|
claus
parents: 329
diff changeset
  1317
%{
claus
parents: 329
diff changeset
  1318
    REGISTER INT tmp;
claus
parents: 329
diff changeset
  1319
    REGISTER OBJFUNC code;
claus
parents: 329
diff changeset
  1320
    static struct inlineCache blockVal = __ILC0(0);
claus
parents: 329
diff changeset
  1321
    REGISTER OBJ rHome;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1322
357
claus
parents: 329
diff changeset
  1323
    tmp = __intVal(self);
claus
parents: 329
diff changeset
  1324
    if (tmp > 0) {
claus
parents: 329
diff changeset
  1325
	if (__isBlockLike(aBlock)
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1326
	 && (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(0))) {
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1327
	    if ((code = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
357
claus
parents: 329
diff changeset
  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
claus
parents: 389
diff changeset
  1333
		RETURN (self);
357
claus
parents: 329
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  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
claus
parents: 389
diff changeset
  1341
		    /*
claus
parents: 389
diff changeset
  1342
		     * home will not move - keep in in a register
claus
parents: 389
diff changeset
  1343
		     */
claus
parents: 389
diff changeset
  1344
# if defined(UNROLL_LOOPS)
claus
parents: 389
diff changeset
  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
claus
parents: 389
diff changeset
  1355
		    }
claus
parents: 389
diff changeset
  1356
# endif
claus
parents: 389
diff changeset
  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
claus
parents: 389
diff changeset
  1360
		    } while(--tmp);
claus
parents: 389
diff changeset
  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
claus
parents: 329
diff changeset
  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
claus
parents: 329
diff changeset
  1367
		} while(--tmp);
394
claus
parents: 389
diff changeset
  1368
		RETURN (self);
357
claus
parents: 329
diff changeset
  1369
#endif /* NEW_BLOCK_CALL */
394
claus
parents: 389
diff changeset
  1370
	    }
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1371
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1372
	    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
394
claus
parents: 389
diff changeset
  1373
		/*
claus
parents: 389
diff changeset
  1374
		 * an interpreted block
claus
parents: 389
diff changeset
  1375
		 */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1376
		home = __BlockInstPtr(aBlock)->b_home;
400
claus
parents: 394
diff changeset
  1377
#if defined(mips) || defined(rs6000)
claus
parents: 394
diff changeset
  1378
# define INDIRECT_CALL_IS_FASTER
claus
parents: 394
diff changeset
  1379
#endif
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  1386
#endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1387
400
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  1392
#endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1393
400
claus
parents: 394
diff changeset
  1394
#if defined(UNROLL_LOOPS)
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  1404
		    tmp -= 4;
claus
parents: 394
diff changeset
  1405
		}
claus
parents: 394
diff changeset
  1406
#endif
394
claus
parents: 389
diff changeset
  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
claus
parents: 389
diff changeset
  1410
		} while(--tmp);
claus
parents: 389
diff changeset
  1411
		RETURN (self);
claus
parents: 389
diff changeset
  1412
	    }
357
claus
parents: 329
diff changeset
  1413
	}
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1414
394
claus
parents: 389
diff changeset
  1415
	/*
claus
parents: 389
diff changeset
  1416
	 * arg is something else - call it with value"
claus
parents: 389
diff changeset
  1417
	 */
claus
parents: 389
diff changeset
  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
claus
parents: 389
diff changeset
  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
claus
parents: 389
diff changeset
  1422
	} while(--tmp);
357
claus
parents: 329
diff changeset
  1423
    }
400
claus
parents: 394
diff changeset
  1424
#undef INTERPRET
claus
parents: 394
diff changeset
  1425
#undef HOME
357
claus
parents: 329
diff changeset
  1426
%}
claus
parents: 329
diff changeset
  1427
claus
parents: 329
diff changeset
  1428
"/    |count "{ Class: SmallInteger }" |
claus
parents: 329
diff changeset
  1429
"/
claus
parents: 329
diff changeset
  1430
"/    count := self.
claus
parents: 329
diff changeset
  1431
"/    [count > 0] whileTrue:[
claus
parents: 329
diff changeset
  1432
"/        aBlock value.
claus
parents: 329
diff changeset
  1433
"/        count := count - 1
claus
parents: 329
diff changeset
  1434
"/    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1435
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1436
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1437
to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1438
    "reimplemented as primitive for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1439
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1440
    |home|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1441
%{
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1442
    REGISTER INT tmp, step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1443
    REGISTER INT final;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1444
    REGISTER OBJFUNC code;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1445
    static struct inlineCache blockVal = __ILC1(0);
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1446
    REGISTER OBJ rHome;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1447
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1448
    if (__bothSmallInteger(incr, stop)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1449
	tmp = __intVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1450
	final = __intVal(stop);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1451
	step = __intVal(incr);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1452
	if (__isBlockLike(aBlock)
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1453
	 && ((code = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1454
	 && (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1455
#ifdef NEW_BLOCK_CALL
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1456
	    if (step < 0) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1460
		    tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1461
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1462
	    } else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1466
		    tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1467
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1468
	    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1469
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1470
	    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1471
	     * arg is a compiled block - 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1472
	     * directly call it without going through "Block-value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1473
	     */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1474
	    home = __BlockInstPtr(aBlock)->b_home;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1475
	    rHome = home;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1476
	    if (step < 0) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1477
		if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1478
		    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1479
		     * home is on stack - will not move
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1480
		     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1484
			tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1485
		    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1486
		} else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1490
			tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1491
		    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1492
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1493
	    } else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1494
		if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1495
		    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1496
		     * home is on stack - will not move
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1497
		     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1501
			tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1502
		    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1503
		} else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1507
			tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1508
		    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1509
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1510
	    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1511
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1512
	} else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1513
	    /*
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1514
	     * arg is something else - call it with value"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1515
	     */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1516
	    if (step < 0) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1519
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1520
		    (*blockVal.ilc_func)(aBlock, 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1523
					 __MKSMALLINT(tmp));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1524
		    tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1525
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1526
	    } else {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1529
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1530
		    (*blockVal.ilc_func)(aBlock, 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1533
					 __MKSMALLINT(tmp));
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1534
		    tmp += step;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1535
		}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1536
	    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1537
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1538
	RETURN ( self );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1539
    }
1672
1b56d6e95c9e changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1540
%}.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1541
    ^ super to:stop by:incr do:aBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1542
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1543
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1544
     1 to:10 by:3 do:[:i | i printNewline]
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1545
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1546
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1547
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1548
to:stop do:aBlock
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1549
    "evaluate aBlock for every integer between (and including) the receiver
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1550
     and the argument, stop.
357
claus
parents: 329
diff changeset
  1551
     Reimplemented as primitive for speed"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1552
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1553
    |home|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1554
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1555
    REGISTER INT tmp;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1556
    INT final;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1557
    REGISTER OBJFUNC code;
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  1558
    static struct inlineCache blockVal = __ILC1(0);
2
claus
parents: 1
diff changeset
  1559
    REGISTER OBJ rHome;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1560
252
  1561
    if (__isSmallInteger(stop)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1562
	tmp = __intVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1563
	final = __intVal(stop);
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1564
	if (__isBlockLike(aBlock)
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1565
	 && (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) {
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1566
	    if ((code = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) {
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  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
claus
parents: 394
diff changeset
  1571
		    tmp++;
530
07d0bce293c9 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
  1572
		}
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  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
claus
parents: 394
diff changeset
  1580
		    /*
claus
parents: 394
diff changeset
  1581
		     * home will not move - keep in in a register
claus
parents: 394
diff changeset
  1582
		     * since this is also the most common case,
claus
parents: 394
diff changeset
  1583
		     * its worth trading a bit memory for speed here ...
claus
parents: 394
diff changeset
  1584
		     */
394
claus
parents: 389
diff changeset
  1585
# if defined(UNROLL_LOOPS)
400
claus
parents: 394
diff changeset
  1586
		    {
530
07d0bce293c9 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
  1587
			int t4;
370
claus
parents: 369
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  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
claus
parents: 394
diff changeset
  1599
			    tmp = t4;
530
07d0bce293c9 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
  1600
			}
400
claus
parents: 394
diff changeset
  1601
		    }
claus
parents: 394
diff changeset
  1602
# endif
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 369
diff changeset
  1614
		    }
530
07d0bce293c9 uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
  1615
		}
400
claus
parents: 394
diff changeset
  1616
		RETURN (self);
claus
parents: 394
diff changeset
  1617
#endif /* NEW_BLOCK_CALL */
claus
parents: 394
diff changeset
  1618
	    }
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1619
	    if (__BlockInstPtr(aBlock)->b_bytecodes != nil) {
400
claus
parents: 394
diff changeset
  1620
		/*
claus
parents: 394
diff changeset
  1621
		 * an interpreted block
claus
parents: 394
diff changeset
  1622
		 */
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  1629
#endif
1036
d79dc9e4c6f5 binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  1630
400
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  1639
#ifdef PASS_ARG_POINTER
claus
parents: 394
diff changeset
  1640
		    {
claus
parents: 394
diff changeset
  1641
		      OBJ idx;
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  1644
		    }
claus
parents: 394
diff changeset
  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
claus
parents: 394
diff changeset
  1647
#endif
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  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
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1651
	    }
400
claus
parents: 394
diff changeset
  1652
	}
claus
parents: 394
diff changeset
  1653
	/*
claus
parents: 394
diff changeset
  1654
	 * arg is something else - call it with value"
claus
parents: 394
diff changeset
  1655
	 */
claus
parents: 394
diff changeset
  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
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1658
400
claus
parents: 394
diff changeset
  1659
	    (*blockVal.ilc_func)(aBlock, 
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1662
				     __MKSMALLINT(tmp));
400
claus
parents: 394
diff changeset
  1663
	    tmp++;
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1664
	}
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1665
	RETURN ( self );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  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
claus
parents: 394
diff changeset
  1669
%}.
claus
parents: 394
diff changeset
  1670
    "/
claus
parents: 394
diff changeset
  1671
    "/ arrive here if stop is not a smallInteger
claus
parents: 394
diff changeset
  1672
    "/
claus
parents: 394
diff changeset
  1673
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1674
    ^ super to:stop do:aBlock
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1675
216
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  1676
    "
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  1677
     1 to:10 do:[:i | i printNewline]
a8abff749575 *** empty log message ***
claus
parents: 214
diff changeset
  1678
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1679
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1680
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1681
!SmallInteger methodsFor:'misc math'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1715
gcd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1716
    "return the greatest common divisor (Euclid's algorithm).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1717
     This has been redefined here for more speed since due to the
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1718
     use of gcd in Fraction code, it has become time-critical for
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1719
     some code. (thanx to MessageTally)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1720
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1721
%{  /* NOCONTEXT */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1722
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1723
    if (__isSmallInteger(anInteger)) {
1889
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1724
        INT orgArg, ttt, selfInt, temp;
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1725
1889
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1726
        ttt = orgArg = __intVal(anInteger);
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1727
        if (ttt) {
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1728
            selfInt = __intVal(self);
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1729
            while (ttt != 0) {
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1730
                temp = selfInt % ttt;
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1731
                selfInt = ttt;
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1732
                ttt = temp;
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1733
            }
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1734
            /*
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1735
             * since its not defined in what the sign of
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1736
             * a modulu result is when the arg is negative,
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1737
             * change it explicitely here ...
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1738
             */
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1739
            if (orgArg < 0) {
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1740
                /* result should be negative */
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1741
                if (selfInt > 0) selfInt = -selfInt;
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1742
            } else {
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1743
                /* result should be positive */
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1744
                if (selfInt < 0) selfInt = -selfInt;
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1745
            }
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1746
            RETURN ( __MKSMALLINT(selfInt) );
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  1747
        }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1748
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1749
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1750
.
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1751
    ^ super gcd:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1752
!
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1753
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1754
intlog10
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1755
    "return the truncation of log10 of the receiver -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1756
     stupid implementation; used to find out the number of digits needed
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1757
     to print a number/and for conversion to a LargeInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1758
     Implemented that way, to allow for tiny systems without a Float class
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1759
     (i.e. without log)."
2
claus
parents: 1
diff changeset
  1760
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1761
    self <= 0 ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1762
	self error:'logarithm of negative integer'
2
claus
parents: 1
diff changeset
  1763
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1764
    self < 10 ifTrue:[^ 1].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1765
    self < 100 ifTrue:[^ 2].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1766
    self < 1000 ifTrue:[^ 3].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1767
    self < 10000 ifTrue:[^ 4].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1768
    self < 100000 ifTrue:[^ 5].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1769
    self < 1000000 ifTrue:[^ 6].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1770
    self < 10000000 ifTrue:[^ 7].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1771
    self < 100000000 ifTrue:[^ 8].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1772
    self < 1000000000 ifTrue:[^ 9].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1773
    ^ 10
2
claus
parents: 1
diff changeset
  1774
! !
claus
parents: 1
diff changeset
  1775
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1776
!SmallInteger methodsFor:'modulu arithmetic'!
2
claus
parents: 1
diff changeset
  1777
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1778
plus:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1779
    "return the sum of the receiver and the argument, as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1780
     The argument must be another SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1781
     If the result overflows the smallInteger range, the value modulu the 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1782
     smallInteger range is returned (i.e. the low bits of the sum).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1783
     This is of course not always correct, but some code does a modulu anyway
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1784
     and can therefore speed things up by not going through LargeIntegers."
41
a14247b04d03 *** empty log message ***
claus
parents: 13
diff changeset
  1785
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1786
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1787
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1788
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1789
	RETURN ( __MKSMALLINT((__intVal(self) + __intVal(aNumber)) & 0x7FFFFFFF) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1790
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1791
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1792
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1793
    self primitiveFailed
2
claus
parents: 1
diff changeset
  1794
!
claus
parents: 1
diff changeset
  1795
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1796
subtract:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1797
    "return the difference of the receiver and the argument, as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1798
     The argument must be another SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1799
     If the result overflows the smallInteger range, the value modulu the 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1800
     smallInteger range is returned (i.e. the low bits of the sum).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1801
     This is of course not always correct, but some code does a modulu anyway
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1802
     and can therefore speed things up by not going through LargeIntegers."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1803
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1804
%{  /* NOCONTEXT */
2
claus
parents: 1
diff changeset
  1805
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1806
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1807
	RETURN ( __MKSMALLINT((__intVal(self) - __intVal(aNumber)) & 0x7FFFFFFF) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1808
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1809
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1810
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1811
    self primitiveFailed
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1812
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1813
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1814
times:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1815
    "return the product of the receiver and the argument, as SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1816
     The argument must be another SmallInteger.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1817
     If the result overflows the smallInteger range, the value modulu the 
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1818
     smallInteger range is returned (i.e. the low bits of the product).
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1819
     This is of course not always correct, but some code does a modulu anyway
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1820
     and can therefore speed things up by not going through LargeIntegers."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1821
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1822
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1823
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1824
    if (__isSmallInteger(aNumber)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1825
	RETURN ( __MKSMALLINT((__intVal(self) * __intVal(aNumber)) & 0x7FFFFFFF) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1826
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1827
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1828
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1829
    self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1830
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1831
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1832
!SmallInteger methodsFor:'printing & storing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1833
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1834
printOn:aStream
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  1835
    "append my printstring (base 10) to aStream."
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1836
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1837
    aStream nextPutAll:(self printString)
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1838
!
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1839
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1840
printOn:aStream base:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1841
    "append my printstring in any number base to aStream.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1842
     The radix argument should be between 2 and 36."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1843
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1844
    aStream nextPutAll:(self printStringRadix:radix)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1845
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1846
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1847
printString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1848
    "return my printstring (base 10)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1849
68
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  1850
    "since printf knows pretty good how to do this,
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  1851
     here is an exception to the rule of basing printString
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  1852
     upon the printOn: method."
59faa75185ba *** empty log message ***
claus
parents: 62
diff changeset
  1853
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1854
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1855
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1856
    char buffer[30];
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1857
    OBJ newString;
369
claus
parents: 357
diff changeset
  1858
    /*
claus
parents: 357
diff changeset
  1859
     * actually only needed on sparc: since thisContext is
claus
parents: 357
diff changeset
  1860
     * in a global register, which gets destroyed by printf,
claus
parents: 357
diff changeset
  1861
     * manually save it here - very stupid ...
claus
parents: 357
diff changeset
  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
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1864
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  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
claus
parents: 357
diff changeset
  1868
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1869
    newString = __MKSTRING(buffer COMMA_SND);
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  1870
    if (newString != nil) {
305
26b092c71935 *** empty log message ***
claus
parents: 283
diff changeset
  1871
	RETURN (newString);
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  1872
    }
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  1873
%}.
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  1874
    ^ super printString
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1875
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1876
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1877
printStringRadix:radix
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1878
    "return my printstring (optimized for bases 16, 10 and 8)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1879
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1880
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1881
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1882
    char *format = (char *)0;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1883
    char buffer[30];
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1884
    OBJ newString;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1885
252
  1886
    if (__isSmallInteger(radix)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1887
	switch (__intVal(radix)) {
214
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1888
	    case 10:
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1889
		format = "%d";
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1890
		break;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1891
	    case 16:
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1892
		format = "%x";
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1893
		break;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1894
	    case 8:
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1895
		format = "%o";
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1896
		break;
2e4defd713f9 *** empty log message ***
claus
parents: 159
diff changeset
  1897
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1898
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1899
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1900
    if (format) {
379
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1901
	/*
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1902
	 * actually only needed on sparc: since thisContext is
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1903
	 * in a global register, which gets destroyed by printf,
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1904
	 * manually save it here - very stupid ...
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1912
	newString = __MKSTRING(buffer COMMA_SND);
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
  1913
	if (newString != nil) {
282
94f5c3a6230d *** empty log message ***
claus
parents: 252
diff changeset
  1914
	    RETURN (newString);
324
290cfb34ec93 *** empty log message ***
claus
parents: 314
diff changeset
  1915
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1916
    }
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1917
%}.
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1918
    "
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1919
     fall back for seldom used bases
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1920
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1921
    ^ super printStringRadix:radix
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1922
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1923
    "123 printStringRadix:16"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1924
    "123 printStringRadix:8"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1925
    "123 printStringRadix:2"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1926
    "123 printStringRadix:3"
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1927
    "123 printStringRadix:1"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1928
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1929
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1930
printfPrintString:formatString
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1931
    "non-portable, but sometimes useful.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1932
     return a printed representation of the receiver
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1933
     as specified by formatString, which is defined by the C-
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1934
     function 'printf'.
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1935
     No checking for string overrun - the resulting string 
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1936
     must be shorter than 256 chars or else ...
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1937
     This method is NONSTANDARD and may be removed without notice."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1938
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1939
%{  /* STACK: 400 */
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1940
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1941
    char buffer[256];
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1942
    OBJ s;
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1943
62
e1b4369c61fb *** empty log message ***
claus
parents: 50
diff changeset
  1944
    if (__isString(formatString)) {
379
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1945
	/*
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1946
	 * actually only needed on sparc: since thisContext is
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1947
	 * in a global register, which gets destroyed by printf,
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  1948
	 * manually save it here - very stupid ...
5b5a130ccd09 revision added
claus
parents: 370
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  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
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  1956
	s = __MKSTRING(buffer COMMA_SND);
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1957
	if (s != nil) {
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1958
	    RETURN (s);
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1959
	}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1960
    }
314
7581a5c57224 *** empty log message ***
claus
parents: 305
diff changeset
  1961
%}.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1962
    self primitiveFailed
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1963
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1964
    "123 printfPrintString:'%%d -> %d'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1965
    "123 printfPrintString:'%%6d -> %6d'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1966
    "123 printfPrintString:'%%x -> %x'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1967
    "123 printfPrintString:'%%4x -> %4x'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1968
    "123 printfPrintString:'%%04x -> %04x'"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1969
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1995
!SmallInteger methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1996
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1997
between:min and:max
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1998
    "return true if the receiver is less than or equal to the argument max
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  1999
     and greater than or equal to the argument min.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2000
     - reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2001
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2002
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2003
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2004
    if (__bothSmallInteger(min, max)) {
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2005
	REGISTER INT selfVal;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2006
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2007
	selfVal = __intVal(self);
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2008
	if (selfVal < __intVal(min)) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2009
	     RETURN ( false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2010
	}
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2011
	if (selfVal > __intVal(max)) {
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2012
	     RETURN ( false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2013
	}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2014
	RETURN ( true );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2015
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2016
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2017
.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2018
    (self < min) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2019
    (self > max) ifTrue:[^ false].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2020
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2021
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2022
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2023
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2024
    "return true, if the receiver is even"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2025
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2026
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2027
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2028
#ifdef POSITIVE_ADDRESSES
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2029
    RETURN ( ((INT)self & 1) ? false : true );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2030
#else    
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2031
    RETURN ( ((INT)self & ((INT)__MKSMALLINT(1) & ~TAG_INT)) ? false : true );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2032
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2033
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2034
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2035
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2036
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2037
    "return true, if the receiver is less than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2038
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2039
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2040
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2041
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2042
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2043
    RETURN ( (__intVal(self) < 0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2044
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2045
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2046
    RETURN ( ((INT)(self) < 0) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2047
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2048
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2049
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2050
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2051
odd
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2052
    "return true, if the receiver is odd"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2053
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2054
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2055
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2056
#ifdef POSITIVE_ADDRESSES
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2057
    RETURN ( ((INT)self & 1) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2058
#else    
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2059
    RETURN ( ((INT)self & ((INT)__MKSMALLINT(1) & ~TAG_INT)) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2060
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2061
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2062
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2063
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2064
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2065
    "return true, if the receiver is not negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2066
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2067
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2068
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2069
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2070
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2071
    RETURN ( (__intVal(self) >= 0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2072
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2073
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2074
    RETURN ( ((INT)(self) >= 0) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2075
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2076
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2077
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2078
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2079
sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2080
    "return the sign of the receiver
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2081
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2082
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2083
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2084
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2085
    INT val = __intVal(self);
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2086
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2087
    if (val < 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2088
	RETURN ( __MKSMALLINT(-1) ); 
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2089
    }
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2090
    if (val > 0) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2091
	RETURN ( __MKSMALLINT(1) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2092
    }
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2093
    RETURN ( __MKSMALLINT(0) );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2094
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2095
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2096
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2097
strictlyPositive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2098
    "return true, if the receiver is greater than zero
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2099
     reimplemented here for speed"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2100
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2101
%{  /* NOCONTEXT */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2102
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2103
#ifdef POSITIVE_ADDRESSES
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1036
diff changeset
  2104
    RETURN ( (__intVal(self) > 0) ? true : false );
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2105
#else
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2106
    /* tag bit does not change sign */
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2107
    RETURN ( ((INT)(self) > 0) ? true : false );
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2108
#endif
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2109
%}
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2110
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2113
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2114
version
1889
304e3857f0d6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1884
diff changeset
  2115
    ^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.61 1996-11-05 18:25:59 cg Exp $'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 587
diff changeset
  2116
! !