11using Base. Test
22using FixedPointNumbers
33
4+ function test_op {F,T} (fun:: F , :: Type{T} , fx, fy, fxf, fyf, tol)
5+ # Make sure that the result is representable
6+ (typemin (T) <= fun (fxf, fyf) <= typemax (T)) || return nothing
7+ @assert abs (fun (fx, fy) - convert (T, fun (fxf, fyf))) <= tol
8+ @assert abs (convert (Float64, fun (fx, fy)) - fun (fxf, fyf)) <= tol
9+ end
10+
411function test_fixed {T} (:: Type{T} , f)
512 values = [- 10 : 0.01 : 10 ; - 180 : .01 : - 160 ; 160 : .01 : 180 ]
613 tol = 2.0 ^- f
@@ -29,21 +36,16 @@ function test_fixed{T}(::Type{T}, f)
2936 fy = convert (T,y)
3037 fyf = convert (Float64, fy)
3138
32- @test fx== fy || x!= y
33- @test fx< fy || x>= y
34- @test fx<= fy || x> y
39+ @assert fx== fy || x!= y
40+ @assert fx< fy || x>= y
41+ @assert fx<= fy || x> y
3542
36- for fun in [+ , - , * , / ]
37- # Make sure that the result is representable
38- if ! (typemin (T) <= fun (fxf, fyf) <= typemax (T))
39- continue
40- elseif (fun == / ) && fy != 0
41- @test abs (fun (fx, fy) - convert (T, fun (fxf, fyf))) <= tol
42- @test abs (convert (Float64, fun (fx, fy)) - fun (fxf, fyf)) <= tol
43- end
44- end
43+ test_op (+ , T, fx, fy, fxf, fyf, tol)
44+ test_op (- , T, fx, fy, fxf, fyf, tol)
45+ test_op (* , T, fx, fy, fxf, fyf, tol)
46+ fy != 0 && test_op (/ , T, fx, fy, fxf, fyf, tol)
4547
46- @test isequal (fx,fy) == isequal (hash (fx),hash (fy))
48+ @assert isequal (fx,fy) == isequal (hash (fx),hash (fy))
4749 end
4850 end
4951end
@@ -66,3 +68,9 @@ a = F6[1.2, 1.4]
6668acmp = Float64 (a[1 ])* Float64 (a[2 ])
6769@test prod (a) == acmp
6870@test prod (a, 1 ) == [acmp]
71+
72+ x = Fixed {Int8,8} (0.3 )
73+ for T in (Float16, Float32, Float64, BigFloat)
74+ y = convert (T, x)
75+ @test isa (y, T)
76+ end
0 commit comments