mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +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:
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user