|
1 | 1 | using Base.Test
|
2 | 2 | using FixedPointNumbers
|
3 | 3 |
|
| 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 | + @test abs(fun(fx, fy) - convert(T, fun(fxf, fyf))) <= tol |
| 8 | + @test abs(convert(Float64, fun(fx, fy)) - fun(fxf, fyf)) <= tol |
| 9 | +end |
| 10 | + |
4 | 11 | function test_fixed{T}(::Type{T}, f)
|
5 | 12 | values = [-10:0.01:10; -180:.01:-160; 160:.01:180]
|
6 | 13 | tol = 2.0^-f
|
@@ -33,15 +40,10 @@ function test_fixed{T}(::Type{T}, f)
|
33 | 40 | @test fx<fy || x>=y
|
34 | 41 | @test fx<=fy || x>y
|
35 | 42 |
|
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) |
45 | 47 |
|
46 | 48 | @test isequal(fx,fy) == isequal(hash(fx),hash(fy))
|
47 | 49 | end
|
|
0 commit comments