Make Field::double take &self and return Self

This commit is contained in:
Jack Grigg
2019-12-12 22:59:18 +00:00
parent 91c32f1c7c
commit 9dac748224
23 changed files with 87 additions and 111 deletions

View File

@@ -1040,12 +1040,16 @@ fn prime_field_impl(
}
#[inline]
fn double(&mut self) {
fn double(&self) -> Self {
let mut ret = *self;
// This cannot exceed the backing capacity.
self.0.mul2();
ret.0.mul2();
// However, it may need to be reduced.
self.reduce();
ret.reduce();
ret
}
fn inverse(&self) -> Option<Self> {

View File

@@ -54,7 +54,8 @@ pub trait Field:
fn square(&mut self);
/// Doubles this element.
fn double(&mut self);
#[must_use]
fn double(&self) -> Self;
/// Computes the multiplicative inverse of this element, if nonzero.
fn inverse(&self) -> Option<Self>;