Beware of `preferunits`
j-fu opened this issue ยท 1 comments
preferunits allows to change the preferred units such that they will deviate from the default SI base units:
julia> using DynamicQuantities, Unitful
julia> Unitful.preferunits(u"km")
julia> convert(DynamicQuantities.Quantity,3u"km")
3 ๐ ยน
I think users shall be made aware of this possibility.
In LessUnitful.jl I tried to provide an API function to allow a consistency check.
Thanks for the notice. The intention of upreferred
was for instances like this to be a feature rather than a bug, so users could change the standardized form we convert to before performing calculations. But I just took a look and it seems like in fact due to how upreferred
works, your example points out a bug:
julia> using DynamicQuantities, Unitful
julia> Unitful.preferunits(u"km")
julia> convert(DynamicQuantities.Quantity,3u"km")
3 ๐ ยน
julia> convert(Unitful.Quantity, convert(DynamicQuantities.Quantity,3u"km"))
3 m
So I guess upreferred
should always be called within the conversion function, rather than to define a global conversion constant as is being done right now.