Trait in prelude::ops auto-imported

Rem

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

The remainder operator %.

a % b on a type with a Rem instance calls rem(a, b). int and float have builtin instances. The int result has the sign of a (-7 % 2 is -1) and % 0 panics with division by zero.

Required methods#

NameDescription
remReturns the remainder of a / b.

Examples#

use tests::assert;
class Hours {
    pub h: int,
}

impl Rem for Hours {
    pub fn rem(Hours a, Hours b) -> Hours {
        return new Hours(a.h % b.h);
    }
}

fn main() {
    let t = new Hours(27) % new Hours(24);
    assert!(t.h == 3);
    assert!(-7 % 2 == -1);
}

See also#

  • int
  • float
  • Add: The addition operator +.
  • Sub: The subtraction operator -.
  • Mul: The multiplication operator *.
  • Div: The division operator /.
  • Neg: The unary negation operator -x.
  • Pow: The exponentiation operator **.
↑ ↓ navigate ↵ open