Skip to content

Commit 5f383dd

Browse files
authored
Merge pull request #3 from JuliaMath/teh/ambs-0.6
Fix and test for ambiguities on 0.6
2 parents 99faf1f + a509e2f commit 5f383dd

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/RoundingIntegers.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Base.promote_rule{T<:Real,RI<:RInteger}(::Type{Complex{T}}, ::Type{RI}) =
7777
promote_type(Complex{T}, itype(RI))
7878
Base.promote_rule{T<:Integer,RI<:RInteger}(::Type{Rational{T}}, ::Type{RI}) =
7979
promote_type(Rational{T}, itype(RI))
80-
Base.promote_rule{s,RI<:RInteger}(::Type{Irrational{s}}, ::Type{RI}) =
81-
promote_type(Irrational{S}, itype(RI))
80+
@compat Base.promote_rule{RI<:RInteger}(::Type{<:Irrational}, ::Type{RI}) =
81+
promote_type(Float64, itype(RI))
8282

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

9292
# Basic conversions
93-
@inline Base.convert{T<:RSigned}(::Type{T}, x::T) = x
94-
@inline Base.convert{T<:RUnsigned}(::Type{T}, x::T) = x
93+
# @inline Base.convert{T<:RSigned}(::Type{T}, x::T) = x
94+
# @inline Base.convert{T<:RUnsigned}(::Type{T}, x::T) = x
95+
@inline Base.convert{T<:RInteger}(::Type{T}, x::T) = x
9596
@inline Base.convert{T<:RInteger}(::Type{T}, x::RInteger) =
9697
RInteger(convert(itype(T), Integer(x)))
9798
@inline Base.convert{T<:RInteger}(::Type{T}, x::Integer) = RInteger(convert(itype(T), x))
@@ -120,6 +121,7 @@ Base.convert{T<:RInteger}(::Type{T}, x::Float16) = RInteger(convert(itype(T), x)
120121
Base.convert(::Type{Bool}, x::RInteger) = convert(Bool, Integer(x))
121122

122123
# rem conversions
124+
@inline Base.rem{T<:RInteger}(x::T, ::Type{T}) = T
123125
@inline Base.rem{T<:RInteger}(x::Integer, ::Type{T}) = RInteger(rem(x, itype(T)))
124126
# ambs
125127
@inline Base.rem{T<:RInteger}(x::BigInt, ::Type{T}) = error("no rounding BigInt available")
@@ -133,6 +135,7 @@ Base.flipsign(x::RSigned, y::RSigned) = RInteger(flipsign(Integer(x), Integer(y)
133135
Base.count_ones(x::RInteger) = count_ones(Integer(x))
134136
Base.leading_zeros(x::RInteger) = leading_zeros(Integer(x))
135137
Base.trailing_zeros(x::RInteger) = trailing_zeros(Integer(x))
138+
Base.ndigits0z(x::RInteger) = Base.ndigits0z(Integer(x))
136139

137140
# A few operations preserve the type
138141
-(x::RInteger) = RInteger(-Integer(x))

test/runtests.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
using RoundingIntegers
21
using Compat, Base.Test
3-
4-
@test isempty(detect_ambiguities(Base, Core, RoundingIntegers))
2+
if VERSION < v"0.6.0-pre.alpha.229"
3+
using RoundingIntegers
4+
@test isempty(detect_ambiguities(Base, Core, RoundingIntegers))
5+
else
6+
ambs0 = detect_ambiguities(Base, Core, Compat)
7+
using RoundingIntegers
8+
ambs1 = detect_ambiguities(Base, Core, Compat, RoundingIntegers)
9+
@test isempty(setdiff(ambs1, ambs0))
10+
end
511

612
@testset "Basics" begin
713
r16 = RInt16(3)
@@ -55,6 +61,8 @@ using Compat, Base.Test
5561
@test copysign(r, r) === r
5662
@test unsigned(r) === RUInt(5)
5763
@test hex(r) == "5"
64+
65+
@test string(RInt(7.2)) == "7"
5866
end
5967

6068
@testset "Rounding" begin

0 commit comments

Comments
 (0)