From 63055ff71bdc1ea1054c858634f94de664ba6f9a Mon Sep 17 00:00:00 2001 From: "C. Brenhin Keller" Date: Sun, 2 Apr 2023 14:39:27 -0400 Subject: [PATCH] Fix bug in pretty printing of `CI`s with negative values --- Project.toml | 2 +- src/show.jl | 2 +- test/runtests.jl | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 116b8e2..7803fab 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Isoplot" uuid = "5adc30d5-9ddf-423c-bb15-ece697bec3ab" authors = ["C. Brenhin Keller "] -version = "0.2.4" +version = "0.2.5" [deps] Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" diff --git a/src/show.jl b/src/show.jl index 3177f94..6e66c3b 100644 --- a/src/show.jl +++ b/src/show.jl @@ -23,7 +23,7 @@ end function Base.print(io::IO, x::CI) l = round(x.mean - x.lower, sigdigits=3) u = round(x.upper - x.mean, sigdigits=3) - d = floor(Int, log10(x.mean)) - floor(Int, log10(max(l,u))) + d = floor(Int, log10(abs(x.mean))) - floor(Int, log10(max(abs(l),abs(u)))) m = round(x.mean, sigdigits=3+d) print(io, "$m +$u/-$l") end diff --git a/test/runtests.jl b/test/runtests.jl index 42099a6..d54384f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,9 @@ using Measurements @test ci == CI{Float64}(5.5, 3.0276503540974917, 5.5, 1.225, 9.775) @test "$ci" === "5.5 +4.28/-4.28" @test display(ci) != NaN + + ci = CI(randn(100)) + @test display(ci) != NaN end @testset "General" begin