Documentation Index
Fetch the complete documentation index at: https://docs.starknet.io/llms.txt
Use this file to discover all available pages before exploring further.
The unary negation operator -.
Signature
Examples
An implementation of Neg for Sign, which allows the use of - to
negate its value.
#[derive(Copy, Drop, PartialEq)]
enum Sign {
Negative,
Zero,
Positive,
}
impl SignNeg of Neg {
fn neg(a: Sign) -> Sign {
match a {
Sign::Negative => Sign::Positive,
Sign::Zero => Sign::Zero,
Sign::Positive => Sign::Negative,
}
}
}
// A negative positive is a negative
assert!(-Sign::Positive == Sign::Negative);
// A double negative is a positive
assert!(-Sign::Negative == Sign::Positive);
// Zero is its own negation
assert!(-Sign::Zero == Sign::Zero);
Trait functions
neg
Performs the unary - operation.
Signature
Examples
let x: i8 = 1;
assert!(-x == -1);