ff: PrimeField::{is_even, is_odd}

This commit is contained in:
Jack Grigg
2020-04-21 19:05:19 +12:00
parent 232f0a50b8
commit 1fdca393bb
10 changed files with 54 additions and 8 deletions

View File

@@ -1029,6 +1029,11 @@ fn prime_field_impl(
r.0
}
#[inline(always)]
fn is_odd(&self) -> bool {
self.into_repr().is_odd()
}
fn char() -> #repr {
MODULUS
}

View File

@@ -309,6 +309,15 @@ pub trait PrimeField: Field + From<u64> {
/// the number is an element of the field.
fn into_repr(&self) -> Self::Repr;
/// Returns true iff this element is odd.
fn is_odd(&self) -> bool;
/// Returns true iff this element is even.
#[inline(always)]
fn is_even(&self) -> bool {
!self.is_odd()
}
/// Returns the field characteristic; the modulus.
fn char() -> Self::Repr;