JuliaPhysics / JuliaPhysics/Unitful.jl

`Base.show(io::IO, x::Level)` error

Open
#766 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

Hi, thank you for this wonderful package!

Here's the thing, I can construct a `Level`:
```
y = Unitful.Level{Unitful.Decibel,1}(2);
```

But I can't show it:
```
julia> y
Error showing value of type Level{Unitful.LogInfo{:Decibel, 10, 10}, 1, Int64}:
ERROR: undefined behavior. Please file an issue with the code needed to reproduce.
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] isrootpower_dim(y::Unitful.Dimensions{()})
@ Unitful ~/.julia/packages/Unitful/dHMk1/src/logarithm.jl:167
[3] isrootpower(y::Int64)
@ Unitful ~/.julia/packages/Unitful/dHMk1/src/logarithm.jl:166
[4] tolog(L::Type{Unitful.LogInfo{:Decibel, 10, 10}}, S::Int64, x::Float64)
@ Unitful ~/.julia/packages/Unitful/dHMk1/src/logarithm.jl:82
[5] ustrip(x::Level{Unitful.LogInfo{:Decibel, 10, 10}, 1, Int64})
@ Unitful ~/.julia/packages/Unitful/dHMk1/src/logarithm.jl:162
[6] show(io::IOContext{Base.TTY}, x::Level{Unitful.LogInfo{:Decibel, 10, 10}, 1, Int64})
@ Unitful ~/.julia/packages/Unitful/dHMk1/src/logarithm.jl:314
[7] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, x::Level{Unitful.LogInfo{:Decibel, 10, 10}, 1, Int64})
@ Base.Multimedia ./multimedia.jl:47
...
```

A similar issue exists with:
```
x1 = @dB (-2u"V")/1u"V";
```
where I can construct it, but cannot show it.
Here, the issue is probably due to logarithmic scales not allowing negative values. In fact, this works perfectly:
```
julia> x2 = @dB (2u"V")/1u"V"
6.020599913279624 dBV
```
But then, the issue is that that `x1` construction shouldn´t probably be allowed at all.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/logarithm.jl, especially the show method around line 314 and the logarithmic helpers around lines 82 and 162-167. Reproduce the Level and @dB examples from the issue, then inspect existing tests for logarithmic quantities. Done means the negative-value behavior is deliberate and covered, and displaying valid Level values no longer triggers the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.