--- a/SmallInteger.st Fri Aug 25 10:39:27 2017 +0200
+++ b/SmallInteger.st Fri Aug 25 12:31:37 2017 +0200
@@ -1866,9 +1866,9 @@
"return the value of the receiver shifted by shiftCount bits;
right shift if shiftCount > 0; left shift otherwise.
Notice: the result of bitShift: on negative receivers is not
- defined in the language standard (since the implementation
- is free to choose any internal representation for integers).
- However, ST/X preserves the sign."
+ defined in the language standard (since the implementation
+ is free to choose any internal representation for integers).
+ However, ST/X preserves the sign."
%{ /* NOCONTEXT */
#ifdef __SCHTEAM__
@@ -1876,76 +1876,81 @@
INT bits, count;
if (__isSmallInteger(shiftCount)) {
- bits = __intVal(self);
- if (bits == 0) {
- RETURN (self);
- }
-
- count = __intVal(shiftCount);
-
- if (count < 0) {
- /*
- * a left shift
- */
- count = -count;
+ bits = __intVal(self);
+ if (bits == 0) {
+ RETURN (self);
+ }
+
+ count = __intVal(shiftCount);
+
+ if (count < 0) {
+ /*
+ * a left shift
+ */
+ count = -count;
# if defined(USE_LONGLONG_FOR_SHIFT)
- if (count <= N_INT_BITS) {
- unsigned LONGLONG result;
-
- result = (unsigned LONGLONG)bits;
- result <<= count;
- if (result <= _MAX_INT) {
- RETURN ( __mkSmallInteger(result) );
- }
- {
- RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
- }
- }
+ if (count <= N_INT_BITS) {
+ unsigned LONGLONG result;
+
+ result = (unsigned LONGLONG)bits;
+ result <<= count;
+ if (result <= _MAX_INT) {
+ RETURN ( __mkSmallInteger(result) );
+ }
+ {
+ RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF)));
+ }
+ }
# else
- /*
- * check for overflow
- */
- if (count < (N_INT_BITS-1)) {
- if (! (bits >> (N_INT_BITS - 1 - count))) {
- RETURN ( __mkSmallInteger(bits << count) );
- }
- /*
- * so, there is an overflow ...
- * handle it as largeInteger
- */
- /* FALL THROUGH */
- }
+ /*
+ * check for overflow
+ */
+ if (count < (N_INT_BITS-1)) {
+ if (! (bits >> (N_INT_BITS - 1 - count))) {
+ RETURN ( __mkSmallInteger(bits << count) );
+ }
+ /*
+ * so, there is an overflow ...
+ * handle it as largeInteger
+ */
+ /* FALL THROUGH */
+ }
# endif
- } else {
- if (count == 0) {
- RETURN (self);
- }
-
- /*
- * right shifts cannot overflow
- *
- * some machines ignore shifts bigger than
- * the number of bits in an int ...
- */
- if (count > (N_INT_BITS-1)) {
- RETURN (__mkSmallInteger(0));
- }
-
- RETURN ( __mkSmallInteger(bits >> count) );
- }
+ } else {
+ if (count == 0) {
+ RETURN (self);
+ }
+
+ /*
+ * right shifts cannot overflow
+ *
+ * some machines ignore shifts bigger than
+ * the number of bits in an int ...
+ */
+ if (count > (N_INT_BITS-1)) {
+ RETURN (__mkSmallInteger(0));
+ }
+
+ RETURN ( __mkSmallInteger(bits >> count) );
+ }
}
#endif /* not __SCHTEAM__ */
%}.
(shiftCount isMemberOf:SmallInteger) ifTrue:[
- ^ (LargeInteger value:self) rightShift:shiftCount
+ ^ (LargeInteger value:self) rightShift:shiftCount
].
^ self rightShift:shiftCount asInteger "/ is this a good idea ?
"
- 16 rightShift:2
- 4 rightShift:-2
+ 16 rightShift:2
+ -16 rightShift:2
+
+ 4 rightShift:-2
+ -4 rightShift:-2
"
+
+ "Modified: / 25-08-2017 / 12:30:42 / cg"
! !
!SmallInteger methodsFor:'bit operators - indexed'!