number_theory/arithmetic/
sign.rs

1
2/// Enum representing the sign
3#[derive(PartialEq, Clone,Copy, Debug, Default)]
4pub enum Sign {
5   /// N >= 0 representation
6    #[default]
7    Positive,
8   /// N <  0 representation 
9    Negative,
10}
11
12impl Sign {
13    pub(crate) fn neg(&self) -> Sign {
14        match self {
15            Sign::Positive => Sign::Negative,
16            Sign::Negative => Sign::Positive,
17        }
18    }
19
20    pub(crate) fn mul(&self, other: &Sign) -> Sign {
21        match (self, other) {
22            (&Sign::Positive, &Sign::Negative) => Sign::Negative,
23            (&Sign::Negative, &Sign::Positive) => Sign::Negative,
24            _ => Sign::Positive,
25        }
26    }
27
28    pub(crate) fn _pow(&self, y: u64) -> Sign {
29        if self == &Sign::Negative && y % 2 == 1 {
30            Sign::Negative
31        } else {
32            Sign::Positive
33        }
34    }
35    
36 ///   To boolean for FFI
37    pub fn ffi(&self) -> bool{
38       match self{
39         Sign::Negative => true,
40         Sign::Positive => false,
41       }
42    }
43  /// From boolean FFI  
44    pub fn from_ffi(x: bool) -> Self{
45    match x{
46        true => Sign::Negative,
47        false => Sign::Positive,
48        }
49    }
50}