Skip to content

Commit

Permalink
Merge pull request #19779 from JuliaLang/sk/slashfall
Browse files Browse the repository at this point in the history
Integer /: restrict fallback to same-type case (fix #19714)
  • Loading branch information
StefanKarpinski authored Jan 3, 2017
2 parents 8f9036a + d62fe5a commit e0c6887
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ for (fJ, fC) in ((:+, :add), (:-,:sub), (:*, :mul),
end
end

/(x::BigInt, y::BigInt) = float(x)/float(y)

function invmod(x::BigInt, y::BigInt)
z = zero(BigInt)
ya = abs(y)
Expand Down Expand Up @@ -342,6 +344,9 @@ function *(x::BigInt, c::ClongMax)
end
*(c::ClongMax, x::BigInt) = x * c

/(x::BigInt, y::Union{ClongMax,CulongMax}) = float(x)/y
/(x::Union{ClongMax,CulongMax}, y::BigInt) = x/float(y)

# unary ops
for (fJ, fC) in ((:-, :neg), (:~, :com))
@eval begin
Expand Down
4 changes: 3 additions & 1 deletion base/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ typealias BitUnsigned64T Union{Type{UInt8},Type{UInt16},Type{UInt32},Type{UInt64
+{T<:BitInteger}(x::T, y::T) = box(T, add_int(unbox(T,x),unbox(T,y)))
*{T<:BitInteger}(x::T, y::T) = box(T, mul_int(unbox(T,x),unbox(T,y)))

/(x::Integer, y::Integer) = float(x)/float(y)
inv(x::Integer) = float(one(x))/float(x)
/{T<:Integer}(x::T, y::T) = float(x)/float(y)
# skip promotion for system integer types
/(x::BitInteger, y::BitInteger) = float(x)/float(y)

"""
isodd(x::Integer) -> Bool
Expand Down
8 changes: 8 additions & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ let xs = [[i:i+4;] for i in 1:10]
@test max.(xs[1:n]...) == [n:n+4;]
end
end

# issue #19714
immutable T19714 <: Integer end
Base.float(::T19714) = 19714.0
Base.:/(::T19714, ::T19714) = T19714()
Base.convert(::Type{T19714}, ::Int) = T19714()
Base.promote_rule(::Type{T19714}, ::Type{Int}) = T19714
@test T19714()/1 === 1/T19714() === T19714()

0 comments on commit e0c6887

Please sign in to comment.