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