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
952 stars 135 forks source link

Fix streaming of ephemeral units of integer underlying type #163

Closed JohelEGP closed 6 years ago

JohelEGP commented 6 years ago

When the conversion to the base unit is lossy, it is a compile-time error. This solution might incur accuracy loss as the unit is converted to a base unit of double underlying type.

Any idea on how to avoid the accuracy loss?

nholthaus commented 6 years ago

Ideally lossy conversions would result in warnings rather than compile-time errors (mimicking existing c++ behavior). Nothing obvious springs to mind, but I'll play with it.

JohelEGP commented 6 years ago

The streaming operator for ephemeral units streams coherent derived unit.

Printing an object of type unit<millimeter, int> fails to compile because converting to its coherent form of type unit<meter, int> is lossy.