Skip to content

Commit c1a642f

Browse files
committed
Backport partially JuliaMath#207
1 parent efa40a6 commit c1a642f

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
@@ -455,13 +455,24 @@ end
455455
@test Fixed{Int16,3}(-1) == Fixed{Int8,5}(-1)
456456
@test Fixed{Int16,3}(0.25) == Fixed{Int8,5}(0.25)
457457

458-
@test promote_type(Q0f7,Float32,Int) == Float32
459-
@test promote_type(Q0f7,Int,Float32) == Float32
460-
@test promote_type(Int,Q0f7,Float32) == Float32
461-
@test promote_type(Int,Float32,Q0f7) == Float32
462-
@test promote_type(Float32,Int,Q0f7) == Float32
463-
@test promote_type(Float32,Q0f7,Int) == Float32
464-
@test promote_type(Q0f7,Q1f6,Q2f5,Q3f4,Q4f3,Q5f2) == Fixed{Int128,7}
458+
@test @inferred(promote_type(Q0f7, Float64)) === Float64
459+
@test @inferred(promote_type(Float32, Q7f24)) === Float32 # Float64 on v0.9 (#207)
460+
461+
@test @inferred(promote_type(Q0f7, Int8)) === Q0f7 # Float32 on v0.9 (#207)
462+
@test @inferred(promote_type(Int128, Q7f24)) === Q7f24 # Float64 on v0.9 (#207)
463+
464+
@test @inferred(promote_type(Q0f15, Rational{UInt8})) === Rational{UInt8}
465+
466+
@test @inferred(promote_type(Q0f7, Float32, Int)) === Float32
467+
@test @inferred(promote_type(Q0f7, Int, Float32)) === Float32
468+
@test @inferred(promote_type(Int, Q0f7, Float32)) === Float32
469+
@test @inferred(promote_type(Int, Float32, Q0f7)) === Float32
470+
@test @inferred(promote_type(Float32, Int, Q0f7)) === Float32
471+
@test @inferred(promote_type(Float32, Q0f7, Int)) === Float32
472+
473+
@test @inferred(promote_type(Q0f7,Q1f6,Q2f5,Q3f4,Q4f3,Q5f2)) == Fixed{Int128,7}
474+
475+
@test @inferred(promote_type(Q0f7, N0f32)) === FixedPoint # Float64 on v0.9 (#207)
465476
end
466477

467478
@testset "show" begin

test/normed.jl

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

488-
@test promote_type(N0f8,Float32,Int) == Float32
489-
@test promote_type(N0f8,Int,Float32) == Float32
490-
@test promote_type(Int,N0f8,Float32) == Float32
491-
@test promote_type(Int,Float32,N0f8) == Float32
492-
@test promote_type(Float32,Int,N0f8) == Float32
493-
@test promote_type(Float32,N0f8,Int) == Float32
494-
@test promote_type(N0f8,N1f7,N2f6,N3f5,N4f4,N5f3) == Normed{UInt128,8}
488+
@test @inferred(promote_type(N0f8, Float64)) === Float64
489+
@test @inferred(promote_type(Float32, N8f24)) === Float64
490+
491+
@test @inferred(promote_type(N0f8, Int8)) === Float32
492+
@test @inferred(promote_type(Int128, N8f24)) === Float64
493+
494+
@test @inferred(promote_type(N0f16, Rational{Int8})) === Rational{Int8}
495+
496+
@test @inferred(promote_type(N0f8, Float32, Int)) === Float32
497+
@test @inferred(promote_type(N0f8, Int, Float32)) === Float32
498+
@test @inferred(promote_type(Int, N0f8, Float32)) === Float32
499+
@test @inferred(promote_type(Int, Float32, N0f8)) === Float32
500+
@test @inferred(promote_type(Float32, Int, N0f8)) === Float32
501+
@test @inferred(promote_type(Float32, N0f8, Int)) === Float32
502+
503+
@test @inferred(promote_type(N0f8,N1f7,N2f6,N3f5,N4f4,N5f3)) === Normed{UInt128,8}
504+
505+
@test @inferred(promote_type(N0f8, Q0f31)) === FixedPoint # Float64 on v0.9 (#207)
495506
end
496507

497508
@testset "show" begin

0 commit comments

Comments
 (0)