Unitful.jl
Unitful.jl copied to clipboard
Negating Gains
Is it intentional that this works (-2u"dB"
), and this works (0u"dB" - 2u"dB"
) but not this (-(2u"dB")
) nor (-uconvertp(u"dB", 2)
) nor this (-uconvertrp(u"dB", 2)
)?
It’s probably not intentional. If addition is well-defined, negation should work as well.
Maybe it just needs an extra line like -(x<:Gain) = inv(x)
?
Also, multiplying a Gain by a number works but dividing doesnt.
This is less related but, ustrip(dB, 2dB) doesnt work, while ustrip(uconvert(dB, 2dB)) does. Maybe the former should return the same as the latter?
Also, maybe the definition for converting to types of floats for quantities ((Base.$f)(x::AbstractQuantity) = Quantity($f(x.val), unit(x))
in quantities.jl lines 436-445) should extend to log units too. Right now, one can't do e.g. Float16(2dB)