From 5c2bed114653fff3f69a0d3047070a7ba249d87f Mon Sep 17 00:00:00 2001 From: kimikage Date: Sat, 17 Oct 2026 19:07:26 +0900 Subject: [PATCH] Revert "Fix `floattype()` for non-concrete types (#354)" This reverts commit a26b6d8f06ce044fc98393b0b4eb46cf0669e117. --- src/FixedPointNumbers.jl | 5 +++-- src/deprecations.jl | 8 ++++++++ test/fixed.jl | 1 - test/normed.jl | 1 - test/traits.jl | 18 ++---------------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/FixedPointNumbers.jl b/src/FixedPointNumbers.jl index e58f26ee..7bafaca2 100644 --- a/src/FixedPointNumbers.jl +++ b/src/FixedPointNumbers.jl @@ -196,8 +196,9 @@ floattype(::Type{T}) where {T <: Integer} = Float64 floattype(::Type{T}) where {T <: LongInts} = BigFloat floattype(::Type{T}) where {I <: Integer, T <: Rational{I}} = typeof(zero(I)/oneunit(I)) floattype(::Type{<:AbstractIrrational}) = Float64 -floattype(::Type{<:FixedPoint}) = BigFloat # fallback for `FixedPoint` -floattype(::Type{<:FixedPoint{T}}) where {T <: Integer} = isconcretetype(T) ? floattype(T) : BigFloat +floattype(::Type{X}) where {T <: ShortInts, X <: FixedPoint{T}} = Float32 +floattype(::Type{X}) where {T <: Integer, X <: FixedPoint{T}} = Float64 +floattype(::Type{X}) where {T <: LongInts, X <: FixedPoint{T}} = BigFloat # Non-Real types floattype(::Type{Complex{T}}) where T = Complex{floattype(T)} diff --git a/src/deprecations.jl b/src/deprecations.jl index 101bf250..2441efd3 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -1,5 +1,13 @@ import Base.@deprecate_binding +function floattype(::Type{T}) where {T <: Real} + Base.depwarn(""" + In a future release, the fallback definition of `floattype` will throw a MethodError if it cannot return a type `<:AbstractFloat`. + See the documentation on `floattype` for guidance on whether to define a custom `floattype(::Type{$T})` method. + """, :floattype) + return T +end + function typechar(::Type{X}) where {X} Base.depwarn(""" `typechar` was deprecated since the prefix may not be a single character in the future. diff --git a/test/fixed.jl b/test/fixed.jl index 1b5fdd86..d0909c3b 100644 --- a/test/fixed.jl +++ b/test/fixed.jl @@ -245,7 +245,6 @@ end @test float(0.75Q10f53)::BigFloat == big"0.75" test_floattype(Fixed) - # see test/traits.jl for floattype tests for non-concrete types end @testset "conversions from float" begin diff --git a/test/normed.jl b/test/normed.jl index 28974e35..50b60093 100644 --- a/test/normed.jl +++ b/test/normed.jl @@ -210,7 +210,6 @@ end @test float(1N11f53)::BigFloat == big"1.0" test_floattype(Normed) - # see test/traits.jl for floattype tests for non-concrete types end @testset "conversions from float" begin diff --git a/test/traits.jl b/test/traits.jl index 09870514..c248b4c0 100644 --- a/test/traits.jl +++ b/test/traits.jl @@ -2,21 +2,8 @@ using FixedPointNumbers, Test using FixedPointNumbers: bitwidth struct MyReal <: Real end -struct MyInteger <: Integer end - -@testset "floattype for non-concrete/non-FixedPoint types" begin - @test floattype(FixedPoint) === BigFloat - @test floattype(Normed) === BigFloat - @test floattype(Fixed) === BigFloat - @test floattype(FixedPoint{Int8}) === Float32 - @test floattype(Normed{UInt32}) === Float64 - @test floattype(Fixed{Int64}) === BigFloat - @test floattype(FixedPoint{MyInteger}) === Float64 - @test floattype(FixedPoint{Union{},1}) === BigFloat - @test floattype(Normed{Unsigned,2}) === BigFloat - @test floattype(Fixed{T,3} where {T<:Signed}) === BigFloat - @test_throws MethodError floattype(Fixed{T,3} where T) # T is not bounded +@testset "floattype" begin for T in (UInt8, UInt16, UInt32, UInt64, UInt128, Bool, Int8, Int16, Int32, Int64, Int128) @test typemax(T) <= maxintfloat(floattype(T)) @@ -29,6 +16,5 @@ struct MyInteger <: Integer end @test floattype(Base.TwicePrecision{Float64}) === Float64 @test floattype(typeof(π)) === Float64 - @test_throws MethodError floattype(MyReal) # See #177. - @test floattype(MyInteger) === Float64 + @test_skip(@test_throws MethodError floattype(MyReal)) # TODO: eliminate `@test_skipped` when depwarn is eliminated. See #177. end