JuliaPhysics / JuliaPhysics/Unitful.jl

Multiplication of gains is problematic

Open
#461 1 comment 0 reactions 0 assignees View on GitHub
logarithmic
Dominant language
Julia
Stars
675
Forks
124
Avg merge
3h 38m
Merged PRs (30d)
1

Description

Multiplication between `Gain`s is defined to be the same as addition:

```
julia> 2dB + 5dB
7 dB

julia> 2dB * 5dB
7 dB
```

I think this is somewhat problematic. Multiplication is supposed to be commutative/associative, which this is not:
```
julia> 2 * 5 * (dB * dB)
ERROR: ArgumentError: cannot multiply logarithmic units together.
Stacktrace:
[1] *(#unused#::Unitful.MixedUnits{Gain{Unitful.LogInfo{:Decibel, 10, 10}, :?, T} where T<:Real, Unitful.FreeUnits{(), NoDims, nothing}}, #unused#::Unitful.MixedUnits{Gain{Unitful.LogInfo{:Decibel, 10, 10}, :?, T} where T<:Real, Unitful.FreeUnits{(), NoDims, nothing}})
@ Unitful ~/.julia/packages/Unitful/0oqX5/src/logarithm.jl:102
[2] top-level scope
@ REPL[25]:1
```

I can see why this is convenient, but the `*` generic function really is supposed to behave like multiplication. If you're using a logarithmic scale, use the addition functions. @sostock you seem to have been the last person to touch this code extensively, thoughts?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.