Skip to content

Support in-place negation/reciprocal operations #438

Open
@mozhewen

Description

@mozhewen

Big numbers are often stored in some data structure such as values of a BTreeMap. When I want to do some local change on the data structure, I usually get a &mut of the number. In this case, if I'm taking a neg(), a clone() of the number is needed, which is inefficient since it's essentially only a flip of sign. Similar for recip().

A new function like

fn set_neg(&mut self) {
    self.sign = -self.sign;
}

may be helpful. In fact, I even think it should be a method of the Neg trait.

Metadata

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