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

Unable to clamp quantity to a range. #440

Closed
DJDuque opened this issue Sep 12, 2023 · 2 comments
Closed

Unable to clamp quantity to a range. #440

DJDuque opened this issue Sep 12, 2023 · 2 comments

Comments

@DJDuque
Copy link

DJDuque commented Sep 12, 2023

I am not sure if this is the expected behavior, but the following fails for me (I would expect it to work):

use uom::si::angle::radian;
use uom::si::f64::Angle;

fn main() {
    let x = Angle::new::<radian>(5.0);
    let clamped = x.clamp(-Angle::HALF_TURN, Angle::HALF_TURN);
}

I am not very familiar with the code under the hood, but looking here it looks like this should work (?).

@DJDuque
Copy link
Author

DJDuque commented Sep 12, 2023

Ok, I just noticed that what I linked requires V (in this case f64) to implement the Ord trait. Now I understand why it doesn't work.

Maybe it is worth adding this as a separate method (?) given that the clamp method does exist for f64. Maybe it could be useful for some people

@iliekturtles
Copy link
Owner

Closing as a duplicate of #239. There is a draft PR in #377 but it hasn't gotten past the draft stage unfortunately.

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