You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Outside of NaN, I expect float values to equal themselves.
The panic message is confusing, because there's no obvious difference between the values.
If you instead compare value.value, or value.get::<foot>(), etc. the test passes.
I looked into Quantity's PartialEq implementation, and saw that it calls change_base on the right operand to handle the fact that the operand types can have different U parameters. change_base looks like this:
Essentially since I'm not using metric units, we end up having something that looks like this:
// 0.3048 being the ft -> m conversion factorself.value*0.3048 / 0.3048* ...
These operations don't cancel out due to floating point error, so we end up with a different value, hence the assertion failure.
I'm not sure what uom could do to handle this better, but it is unfortunate that these conversions have to happen at all when comparing values in the same unit system. There's probably a performance overhead to that as well?
Worth mentioning that disabling the autoconvert feature fixes this since the code for handling mixed base units is stripped out, though the downside to that solution is that it can easily be broken by feature unification.
I have the following code, which defines a foot/pound/second system of units:
My expectation is that the test will pass, as
value
should be equal to itself.Instead, I get the following error:
This is surprising because:
value.value
, orvalue.get::<foot>()
, etc. the test passes.I looked into Quantity's
PartialEq
implementation, and saw that it callschange_base
on the right operand to handle the fact that the operand types can have differentU
parameters.change_base
looks like this:Essentially since I'm not using metric units, we end up having something that looks like this:
These operations don't cancel out due to floating point error, so we end up with a different value, hence the assertion failure.
I'm not sure what uom could do to handle this better, but it is unfortunate that these conversions have to happen at all when comparing values in the same unit system. There's probably a performance overhead to that as well?
uom version: 0.36.0
I have a minimal repro of the issue here: https://github.com/nsunderland1/uom-partialeq
The text was updated successfully, but these errors were encountered: