Skip to content

Commit dea6af2

Browse files
committed
Backport partially JuliaMath#207
1 parent 727a11a commit dea6af2

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

src/utilities.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# utility functions and macros, which are independent of `FixedPoint`
22
bitwidth(T::Type) = 8sizeof(T)
33

4+
widen1(T::Type) = T # fallback
45
widen1(::Type{Int8}) = Int16
56
widen1(::Type{UInt8}) = UInt16
67
widen1(::Type{Int16}) = Int32
@@ -9,8 +10,6 @@ widen1(::Type{Int32}) = Int64
910
widen1(::Type{UInt32}) = UInt64
1011
widen1(::Type{Int64}) = Int128
1112
widen1(::Type{UInt64}) = UInt128
12-
widen1(::Type{Int128}) = Int128
13-
widen1(::Type{UInt128}) = UInt128
1413
widen1(x::Integer) = x % widen1(typeof(x))
1514

1615
signedtype(::Type{T}) where {T <: Integer} = typeof(signed(zero(T)))

test/fixed.jl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,24 @@ end
450450
@test Fixed{Int16,3}(-1) == Fixed{Int8,5}(-1)
451451
@test Fixed{Int16,3}(0.25) == Fixed{Int8,5}(0.25)
452452

453-
@test promote_type(Q0f7,Float32,Int) == Float32
454-
@test promote_type(Q0f7,Int,Float32) == Float32
455-
@test promote_type(Int,Q0f7,Float32) == Float32
456-
@test promote_type(Int,Float32,Q0f7) == Float32
457-
@test promote_type(Float32,Int,Q0f7) == Float32
458-
@test promote_type(Float32,Q0f7,Int) == Float32
459-
@test promote_type(Q0f7,Q1f6,Q2f5,Q3f4,Q4f3,Q5f2) == Fixed{Int128,7}
453+
@test @inferred(promote_type(Q0f7, Float64)) === Float64
454+
@test @inferred(promote_type(Float32, Q7f24)) === Float32 # Float64 on v0.9 (#207)
455+
456+
@test @inferred(promote_type(Q0f7, Int8)) === Q0f7 # Float32 on v0.9 (#207)
457+
@test @inferred(promote_type(Int128, Q7f24)) === Q7f24 # Float64 on v0.9 (#207)
458+
459+
@test @inferred(promote_type(Q0f15, Rational{UInt8})) === Rational{UInt8}
460+
461+
@test @inferred(promote_type(Q0f7, Float32, Int)) === Float32
462+
@test @inferred(promote_type(Q0f7, Int, Float32)) === Float32
463+
@test @inferred(promote_type(Int, Q0f7, Float32)) === Float32
464+
@test @inferred(promote_type(Int, Float32, Q0f7)) === Float32
465+
@test @inferred(promote_type(Float32, Int, Q0f7)) === Float32
466+
@test @inferred(promote_type(Float32, Q0f7, Int)) === Float32
467+
468+
@test @inferred(promote_type(Q0f7,Q1f6,Q2f5,Q3f4,Q4f3,Q5f2)) == Fixed{Int128,7}
469+
470+
@test @inferred(promote_type(Q0f7, N0f32)) === FixedPoint # Float64 on v0.9 (#207)
460471
end
461472

462473
@testset "show" begin

test/normed.jl

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,24 @@ end
480480
@test Normed{UInt16,4}(1) == Normed{UInt8,6}(1)
481481
@test Normed{UInt16,4}(0.2) == Normed{UInt8,6}(0.2)
482482

483-
@test promote_type(N0f8,Float32,Int) == Float32
484-
@test promote_type(N0f8,Int,Float32) == Float32
485-
@test promote_type(Int,N0f8,Float32) == Float32
486-
@test promote_type(Int,Float32,N0f8) == Float32
487-
@test promote_type(Float32,Int,N0f8) == Float32
488-
@test promote_type(Float32,N0f8,Int) == Float32
489-
@test promote_type(N0f8,N1f7,N2f6,N3f5,N4f4,N5f3) == Normed{UInt128,8}
483+
@test @inferred(promote_type(N0f8, Float64)) === Float64
484+
@test @inferred(promote_type(Float32, N8f24)) === Float64
485+
486+
@test @inferred(promote_type(N0f8, Int8)) === Float32
487+
@test @inferred(promote_type(Int128, N8f24)) === Float64
488+
489+
@test @inferred(promote_type(N0f16, Rational{Int8})) === Rational{Int8}
490+
491+
@test @inferred(promote_type(N0f8, Float32, Int)) === Float32
492+
@test @inferred(promote_type(N0f8, Int, Float32)) === Float32
493+
@test @inferred(promote_type(Int, N0f8, Float32)) === Float32
494+
@test @inferred(promote_type(Int, Float32, N0f8)) === Float32
495+
@test @inferred(promote_type(Float32, Int, N0f8)) === Float32
496+
@test @inferred(promote_type(Float32, N0f8, Int)) === Float32
497+
498+
@test @inferred(promote_type(N0f8,N1f7,N2f6,N3f5,N4f4,N5f3)) === Normed{UInt128,8}
499+
500+
@test @inferred(promote_type(N0f8, Q0f31)) === FixedPoint # Float64 on v0.9 (#207)
490501
end
491502

492503
@testset "show" begin

0 commit comments

Comments
 (0)