Skip to content

Use in_place suffix for BigInteger operations #781

Open
@tcoratger

Description

In the whole codebase, there is a standard which is to include the suffix in_place on operations which modify the value passed as a mutable parameter. For example here:

fn double_in_place(&mut self, two_inv: &P::Fp) -> EllCoeff<P> {
// Formula for line function when working with
// homogeneous projective coordinates.
let mut a = self.x * &self.y;
a.mul_assign_by_fp(two_inv);
let b = self.y.square();
let c = self.z.square();
let e = P::G2Config::COEFF_B * &(c.double() + &c);
let f = e.double() + &e;
let mut g = b + &f;
g.mul_assign_by_fp(two_inv);
let h = (self.y + &self.z).square() - &(b + &c);
let i = e - &b;
let j = self.x.square();
let e_square = e.square();
self.x = a * &(b - &f);
self.y = g.square() - &(e_square.double() + &e_square);
self.z = b * &h;
match P::TWIST_TYPE {
TwistType::M => (i, j.double() + &j, -h),
TwistType::D => (-h, j.double() + &j, i),
}
}

We know from the function name that the self mutable will be modified.

However similar operations are performed in the BigInteger trait like:

fn mul2(&mut self) -> bool;

or

fn sub_with_borrow(&mut self, other: &Self) -> bool;

without including the in_place suffix. For readability and consistency, it could be nice to include this suffix for all the BigInteger operations concerned by this type of logic.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions