From 886185c0418d15eb9f9c9bf3058cf263d0e24fd2 Mon Sep 17 00:00:00 2001 From: wheeheee <104880306+wheeheee@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:23:13 +0800 Subject: [PATCH 1/2] Aggressively propagate constants for positive base in ndigits Annotated `ndigits0zpb` and `ndigits0z` with `@constprop :aggressive`. --- base/intfuncs.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 21677baa923e0..c958d6a204ee7 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -758,6 +758,7 @@ ndigits0znb(x::Bool, b::Integer) = x % Int # The suffix "pb" stands for "positive base" function ndigits0zpb(x::Integer, b::Integer) + @constprop :aggressive # precondition: b > 1 x == 0 && return 0 b = Int(b) @@ -822,6 +823,7 @@ julia> Base.ndigits0z(10) See also [`ndigits`](@ref). """ function ndigits0z(x::Integer, b::Integer) + @constprop :aggressive if b < -1 ndigits0znb(x, b) elseif b > 1 From 7d02fcf492011302f6b5678ac7588fa9de44f208 Mon Sep 17 00:00:00 2001 From: wheeheee <104880306+wheeheee@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:23:14 +0800 Subject: [PATCH 2/2] also constprop string(::Int; base) make clear that `split_sign` returns a tuple --- base/intfuncs.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index c958d6a204ee7..51a728b0b4b7d 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -1066,8 +1066,8 @@ function _base(base::Integer, x::Integer, pad::Int, neg::Bool) return str end -split_sign(n::Integer) = unsigned(abs(n)), n < 0 -split_sign(n::Unsigned) = n, false +split_sign(n::Integer) = (unsigned(abs(n)), n < 0) +split_sign(n::Unsigned) = (n, false) """ string(n::Integer; base::Integer = 10, pad::Integer = 1) @@ -1096,6 +1096,7 @@ julia> @sprintf("%4i", 5) ``` """ function string(n::Integer; base::Integer = 10, pad::Integer = 1) + @constprop :aggressive pad = (min(max(pad, typemin(Int)), typemax(Int)) % Int)::Int if base == 2 (n_positive, neg) = split_sign(n)