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

Negating Gains

Open anojo opened this issue 3 years ago • 5 comments

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))?

anojo avatar Mar 09 '21 17:03 anojo

It’s probably not intentional. If addition is well-defined, negation should work as well.

sostock avatar Mar 09 '21 18:03 sostock

Maybe it just needs an extra line like -(x<:Gain) = inv(x) ?

anojo avatar Mar 10 '21 02:03 anojo

Also, multiplying a Gain by a number works but dividing doesnt.

anojo avatar Mar 24 '21 18:03 anojo

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?

anojo avatar Mar 25 '21 04:03 anojo

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)

anojo avatar Apr 05 '21 20:04 anojo