nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
947 stars 135 forks source link

Support for equivalent units #223

Open simonvpe opened 5 years ago

simonvpe commented 5 years ago

The following code calculates the angular acceleration when applying torque to a body with a given rotational inertia. However, the resulting unit [N/(kg*m)] should be convertible to [rad/s^2]. What support is there for this in the library?

using kilogram_meters_squared_t = decltype(1.0_kg * 1.0_sq_m);
using radians_per_second_squared_t = decltype(1.0_rad / 1.0_s / 1.0_s);

const kilogram_meters_squared_t inertia = kilogram_meters_squared_t{1.0};
const newton_meter_t torque = 1.0_Nm;

// Conversion should happen automatically
const radians_per_second_squared_t angular_acc{(torque / inertia).to<float>()};