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

Generic parameter for unit's underlying float #51

Open
tower120 opened this issue Mar 31, 2022 · 1 comment
Open

Generic parameter for unit's underlying float #51

tower120 opened this issue Mar 31, 2022 · 1 comment

Comments

@tower120
Copy link

Is it possible to make something like Mass<T=f64> instead of just Mass?

For example, I would like to work with f32 precision mass, volume, etc...

@sunsided
Copy link

sunsided commented Jun 16, 2023

I tried to give that a spin here using num-traits constrained generics but it ended up in one difficult spot: When T can be anything, the automatically implemented commutative implementations for Mul and Add fail, particularly with Duration:

impl<T: num_trait::Float> Mul<T> for Duration and impl<T: num_trait::Float> Mul<Duration> for T cannot coexist because a user of the create may implement num_trait::Float for Duration, leading to a conflicting trait implementation. That's blocked by RFC 1210.

Resolving this by making operations non-commutative could work, but then the specializations for f64 would have to be implemented manually.

I also thought of feature-gating the implementation, defaulting to <f64> specializations if generic types are not wished for - that's a bridge to be crossed once I'm there.

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