Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong conversion from dimensionless Quantity to Gain #726

Open
sostock opened this issue May 31, 2024 · 2 comments
Open

Wrong conversion from dimensionless Quantity to Gain #726

sostock opened this issue May 31, 2024 · 2 comments
Labels
bug logarithmic logarithmic scales (decibels, nepers, …)

Comments

@sostock
Copy link
Collaborator

sostock commented May 31, 2024

using convert:

julia> convert(typeof(1.0u"dB_rp"), 100.0) # correct
40.0 dB

julia> convert(typeof(1.0u"dB_rp"), 1.0u"m/cm") # this should be the same, because 1m/cm == 100
100.0 dB

using uconvert:

julia> uconvert(u"dB_rp", 100.0) # correct
40.0 dB

julia> uconvert(u"dB_rp", 1.0u"m/cm") # a _different_ wrong result
0.0 dB
@sostock sostock added bug logarithmic logarithmic scales (decibels, nepers, …) labels May 31, 2024
@sostock
Copy link
Collaborator Author

sostock commented May 31, 2024

The other direction works correctly for both convert and uconvert:

julia> convert(Float64, 40.0u"dB_rp")
100.0

julia> convert(typeof(1.0u"m/cm"), 40.0u"dB_rp")
1.0 m cm^-1
julia> uconvert(NoUnits, 40.0u"dB_rp")
100.0

julia> uconvert(u"m/cm", 40.0u"dB_rp")
1.0 m cm^-1

@sostock
Copy link
Collaborator Author

sostock commented May 31, 2024

Mixed units are interesting as well:

julia> convert(typeof(1.0u"dB_p/s"), 1.0u"dB_p/s")
[1.0 dB] s^-1

julia> convert(typeof(1.0u"dB_p/s"), 1u"dB_p/s")
[1.2589254117941673 dB] s^-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug logarithmic logarithmic scales (decibels, nepers, …)
Projects
None yet
Development

No branches or pull requests

1 participant