@@ -16,7 +16,7 @@ function test_fixed(::Type{T}, f) where {T}
1616 if ! (typemin (T) < x <= typemax (T))
1717 continue
1818 end
19- isinteger (x) && @show x
19+ # isinteger(x) && @show x
2020 fx = convert (T,x)
2121 @test convert (T,convert (Float64, fx)) == fx
2222 @test convert (T,convert (Float64, - fx)) == - fx
6262@testset " test_fixed" begin
6363for (TI, f) in [(Int8, 8 ), (Int16, 8 ), (Int16, 10 ), (Int32, 16 )]
6464 T = Fixed{TI,f}
65- println (" Testing $T " )
65+ # println(" Testing $T")
6666 test_fixed (T, f)
6767end
6868end
@@ -166,4 +166,30 @@ for (T, f) in ((Int8, 7),
166166 @test abs (Fixed {T, f} (x) - x) <= tol
167167 end
168168end
169+
170+ @testset " Promotion within Fixed" begin
171+ @test @inferred (promote (Q0f7 (0.25 ), Q0f7 (0.75 ))) ===
172+ (Q0f7 (0.25 ), Q0f7 (0.75 ))
173+ @test @inferred (promote (Fixed {Int16,3} (0.25 ), Fixed {Int8,3} (0.875 ))) ===
174+ (Fixed {Int16,3} (0.25 ), Fixed {Int16,3} (0.875 ))
175+ @test @inferred (promote (Fixed {Int8,6} (0.125 ), Fixed {Int8,4} (0.75 ))) ===
176+ (Fixed {Int16,6} (0.125 ), Fixed {Int16,6} (0.75 ))
177+
178+ @test Fixed {Int16,15} (- 1 ) == Fixed {Int8,7} (- 1 )
179+ @test Fixed {Int16,15} (0.25 ) == Fixed {Int8,7} (0.25 )
180+ @test Fixed {Int16,7} (- 1 ) == Fixed {Int8,7} (- 1 )
181+ @test Fixed {Int16,7} (0.25 ) == Fixed {Int8,7} (0.25 )
182+ @test Fixed {Int16,15} (- 1 ) == Fixed {Int8,5} (- 1 )
183+ @test Fixed {Int16,15} (5 / 32 ) == Fixed {Int8,5} (5 / 32 )
184+ @test Fixed {Int16,3} (- 1 ) == Fixed {Int8,5} (- 1 )
185+ @test Fixed {Int16,3} (0.25 ) == Fixed {Int8,5} (0.25 )
186+
187+ @test promote_type (Q0f7,Float32,Int) == Float32
188+ @test promote_type (Q0f7,Int,Float32) == Float32
189+ @test promote_type (Int,Q0f7,Float32) == Float32
190+ @test promote_type (Int,Float32,Q0f7) == Float32
191+ @test promote_type (Float32,Int,Q0f7) == Float32
192+ @test promote_type (Float32,Q0f7,Int) == Float32
193+ @test promote_type (Q0f7,Q1f6,Q2f5,Q3f4,Q4f3,Q5f2) == Fixed{Int128,7 }
194+ end
169195end
0 commit comments