Skip to content

Commit

Permalink
Integer /: restrict fallback to same-type case (fix #19714)
Browse files Browse the repository at this point in the history
The principle here is that if there's an implementation of a promoted
operator for some type and promotions for that type, unless other
methods are defined, the operation should always be "funnelled"
through the core operator definition for that type. The method for
`/(::Integer, ::Integer)` violated that principle since it would take
precedence in mixed-integer-type division cases even in the presence
of a same-type method definition for a custom integer type and the
appropriate promotion rules.
  • Loading branch information
StefanKarpinski committed Dec 29, 2016
1 parent 9ce0aca commit 087e4b0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/int.jl
Original file line number Diff line number Diff line change
@@ -32,8 +32,9 @@ 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)
/(x::BitInteger, y::BitInteger) = float(x)/float(y)

"""
isodd(x::Integer) -> Bool

0 comments on commit 087e4b0

Please sign in to comment.