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

time_calc.rs #12

Open
Tracked by #10
VladDrgm opened this issue Aug 26, 2021 · 4 comments
Open
Tracked by #10

time_calc.rs #12

VladDrgm opened this issue Aug 26, 2021 · 4 comments

Comments

@VladDrgm
Copy link
Owner

No description provided.

@VladDrgm VladDrgm mentioned this issue Aug 26, 2021
4 tasks
@VladDrgm
Copy link
Owner Author

VladDrgm commented Sep 2, 2021

Cannot find logarithm functions in the Rust crates. They are needed in order to solve this, as the formula for time calculation is

t = ln(A/P) / n[ln(1 + r/n)], where ln = natural logarithm

@boorich
Copy link
Collaborator

boorich commented Sep 2, 2021

Would a macro like this help you:

macro_rules! log_of {
    ($val:expr, $base:expr, $type:ty) => {
         ($val as f32).log($base) as $type
    }
}

fn main() {
    println!("{}", log_of!(4096, 2., usize));
}

@VladDrgm
Copy link
Owner Author

VladDrgm commented Sep 2, 2021

made some changes. trying to use it.

macro_rules! log_of {
    ($val:expr, $base:expr, $type:ty) => {
         ($val as f32).log($base) as $type
    }
}

ln(A/P) would be log_of!(A/P, 2., usize) ?

@VladDrgm
Copy link
Owner Author

VladDrgm commented Sep 4, 2021

I think I managed to make it work.
Would like to test tying the commit to the issue so they both close automatically, which is why I'm not pull requesting now.

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

2 participants