snarkVM icon indicating copy to clipboard operation
snarkVM copied to clipboard

Introduce integer `is_*` helpers

Open howardwu opened this issue 3 years ago • 0 comments

If we introduce is_negative and is_positive trait methods, we can further reduce the cost of these self.is_less_than(&Self::zero()) checks.

For signed cases, we can inspect that self.msb().is_one() when I::is_signed() for is_negative, and noop for !I::is_signed(). A similar case can be done for is_positive.

In Rust (and in math), 0 is neither positive nor negative. So we do need to perform a .fold() to ensure the case that all bits are 0 is false for is_positive.

Originally posted by @howardwu in https://github.com/AleoHQ/snarkVM/pull/876#discussion_r922655083

howardwu avatar Jul 18 '22 11:07 howardwu