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

Generate Conversion<V> implementations to return literals #60

Open
iliekturtles opened this issue Mar 28, 2018 · 0 comments
Open

Generate Conversion<V> implementations to return literals #60

iliekturtles opened this issue Mar 28, 2018 · 0 comments
Milestone

Comments

@iliekturtles
Copy link
Owner

iliekturtles commented Mar 28, 2018

Generate impls using some kind of compile-time calculation: custom derive, build.rs, const fn? Currently all conversion factors go through f64 which may have run-time costs and causes imprecision issues where the conversion factor can be exactly represented as Self::T but not as f64. Also see #40 regarding conversion factors that can't be represented.

For example the Conversion<V> implementation for primitive integer and BigInt types uses Self::T::from_f64:

fn conversion() -> Self::T {
    Self::T::from_f64($conversion).unwrap()
}

Ideally the method should be generated to return a pre-calculated literal for each type:

fn conversion() -> Self::T {
    Self::T::new_raw(10, 1) // assuming Self::T is Ratio<V>.
}
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