From a6ad7ae2b1645b6f6ab51ebb515752bd4819d757 Mon Sep 17 00:00:00 2001 From: Gerhard Aigner Date: Sat, 6 Dec 2025 06:08:47 +0100 Subject: [PATCH 1/3] Remove legacy Grisu --- Project.toml | 6 +- src/Showoff.jl | 15 +---- src/grisu.jl | 142 ----------------------------------------------- test/runtests.jl | 5 -- 4 files changed, 3 insertions(+), 165 deletions(-) delete mode 100644 src/grisu.jl diff --git a/Project.toml b/Project.toml index bacebf5..ddf554a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,15 +1,13 @@ name = "Showoff" uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" author = ["Daniel C. Jones (@dcjones)"] -version = "1.0.3" +version = "2.0.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" -Grisu = "42e2da0e-8278-4e71-bc24-59509adca0fe" [compat] -Grisu = "1" -julia = "1" +julia = "1.10" [extras] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/Showoff.jl b/src/Showoff.jl index 0001f5b..8cc62f0 100644 --- a/src/Showoff.jl +++ b/src/Showoff.jl @@ -2,19 +2,10 @@ module Showoff using Dates -if isdefined(Base, :Ryu) - include("ryu.jl") -else - include("grisu.jl") -end +include("ryu.jl") export showoff -# suppress compile errors when there isn't a grisu_ccall macro -macro grisu_ccall(x, mode, ndigits) - quote end -end - # Fallback function showoff(xs::AbstractArray, style=:none) result = Vector{String}(undef, length(xs)) @@ -132,17 +123,13 @@ function showoff(ds::AbstractArray{T}, style=:none) where T<:Union{Date,DateTime push!(minutes, Dates.minute(d)) push!(seconds, Dates.second(d)) end - all_same_year = length(years) == 1 all_one_month = length(months) == 1 && 1 in months all_one_day = length(days) == 1 && 1 in days all_zero_hour = length(hours) == 1 && 0 in hours all_zero_minute = length(minutes) == 1 && 0 in minutes all_zero_seconds = length(minutes) == 1 && 0 in minutes - all_zero_milliseconds = length(minutes) == 1 && 0 in minutes # first label format - label_months = false - label_days = false f1 = "u d, yyyy" f2 = "" if !all_zero_seconds diff --git a/src/grisu.jl b/src/grisu.jl deleted file mode 100644 index b6ab0d5..0000000 --- a/src/grisu.jl +++ /dev/null @@ -1,142 +0,0 @@ -# This is used on Julia version that have the Base.Grisu module - -import Base.Grisu - -function grisu(v::AbstractFloat, mode, requested_digits) - return tuple(Grisu.grisu(v, mode, requested_digits)..., Grisu.DIGITS) -end - -function plain_precision_heuristic(xs::AbstractArray{<:AbstractFloat}) - ys = filter(isfinite, xs) - precision = 0 - for y in ys - len, point, neg, digits = grisu(convert(Float32, y), Grisu.SHORTEST, 0) - precision = max(precision, len - point) - end - return max(precision, 0) -end - -# Print a floating point number at fixed precision. Pretty much equivalent to -# @sprintf("%0.$(precision)f", x), without the macro issues. -function format_fixed(x::AbstractFloat, precision::Integer) - @assert precision >= 0 - - if x == Inf - return "∞" - elseif x == -Inf - return "-∞" - elseif isnan(x) - return "NaN" - end - - len, point, neg, digits = grisu(x, Grisu.FIXED, precision) - - buf = IOBuffer() - if x < 0 - print(buf, '-') - end - - for c in digits[1:min(point, len)] - print(buf, convert(Char, c)) - end - - if point > len - for _ in len:point-1 - print(buf, '0') - end - elseif point < len - if point <= 0 - print(buf, '0') - end - print(buf, '.') - if point < 0 - for _ in 1:-point - print(buf, '0') - end - for c in digits[1:len] - print(buf, convert(Char, c)) - end - else - for c in digits[point+1:len] - print(buf, convert(Char, c)) - end - end - end - - trailing_zeros = precision - max(0, len - point) - if trailing_zeros > 0 && point >= len - print(buf, '.') - end - - for _ in 1:trailing_zeros - print(buf, '0') - end - - String(take!(buf)) -end - -# Print a floating point number in scientific notation at fixed precision. Sort of equivalent -# to @sprintf("%0.$(precision)e", x), but prettier printing. -function format_fixed_scientific(x::AbstractFloat, precision::Integer, - engineering::Bool) - if x == 0.0 - return "0" - elseif x == Inf - return "∞" - elseif x == -Inf - return "-∞" - elseif isnan(x) - return "NaN" - end - - mag = floor(Int, log10(abs(x))) - grisu_precision = precision - - len, point, neg, digits = grisu((x / 10.0^mag), Grisu.FIXED, grisu_precision) - point += mag - - @assert len > 0 - - buf = IOBuffer() - if x < 0 - print(buf, '-') - end - - print(buf, convert(Char, digits[1])) - nextdigit = 2 - if engineering - while (point - 1) % 3 != 0 - if nextdigit <= len - print(buf, convert(Char, digits[nextdigit])) - else - print(buf, '0') - end - nextdigit += 1 - point -= 1 - end - end - - if precision > 1 - print(buf, '.') - end - - for i in nextdigit:len - print(buf, convert(Char, digits[i])) - end - - for i in (len+1):precision - print(buf, '0') - end - - print(buf, "×10") - for c in string(point - 1) - if '0' <= c <= '9' - print(buf, superscript_numerals[c - '0' + 1]) - elseif c == '-' - print(buf, '⁻') - end - end - - return String(take!(buf)) -end - diff --git a/test/runtests.jl b/test/runtests.jl index 3d205b9..fc58994 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,11 +6,6 @@ using Printf const drops0s = !isdefined(Base, :Ryu) @testset "Internals" begin - @test Showoff.@grisu_ccall(1, 2, 3) === nothing - if isdefined(Showoff, :Grisu) - @test Showoff.grisu(1.0, Showoff.Grisu.SHORTEST, 2) == (1, 1, false, Showoff.Grisu.DIGITS) - end - let x = [1.0, Inf, 2.0, NaN] @test Showoff.concrete_minimum(x) == 1.0 @test Showoff.concrete_maximum(x) == 2.0 From d489982c76c04b491a9da7014ce7517ba4c7e443 Mon Sep 17 00:00:00 2001 From: Gerhard Aigner Date: Sat, 6 Dec 2025 11:39:02 +0100 Subject: [PATCH 2/3] Update Project version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mosè Giordano <765740+giordano@users.noreply.github.com> --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ddf554a..98f1082 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Showoff" uuid = "992d4aef-0814-514b-bc4d-f2e9a6c4116f" author = ["Daniel C. Jones (@dcjones)"] -version = "2.0.0" +version = "1.1.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" From e510033ea549ee3a4b6180bc2e487eeaba10c766 Mon Sep 17 00:00:00 2001 From: Gerhard Aigner Date: Thu, 11 Dec 2025 15:33:29 +0100 Subject: [PATCH 3/3] revert unrelated code removal --- src/Showoff.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Showoff.jl b/src/Showoff.jl index 8cc62f0..f115e6c 100644 --- a/src/Showoff.jl +++ b/src/Showoff.jl @@ -123,13 +123,17 @@ function showoff(ds::AbstractArray{T}, style=:none) where T<:Union{Date,DateTime push!(minutes, Dates.minute(d)) push!(seconds, Dates.second(d)) end + all_same_year = length(years) == 1 all_one_month = length(months) == 1 && 1 in months all_one_day = length(days) == 1 && 1 in days all_zero_hour = length(hours) == 1 && 0 in hours all_zero_minute = length(minutes) == 1 && 0 in minutes all_zero_seconds = length(minutes) == 1 && 0 in minutes + all_zero_milliseconds = length(minutes) == 1 && 0 in minutes # first label format + label_months = false + label_days = false f1 = "u d, yyyy" f2 = "" if !all_zero_seconds