Improved handling of getting ints with units (safeguarding against future mistakes)
Generalised solution to the issue discovered and fixed in !1127 (merged)
The issue is that if one gets an int with a unit that is not an int in internal units, there is a rounding error. The proposed fix is to have a condition in the templated get
function, where it throws a runtime error if one tries to get a value in a way that doesn't actually return the provided value (e.g. Units::get(5, "um")
, which would previously return 0 instead of 0.005). A runtime error is not the nicest, but I couldn't find a way to do it at compile time.
The MR also contains the fixes for this bug that I found. It's a bit subtle though, so I might not have caught them all, but this will make it very obvious when one tries to use a default value or so wrongly. Since the tests pass, I think it's alright.