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#
| Name | Description |
|---|---|
rem | Returns 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);
}