diff --git a/src/FixedPointNumbers.jl b/src/FixedPointNumbers.jl index 33e25b5..e590561 100644 --- a/src/FixedPointNumbers.jl +++ b/src/FixedPointNumbers.jl @@ -196,9 +196,8 @@ 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{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 +floattype(::Type{<:FixedPoint}) = BigFloat # fallback for `FixedPoint` +floattype(::Type{<:FixedPoint{T}}) where {T <: Integer} = isconcretetype(T) ? floattype(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 2441efd..101bf25 100644 --- a/src/deprecations.jl +++ b/src/deprecations.jl @@ -1,13 +1,5 @@ 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 509fa4a..bcfce6d 100644 --- a/test/fixed.jl +++ b/test/fixed.jl @@ -245,6 +245,7 @@ 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 58bc4eb..03f73fa 100644 --- a/test/normed.jl +++ b/test/normed.jl @@ -210,6 +210,7 @@ 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 c248b4c..0987051 100644 --- a/test/traits.jl +++ b/test/traits.jl @@ -2,8 +2,21 @@ 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)) @@ -16,5 +29,6 @@ struct MyReal <: Real end @test floattype(Base.TwicePrecision{Float64}) === Float64 @test floattype(typeof(π)) === Float64 - @test_skip(@test_throws MethodError floattype(MyReal)) # TODO: eliminate `@test_skipped` when depwarn is eliminated. See #177. + @test_throws MethodError floattype(MyReal) # See #177. + @test floattype(MyInteger) === Float64 end