Neg
trait Neg<T>
Source: compiler/src/builtin_docs/prelude/ops.hy The unary negation operator -x.
-x on a type with a Neg instance calls neg(x). int and float
have builtin instances; negating the smallest int panics with
integer overflow.
Required methods#
| Name | Description |
|---|---|
neg | Returns -a. |
Examples#
use tests::assert;
class V2 {
pub x: int,
pub y: int,
}
impl Neg for V2 {
pub fn neg(V2 a) -> V2 {
return new V2(-a.x, -a.y);
}
}
fn main() {
let n = -new V2(1, -2);
assert!(n.x == -1);
assert!(n.y == 2);
}