Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DrunkenRandomWalker opened this issue May 3, 2022 · 0 comments

Comments

@DrunkenRandomWalker
Copy link
Collaborator

#[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,
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant