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

global values #82

Open
lattice0 opened this issue Aug 25, 2021 · 0 comments
Open

global values #82

lattice0 opened this issue Aug 25, 2021 · 0 comments

Comments

@lattice0
Copy link

Iḿ struggling with performance because rust has no globlal variables and thus I have to parse them all the time in the code. Using lazy_static actually introduces some overhead. How to have fast constants for usage in code?

pub fn ln_halley(x: &BigDecimal, scale: i64) -> BigDecimal {
    //parsing this everytime is bad
    let epsilon = BigDecimal::from_f64(0.00000000000000001).unwrap();
    let mut y = x - &BigDecimal::one();
    let y_0 = y.clone();
    loop {
        //parsing "2" all the time here too
        y = &y + BigDecimal::from_u64(2).unwrap()*(x-&y.exp())/(x+y.exp());
        if (&y-&y_0).abs() < epsilon {
            break;
        }
    }
    y
}
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