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

Add support for absolute values #40

Closed
droundy opened this issue Jun 22, 2018 · 2 comments
Closed

Add support for absolute values #40

droundy opened this issue Jun 22, 2018 · 2 comments

Comments

@droundy
Copy link
Contributor

droundy commented Jun 22, 2018

It would be lovely to be able to take the absolute value of a dimensioned number. I am not sure how to do this best, but would be happy to work on a pull request. Sadly, abs does not seem to be in a trait in the standard library, so we'd need specific implementations for basically every primitive type as far as I can see?

@paholg
Copy link
Owner

paholg commented Jun 24, 2018

That would be great. Yeah, the only way I could see it is creating the trait and implementing it for all primitives.

You can see an example of this in Recip

dimensioned/src/traits.rs

Lines 156 to 166 in a946893

pub trait Recip {
/// The resulting type after taking the reciprocal
type Output;
/// The method for taking the reciprocal
fn recip(self) -> Self::Output;
}
impl_unary!(f32, Recip, recip);
impl_unary!(f64, Recip, recip);

Abs probably doesn't need the associated type Output. That is, unless we want to support types that change under absolute value. I can't think of what those would be outside of typenum, unless we wanted to do something like have i32::abs() return a u32, but that is probably not useful.

@paholg
Copy link
Owner

paholg commented Jun 25, 2018

Closed by #41.

@paholg paholg closed this as completed Jun 25, 2018
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