mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Add implementation for is_odd()
(#79)
in dalek-ff-group Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
parent
169d5e26ca
commit
a58b3a133c
1 changed files with 12 additions and 1 deletions
|
@ -117,7 +117,7 @@ impl PrimeField for FieldElement {
|
||||||
|
|
||||||
const S: u32 = 2;
|
const S: u32 = 2;
|
||||||
fn is_odd(&self) -> Choice {
|
fn is_odd(&self) -> Choice {
|
||||||
unimplemented!()
|
(self.to_repr()[0] & 1).into()
|
||||||
}
|
}
|
||||||
fn multiplicative_generator() -> Self {
|
fn multiplicative_generator() -> Self {
|
||||||
2u64.into()
|
2u64.into()
|
||||||
|
@ -159,6 +159,17 @@ impl FieldElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
fn test_is_odd() {
|
||||||
|
assert_eq!(0, FieldElement::zero().is_odd().unwrap_u8());
|
||||||
|
assert_eq!(1, FieldElement::one().is_odd().unwrap_u8());
|
||||||
|
assert_eq!(0, FieldElement::one().double().is_odd().unwrap_u8());
|
||||||
|
|
||||||
|
// 0 is even, yet the modulus is odd
|
||||||
|
// -1 moves to the even value before the modulus
|
||||||
|
assert_eq!(0, (-FieldElement::one()).is_odd().unwrap_u8());
|
||||||
|
assert_eq!(1, (-FieldElement::one().double()).is_odd().unwrap_u8());
|
||||||
|
}
|
||||||
|
|
||||||
fn test_edwards_d() {
|
fn test_edwards_d() {
|
||||||
let a = -FieldElement(U256::from_u32(121665));
|
let a = -FieldElement(U256::from_u32(121665));
|
||||||
let b = FieldElement(U256::from_u32(121666));
|
let b = FieldElement(U256::from_u32(121666));
|
||||||
|
|
Loading…
Reference in a new issue