paholg / dimensioned

Compile-time dimensional analysis for various unit systems using Rust's type system.
https://crates.io/crates/dimensioned
MIT License
300 stars 23 forks source link

Add support for absolute values #40

Closed droundy closed 6 years ago

droundy commented 6 years ago

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 commented 6 years ago

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

https://github.com/paholg/dimensioned/blob/a9468936de7959cb24587fa96da5c96d79e184f6/src/traits.rs#L156-L166

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 commented 6 years ago

Closed by #41.