Skip to content

Fix Ambiguities #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
Compat 0.35
3 changes: 3 additions & 0 deletions src/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ struct Fixed{T <: Signed,f} <: FixedPoint{T, f}
Fixed{T, f}(i::Integer, _) where {T,f} = new{T, f}(i % T)
Fixed{T, f}(x) where {T,f} = convert(Fixed{T,f}, x)
Fixed{T, f}(x::Fixed{T,f}) where {T,f} = x
Fixed{T, f}(x::Char) where {T,f} = throw(ArgumentError("Fixed cannot be constructed from a Char"))
Fixed{T, f}(x::Complex) where {T,f} = Fixed{T, f}(convert(real(typeof(x)), x))
Fixed{T, f}(x::Base.TwicePrecision) where {T,f} = Fixed{T, f}(convert(Float64, x))
end

reinterpret(::Type{Fixed{T,f}}, x::T) where {T <: Signed,f} = Fixed{T,f}(x, 0)
Expand Down
3 changes: 3 additions & 0 deletions src/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ struct Normed{T<:Unsigned,f} <: FixedPoint{T,f}
Normed{T, f}(i::Integer,_) where {T,f} = new{T, f}(i%T) # for setting by raw representation
Normed{T, f}(x) where {T,f} = convert(Normed{T,f}, x)
Normed{T, f}(x::Normed{T,f}) where {T,f} = x
Normed{T, f}(x::Char) where {T,f} = throw(ArgumentError("Normed cannot be constructed from a Char"))
Normed{T, f}(x::Complex) where {T,f} = Normed{T, f}(convert(real(typeof(x)), x))
Normed{T, f}(x::Base.TwicePrecision) where {T,f} = Normed{T, f}(convert(Float64, x))
end

typechar(::Type{X}) where {X <: Normed} = 'N'
Expand Down
9 changes: 7 additions & 2 deletions test/fixed.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Base.Test
using FixedPointNumbers
using FixedPointNumbers, Compat.Test

function test_op(fun::F, ::Type{T}, fx, fy, fxf, fyf, tol) where {F,T}
# Make sure that the result is representable
Expand Down Expand Up @@ -130,3 +129,9 @@ end

# issue #79
@test realmin(Q11f4) == Q11f4(0.06)

# Test disambiguation constructors
@test_throws ArgumentError Fixed{Int32,16}('a')
@test_throws InexactError Fixed{Int32,16}(complex(1.0, 1.0))
@test Fixed{Int32,16}(complex(1.0, 0.0)) == 1
@test Fixed{Int32,16}(Base.TwicePrecision(1.0, 0.0)) == 1
10 changes: 8 additions & 2 deletions test/normed.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FixedPointNumbers
using Base.Test
using FixedPointNumbers, Compat.Test

@test reinterpret(N0f8, 0xa2).i === 0xa2
@test reinterpret(N6f10, 0x1fa2).i === 0x1fa2
Expand Down Expand Up @@ -314,3 +313,10 @@ elseif VERSION >= v"0.7.0-DEV.1790"
@test summary(a) == "2-element Array{N0f8,1} with eltype FixedPointNumbers.Normed{UInt8,8}"
@test summary(view(a, 1:2)) == "2-element view(::Array{N0f8,1}, 1:2) with eltype FixedPointNumbers.Normed{UInt8,8}"
end

# Test disambiguation constructors
@test_throws ArgumentError Normed{UInt32,16}('a')
@test_throws InexactError Normed{UInt32,16}(complex(1.0, 1.0))
@test Normed{UInt32,16}(complex(1.0, 0.0)) == 1
@test Normed{UInt32,16}(Base.TwicePrecision(1.0, 0.0)) == 1

6 changes: 2 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using FixedPointNumbers, Base.Test
using FixedPointNumbers, Compat.Test

if VERSION < v"0.7.0-"
@test isempty(detect_ambiguities(FixedPointNumbers, Base, Core))
end
@test isempty(detect_ambiguities(FixedPointNumbers, Base, Core))

for f in ["normed.jl", "fixed.jl"]
println("Testing $f")
Expand Down