@@ -13,50 +13,45 @@ function symbol_to_inttype(::Type{Fixed}, s::Symbol)
13
13
d[s]
14
14
end
15
15
16
- function test_op (fun:: F , :: Type{T} , fx, fy , fxf, fyf, tol) where {F,T }
16
+ function test_op (fun:: Fun , fx :: F , fy :: F , fxf, fyf, tol) where {Fun, F }
17
17
# Make sure that the result is representable
18
- (typemin (T) <= fun (fxf, fyf) <= typemax (T)) || return nothing
19
- @assert abs (fun (fx, fy) - convert (T, fun (fxf, fyf))) <= tol
20
- @assert abs (convert (Float64, fun (fx, fy)) - fun (fxf, fyf)) <= tol
21
- end
22
-
23
- function test_fixed (:: Type{T} ) where {T}
24
- values = [- 10 : 0.01 : 10 ; - 180 : .01 : - 160 ; 160 : .01 : 180 ]
25
- tol = Float64 (eps (T))
18
+ zf = fun (fxf, fyf)
19
+ typemin (F) <= zf <= typemax (F) || return nothing
20
+ z = fun (fx, fy)
21
+ @assert abs (z - convert (F, zf)) <= tol
22
+ @assert abs (convert (Float64, z) - zf) <= tol
23
+ end
24
+
25
+ function test_fixed (:: Type{F} ) where {F}
26
+ tol = Float64 (eps (F))
27
+ v = [- 10 : 0.01 : 10 ; - 180 : .01 : - 160 ; 160 : .01 : 180 ]
28
+ # Ignore values outside the representable range
29
+ values = filter (x -> typemin (F) < x <= typemax (F), v)
26
30
for x in values
27
- # Ignore values outside the representable range
28
- # typemin <, otherwise for -(-0.5) > typemax
29
- if ! (typemin (T) < x <= typemax (T))
30
- continue
31
- end
32
- fx = convert (T,x)
33
- @test convert (T,convert (Float64, fx)) == fx
34
- @test convert (T,convert (Float64, - fx)) == - fx
35
- @test convert (Float64, - fx) == - convert (Float64, fx)
36
-
31
+ fx = convert (F, x)
37
32
fxf = convert (Float64, fx)
38
33
39
- rx = convert (Rational{BigInt},fx)
40
- @assert isequal (fx,rx) == isequal (hash (fx),hash (rx))
34
+ @test convert (F, convert (Float64, fx)) === fx
35
+ @test convert (F, convert (Float64, - fx)) === - fx
36
+ @test convert (Float64, - fx) == - convert (Float64, fx)
41
37
42
- for y in values
43
- if ! (typemin (T) < y <= typemax (T))
44
- continue
45
- end
38
+ rx = convert (Rational{BigInt}, fx)
39
+ @assert isequal (fx, rx) == isequal (hash (fx), hash (rx))
46
40
47
- fy = convert (T,y)
41
+ for y in values
42
+ fy = convert (F, y)
48
43
fyf = convert (Float64, fy)
49
44
50
45
@assert fx== fy || x!= y
51
46
@assert fx< fy || (x + tol)>= y
52
47
@assert fx<= fy || x> y
53
48
54
- test_op (+ , T, fx, fy, fxf, fyf, tol)
55
- test_op (- , T, fx, fy, fxf, fyf, tol)
56
- test_op (* , T, fx, fy, fxf, fyf, tol)
57
- fy != 0 && test_op (/ , T, fx, fy, fxf, fyf, tol)
49
+ test_op (+ , fx, fy, fxf, fyf, tol)
50
+ test_op (- , fx, fy, fxf, fyf, tol)
51
+ test_op (* , fx, fy, fxf, fyf, tol)
52
+ fy != 0 && test_op (/ , fx, fy, fxf, fyf, tol)
58
53
59
- @assert isequal (fx,fy) == isequal (hash (fx),hash (fy))
54
+ @assert isequal (fx, fy) === isequal (hash (fx), hash (fy))
60
55
end
61
56
end
62
57
end
0 commit comments