Skip to content

Pass values by reference for FPDecimal methods, and associate functions #26

Description

@DrunkenRandomWalker
#[allow(clippy::upper_case_acronyms)]
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, JsonSchema)]
pub struct FPDecimal {
    #[schemars(with = "String")]
    pub num: U256,
    pub sign: i8,
}

FPDecimal implemented Copy trait, parameter in associated functions in below are passed parameters by value. So values are copied, I think we are safe to pass parameters by reference, and copy when it is necessary.

pub fn _int(x: FPDecimal) -> FPDecimal {
let x1 = x.num;
let x1_1 = x1 / FPDecimal::ONE.num;
let x_final = x1_1 * FPDecimal::ONE.num;
FPDecimal { num: x_final, sign: x.sign }
}

pub fn _fraction(x: FPDecimal) -> FPDecimal {
let x1 = x.num;
FPDecimal {
num: x1 - FPDecimal::_int(x).num,
sign: x.sign,
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions