iliekturtles / uom

Units of measurement -- type-safe zero-cost dimensional analysis
Apache License 2.0
1.03k stars 97 forks source link

Support for a Unitless #176

Closed jkelleyrtp closed 4 years ago

jkelleyrtp commented 4 years ago

My formula follows something like sqrt( 1 - (...)). I don't see a documented way to generate the 1 with a unitless unit. My workaround is

let u1 = Length::new::<kilometer>(1.0)/Length::new::<kilometer>(1.0);

and then using u1 as it were 1 but this is an ugly workaround. I'm not even sure how to make this const because I don't know the units of u1.

iliekturtles commented 4 years ago

The short answer is you can use ratio with a measurement unit of ratio for unit-less quantities.

Can you provide more details about your formula? The need to create a unit-less constant is odd What's in the (...)?

jkelleyrtp commented 4 years ago

I'm making an orbital mechanics calculator and 1- and + 1 show up very frequently. It's not terribly unusual to find reduced formulas of PDEs/ODEs/trig that involve unit constants.

http://www.braeunig.us/space/orbmech.htm

These tend to be intermediate steps and I would prefer not have to derive the units on the constant, even if there aren't any.

It's not entirely clear to me on how to make a new Ratio, can you provide an example?

iliekturtles commented 4 years ago

Here's a simple example. If this isn't working for you could you provide a minimal example of what you're trying to do.

extern crate uom;

use uom::si::f32::*;
use uom::si::ratio::ratio;

fn main() {
    let _ratio = Ratio::new::<ratio>(1.0);
}
jkelleyrtp commented 4 years ago

Awesome, thanks for the example. That should do the trick.