operator >> method Null safety

  1. @override
Int64 operator >>(
  1. int n
)
override

Right bit-shift operator.

Returns the result of shifting the bits of this integer by shiftAmount bits to the right. High-order bits are filled with zero in the case where this integer is positive, or one in the case where it is negative.

Implementation

@override
Int64 operator >>(int n) {
  if (n < 0) {
    throw ArgumentError.value(n);
  }
  if (n >= 64) {
    return isNegative ? const Int64._bits(_MASK, _MASK, _MASK2) : ZERO;
  }

  int res0, res1, res2;

  // Sign extend h(a).
  int a2 = _h;
  bool negative = (a2 & _SIGN_BIT_MASK) != 0;
  if (negative && _MASK > _MASK2) {
    // Add extra one bits on the left so the sign gets shifted into the wider
    // lower words.
    a2 += (_MASK - _MASK2);
  }

  if (n < _BITS) {
    res2 = _shiftRight(a2, n);
    if (negative) {
      res2 |= _MASK2 & ~(_MASK2 >> n);
    }
    res1 = _shiftRight(_m, n) | (a2 << (_BITS - n));
    res0 = _shiftRight(_l, n) | (_m << (_BITS - n));
  } else if (n < _BITS01) {
    res2 = negative ? _MASK2 : 0;
    res1 = _shiftRight(a2, n - _BITS);
    if (negative) {
      res1 |= _MASK & ~(_MASK >> (n - _BITS));
    }
    res0 = _shiftRight(_m, n - _BITS) | (a2 << (_BITS01 - n));
  } else {
    res2 = negative ? _MASK2 : 0;
    res1 = negative ? _MASK : 0;
    res0 = _shiftRight(a2, n - _BITS01);
    if (negative) {
      res0 |= _MASK & ~(_MASK >> (n - _BITS01));
    }
  }

  return Int64._masked(res0, res1, res2);
}