Unitful.jl icon indicating copy to clipboard operation
Unitful.jl copied to clipboard

Kelvin and °C should not be comparable?

Open cstjean opened this issue 2 years ago • 2 comments

Currently,

julia> 5K - 5°C
ERROR: AffineError: an invalid operation was attempted with affine quantities: 5 K - 5 °C

which is great because it's ambiguous, but

julia> 10°C - 5°C > 2°C
false

This is clearly wrong for anyone who doesn't know about Unitful quirks, and it just bit one of my colleagues. In this case, 10°C - 5°C becomes 5K, which is considered less than 2°C because 2°C == 275 K.

Thus, Kelvin and °C comparisons should be an AffineError.

cstjean avatar Feb 17 '22 15:02 cstjean

One possible issue here is that there are times you would want to compare values in Kelvin and °C - for instance, if you've got a series of inputs to something in a mix of both, or simply if you've got values in both. It might actually be worth rethinking how affine units are thought of in general, actually - I would say that a difference between two affine values, say 200 K - 150 K, should probably not be comparable to an affine value on its own, but affine values in differing units, but the same dimension, should still be comparable, though I'm not sure if there's any good way to implement this.

lukebemish avatar Feb 24 '22 04:02 lukebemish