Skip to content

Commit 65d1b00

Browse files
authored
Merge pull request #85 from JuliaMath/teh/ambs
Fix ambiguities and turn ambiguity testing on for all platforms
2 parents a63b5cc + 5dc22fb commit 65d1b00

7 files changed

Lines changed: 17 additions & 4 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ os:
44
- osx
55
julia:
66
- 0.5
7+
- 0.6
78
- nightly
89
notifications:
910
email: false

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ environment:
22
matrix:
33
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
44
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
5+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
6+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
57
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
68
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
79

src/fixed.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ convert{TF<:AbstractFloat,T,f}(::Type{TF}, x::Fixed{T,f}) =
5555
convert(TF,x.i>>f) + convert(TF,x.i&(1<<f - 1))/convert(TF,1<<f)
5656

5757
convert{T,f}(::Type{Bool}, x::Fixed{T,f}) = x.i!=0
58+
function convert{T,f}(::Type{Integer}, x::Fixed{T,f})
59+
isinteger(x) || throw(InexactError())
60+
convert(Integer, x.i>>f)
61+
end
5862
function convert{TI<:Integer, T,f}(::Type{TI}, x::Fixed{T,f})
5963
isinteger(x) || throw(InexactError())
6064
convert(TI, x.i>>f)

src/normed.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ zero(x::Normed) = zero(typeof(x))
3232
rawone(v) = reinterpret(one(v))
3333

3434
# Conversions
35-
convert{T<:Unsigned,f}(::Type{Normed{T,f}}, x::Normed{T,f}) = x
35+
convert{U<:Normed}(::Type{U}, x::U) = x
3636
convert{T1<:Unsigned,T2<:Unsigned,f}(::Type{Normed{T1,f}}, x::Normed{T2,f}) = Normed{T1,f}(convert(T1, x.i), 0)
3737
function convert{T<:Unsigned,T2<:Unsigned,f}(::Type{Normed{T,f}}, x::Normed{T2})
3838
U = Normed{T,f}
@@ -67,6 +67,7 @@ function convert{T<:AbstractFloat}(::Type{T}, x::Normed)
6767
convert(T, y) # needed for types like Float16 which promote arithmetic to Float32
6868
end
6969
convert(::Type{Bool}, x::Normed) = x == zero(x) ? false : true
70+
convert(::Type{Integer}, x::Normed) = convert(Integer, x*1.0)
7071
convert{T<:Integer}(::Type{T}, x::Normed) = convert(T, x*(1/one(T)))
7172
convert{Ti<:Integer}(::Type{Rational{Ti}}, x::Normed) = convert(Ti, reinterpret(x))//convert(Ti, rawone(x))
7273
convert(::Type{Rational}, x::Normed) = reinterpret(x)//rawone(x)

test/fixed.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ for T in (Float16, Float32, Float64, BigFloat)
103103
@test isa(y, T)
104104
end
105105

106+
@test convert(Int, Q1f6(1)) === 1
107+
@test convert(Integer, Q1f6(1)) === Int8(1)
108+
106109
# Floating-point conversions
107110
@test isa(float(one(Fixed{Int8,6})), Float32)
108111
@test isa(float(one(Fixed{Int32,18})), Float64)

test/normed.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ for T in (FixedPointNumbers.UF..., UF2...)
8989
@test convert(Bool, one(T)) == true
9090
@test convert(Bool, convert(T, 0.2)) == true
9191
@test convert(Int, one(T)) == 1
92+
@test convert(Integer, one(T)) == 1
9293
@test convert(Rational, one(T)) == 1
9394
end
9495
@test convert(Rational, convert(N0f8, 0.5)) == 0x80//0xff
@@ -203,6 +204,9 @@ end
203204
@test mod(reinterpret(N0f8, 0x0f), reinterpret(N0f8, 0x02)) == rem(reinterpret(N0f8, 0x0f), reinterpret(N0f8, 0x02)) == reinterpret(N0f8, 0x01)
204205
@test mod1(reinterpret(N0f8, 0x10), reinterpret(N0f8, 0x02)) == reinterpret(N0f8, 0x02)
205206
@test mod1(reinterpret(N0f8, 0x0f), reinterpret(N0f8, 0x02)) == reinterpret(N0f8, 0x01)
207+
@test bswap(N0f8(0.5)) === N0f8(0.5)
208+
@test bswap(N0f16(0.5)) === reinterpret(N0f16, 0x0080)
209+
@test minmax(N0f8(0.8), N0f8(0.2)) === (N0f8(0.2), N0f8(0.8))
206210

207211
r = reinterpret(N0f8, 0x01):reinterpret(N0f8, 0x01):reinterpret(N0f8, convert(UInt8, 48))
208212
@test length(r) == 48

test/runtests.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ for f in ["normed.jl", "fixed.jl"]
55
include(f)
66
end
77

8-
if v"0.5.0" <= VERSION < v"0.6.0-dev"
9-
@test isempty(detect_ambiguities(FixedPointNumbers, Base, Core))
10-
end
8+
@test isempty(detect_ambiguities(FixedPointNumbers, Base, Core))

0 commit comments

Comments
 (0)