Skip to content

Commit

Permalink
Fix complex constructors
Browse files Browse the repository at this point in the history
Add some tests
  • Loading branch information
andreasnoack committed Feb 1, 2018
1 parent fe45399 commit c6ebe4e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct Fixed{T <: Signed,f} <: FixedPoint{T, f}
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}(real(x))
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,S} = Fixed{T, f}(convert(Float64, x))
end

Expand Down
2 changes: 1 addition & 1 deletion src/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct Normed{T<:Unsigned,f} <: FixedPoint{T,f}
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}(real(x))
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,S} = Normed{T, f}(convert(Float64, x))
end

Expand Down
6 changes: 6 additions & 0 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,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)) == 1
7 changes: 7 additions & 0 deletions test/normed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,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)) == 1

0 comments on commit c6ebe4e

Please sign in to comment.