bernedom / SI

A header only C++ library that provides type safety and user defined literals for physical units
https://si.dominikberner.ch/doc/
MIT License
486 stars 40 forks source link

Integer reps perform truncating conversions without warning #122

Closed chiphogg closed 1 year ago

chiphogg commented 1 year ago

Describe the bug Unit conversions which divide the underlying value by some integer are accepted without complaint for integer reps.

To Reproduce Steps to reproduce the behavior:

SI::length_t<int, std::ratio<1>> x{3};
SI::length_t<int, std::ratio<12>> y = x;
std::cout << "x = " << x << "; y = " << y << "!\n";

For me, this prints:

x = 3 m; y = 0 m!

Expected behavior This should be a compiler error. If the rep is integral, we should only permit conversions which multiply by an integer, since these will stay in the domain of the integers.

Screenshots N/A

Desktop (please complete the following information):

Smartphone (please complete the following information): N/A

Additional context N/A

chiphogg commented 1 year ago

On looking closer, I see that this behaviour is covered in both documentation and unit tests. So I'll close this issue as "working as intended".