decaf377/
sign.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::Fq;

pub trait Sign: core::ops::Neg<Output = Self> + Sized {
    fn is_nonnegative(&self) -> bool;

    fn is_negative(&self) -> bool {
        !self.is_nonnegative()
    }

    fn abs(self) -> Self {
        if self.is_nonnegative() {
            self
        } else {
            -self
        }
    }
}

impl Sign for Fq {
    fn is_nonnegative(&self) -> bool {
        (self.to_le_limbs()[0] & 1) == 0
    }
}