Skip to content

Commit

Permalink
Merge pull request #3 from JuliaMath/teh/ambs-0.6
Browse files Browse the repository at this point in the history
Fix and test for ambiguities on 0.6
  • Loading branch information
timholy authored Mar 23, 2017
2 parents 99faf1f + a509e2f commit 5f383dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/RoundingIntegers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Base.promote_rule{T<:Real,RI<:RInteger}(::Type{Complex{T}}, ::Type{RI}) =
promote_type(Complex{T}, itype(RI))
Base.promote_rule{T<:Integer,RI<:RInteger}(::Type{Rational{T}}, ::Type{RI}) =
promote_type(Rational{T}, itype(RI))
Base.promote_rule{s,RI<:RInteger}(::Type{Irrational{s}}, ::Type{RI}) =
promote_type(Irrational{S}, itype(RI))
@compat Base.promote_rule{RI<:RInteger}(::Type{<:Irrational}, ::Type{RI}) =
promote_type(Float64, itype(RI))

(::Type{Signed})(x::RSigned) = reinterpret(itype(x), x)
(::Type{Unsigned})(x::RUnsigned) = reinterpret(itype(x), x)
Expand All @@ -90,8 +90,9 @@ Base.promote_rule{s,RI<:RInteger}(::Type{Irrational{s}}, ::Type{RI}) =
(::Type{RInteger})(x::Unsigned) = RUnsigned(x)

# Basic conversions
@inline Base.convert{T<:RSigned}(::Type{T}, x::T) = x
@inline Base.convert{T<:RUnsigned}(::Type{T}, x::T) = x
# @inline Base.convert{T<:RSigned}(::Type{T}, x::T) = x
# @inline Base.convert{T<:RUnsigned}(::Type{T}, x::T) = x
@inline Base.convert{T<:RInteger}(::Type{T}, x::T) = x
@inline Base.convert{T<:RInteger}(::Type{T}, x::RInteger) =
RInteger(convert(itype(T), Integer(x)))
@inline Base.convert{T<:RInteger}(::Type{T}, x::Integer) = RInteger(convert(itype(T), x))
Expand Down Expand Up @@ -120,6 +121,7 @@ Base.convert{T<:RInteger}(::Type{T}, x::Float16) = RInteger(convert(itype(T), x)
Base.convert(::Type{Bool}, x::RInteger) = convert(Bool, Integer(x))

# rem conversions
@inline Base.rem{T<:RInteger}(x::T, ::Type{T}) = T
@inline Base.rem{T<:RInteger}(x::Integer, ::Type{T}) = RInteger(rem(x, itype(T)))
# ambs
@inline Base.rem{T<:RInteger}(x::BigInt, ::Type{T}) = error("no rounding BigInt available")
Expand All @@ -133,6 +135,7 @@ Base.flipsign(x::RSigned, y::RSigned) = RInteger(flipsign(Integer(x), Integer(y)
Base.count_ones(x::RInteger) = count_ones(Integer(x))
Base.leading_zeros(x::RInteger) = leading_zeros(Integer(x))
Base.trailing_zeros(x::RInteger) = trailing_zeros(Integer(x))
Base.ndigits0z(x::RInteger) = Base.ndigits0z(Integer(x))

# A few operations preserve the type
-(x::RInteger) = RInteger(-Integer(x))
Expand Down
14 changes: 11 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using RoundingIntegers
using Compat, Base.Test

@test isempty(detect_ambiguities(Base, Core, RoundingIntegers))
if VERSION < v"0.6.0-pre.alpha.229"
using RoundingIntegers
@test isempty(detect_ambiguities(Base, Core, RoundingIntegers))
else
ambs0 = detect_ambiguities(Base, Core, Compat)
using RoundingIntegers
ambs1 = detect_ambiguities(Base, Core, Compat, RoundingIntegers)
@test isempty(setdiff(ambs1, ambs0))
end

@testset "Basics" begin
r16 = RInt16(3)
Expand Down Expand Up @@ -55,6 +61,8 @@ using Compat, Base.Test
@test copysign(r, r) === r
@test unsigned(r) === RUInt(5)
@test hex(r) == "5"

@test string(RInt(7.2)) == "7"
end

@testset "Rounding" begin
Expand Down

0 comments on commit 5f383dd

Please sign in to comment.