From b0b103b3c02c7a93ea794c6f7c9cfb275de117dc Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Thu, 14 May 2026 19:41:44 +0200 Subject: [PATCH] Use `oneunit` instead of `one` in remaining promotion sites Completes b394b96b: five more `typeof(one(T)/one(T))` sites still collapsed `Measurement{Float64}` to `Float64` (since Measurements.jl defines `one(Measurement{T}) = one(T)`), breaking the tf->zpk, ss->tf, ss->zpk, minreal, and charpoly conversion paths reported in #1027. Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/ControlSystemsBase/src/matrix_comps.jl | 2 +- .../src/types/SisoTfTypes/SisoRational.jl | 2 +- lib/ControlSystemsBase/src/types/conversion.jl | 6 +++--- lib/ControlSystemsBase/src/types/zpk.jl | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ControlSystemsBase/src/matrix_comps.jl b/lib/ControlSystemsBase/src/matrix_comps.jl index b216d8473..67f42a4bc 100644 --- a/lib/ControlSystemsBase/src/matrix_comps.jl +++ b/lib/ControlSystemsBase/src/matrix_comps.jl @@ -474,7 +474,7 @@ function _infnorm_two_steps_dt(sys::AbstractStateSpace, normtype::Symbol, tol=1e on_unit_circle = z -> abs(abs(z) - 1) < approxcirc # Helper fcn for readability T = promote_type(real(numeric_type(sys)), Float64, typeof(true/sys.Ts)) - Tw = typeof(one(T)/sys.Ts) + Tw = typeof(oneunit(T)/sys.Ts) if sys.nx == 0 # static gain return (T(opnorm(sys.D)), Tw(0)) diff --git a/lib/ControlSystemsBase/src/types/SisoTfTypes/SisoRational.jl b/lib/ControlSystemsBase/src/types/SisoTfTypes/SisoRational.jl index 6fca28bbb..87643556d 100644 --- a/lib/ControlSystemsBase/src/types/SisoTfTypes/SisoRational.jl +++ b/lib/ControlSystemsBase/src/types/SisoTfTypes/SisoRational.jl @@ -39,7 +39,7 @@ Base.zero(f::SisoRational) = zero(typeof(f)) isproper(f::SisoRational) = (length(f.num) <= length(f.den)) function minreal(sys::SisoRational{T}, eps::Real=sqrt(eps())) where T - T2 = typeof(zero(T)/one(T)) + T2 = typeof(oneunit(T)/oneunit(T)) return convert(SisoRational{T2}, minreal(convert(SisoZpk,sys), eps)) end diff --git a/lib/ControlSystemsBase/src/types/conversion.jl b/lib/ControlSystemsBase/src/types/conversion.jl index 075482c29..b01990997 100644 --- a/lib/ControlSystemsBase/src/types/conversion.jl +++ b/lib/ControlSystemsBase/src/types/conversion.jl @@ -291,7 +291,7 @@ function convert(::Type{TransferFunction{TE,SisoRational{T}}}, sys::AbstractStat TransferFunction{TE,SisoRational{T}}(matrix, TE(sys.timeevol)) end function convert(::Type{TransferFunction{TE1,SisoRational}}, sys::StateSpace{TE2,T0}) where {TE1,TE2,T0<:Number} - T = typeof(one(T0)/one(T0)) + T = typeof(oneunit(T0)/oneunit(T0)) convert(TransferFunction{TE1,SisoRational{T}}, sys) end @@ -307,7 +307,7 @@ function convert(::Type{TransferFunction{TE,SisoZpk{T,TR}}}, sys::AbstractStateS end function convert(::Type{TransferFunction{TE1,SisoZpk}}, sys::AbstractStateSpace{TE2}) where {TE1,TE2} T0 = numeric_type(sys) - T = typeof(one(T0)/one(T0)) + T = typeof(oneunit(T0)/oneunit(T0)) convert(TransferFunction{TE1,SisoZpk{T,complex(T)}}, sys) end @@ -335,7 +335,7 @@ Implements: "An accurate and efficient algorithm for the computation of the char """ function charpoly(A::AbstractMatrix{T}) where {T} N = size(A, 1) - TT = typeof(one(T)/one(T)) + TT = typeof(oneunit(T)/oneunit(T)) poly_factors = vec(ones(TT, N+1)) if N <= 0 return poly_factors diff --git a/lib/ControlSystemsBase/src/types/zpk.jl b/lib/ControlSystemsBase/src/types/zpk.jl index 50bb77bcc..f225da5a7 100644 --- a/lib/ControlSystemsBase/src/types/zpk.jl +++ b/lib/ControlSystemsBase/src/types/zpk.jl @@ -65,7 +65,7 @@ zpk(k::Real, Ts::TimeEvolution) = zpk(eltype(k)[], eltype(k)[], k, Ts) zpk(sys::AbstractStateSpace) = zpk(zpkdata(sys)..., timeevol(sys)) function zpk(G::TransferFunction{TE,S}) where {TE<:TimeEvolution,T0, S<:SisoTf{T0}} - T = typeof(one(T0)/one(T0)) + T = typeof(oneunit(T0)/oneunit(T0)) convert(TransferFunction{TE,SisoZpk{T, complex(T)}}, G) end