Skip to content

Commit

Permalink
Merge pull request #16996 from JuliaLang/nl/bitshift
Browse files Browse the repository at this point in the history
Fix bitshift operators on Bool
  • Loading branch information
JeffBezanson authored Jun 27, 2016
2 parents 861100c + e1e8e9c commit f69dc41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions base/bool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ typemax(::Type{Bool}) = true
(|)(x::Bool, y::Bool) = box(Bool,or_int(unbox(Bool,x),unbox(Bool,y)))
($)(x::Bool, y::Bool) = (x!=y)

>>(x::Bool, c::Unsigned) = Int(x) >> c
<<(x::Bool, c::Unsigned) = Int(x) << c
>>>(x::Bool, c::Unsigned) = Int(x) >>> c

>>(x::Bool, c::Int) = Int(x) >> c
<<(x::Bool, c::Int) = Int(x) << c
>>>(x::Bool, c::Int) = Int(x) >>> c

>>(x::Bool, c::Integer) = Int(x) >> c
<<(x::Bool, c::Integer) = Int(x) << c
>>>(x::Bool, c::Integer) = Int(x) >>> c

signbit(x::Bool) = false
sign(x::Bool) = x
abs(x::Bool) = x
Expand Down
5 changes: 5 additions & 0 deletions test/int.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,8 @@ end

# issue #16700
@test_throws MethodError 1.0 >> 8

# PR #16988
@test true << 2 === 1 << 2
@test true >> 2 === 1 >> 2
@test true >>> 2 === 1 >>> 2

0 comments on commit f69dc41

Please sign in to comment.