Trait in prelude::ops auto-imported

Shr

trait Shr<T>
Source: compiler/src/builtin_docs/prelude/ops.hy

The right shift operator >>.

a >> n on a type with a Shr instance calls shr(a, n). The shift count is always an int. int and byte have builtin instances; the int shift is arithmetic (it keeps the sign, so -8 >> 1 is -4).

Required methods#

NameDescription
shrReturns a shifted right by n bits.

Examples#

use tests::assert;
class Flags {
    pub bits: int,
}

impl Shr for Flags {
    pub fn shr(Flags a, int n) -> Flags {
        return new Flags(a.bits >> n);
    }
}

fn main() {
    let f = new Flags(32) >> 2;
    assert!(f.bits == 8);
    assert!(-8 >> 1 == -4);
}

See also#

  • int
  • byte
  • Add: The addition operator +.
  • Sub: The subtraction operator -.
  • Mul: The multiplication operator *.
  • Div: The division operator /.
  • Neg: The unary negation operator -x.
  • Rem: The remainder operator %.
↑ ↓ navigate ↵ open