Skip to content

Commit

Permalink
Fix mod1
Browse files Browse the repository at this point in the history
Restore old implementation of mod1 that was overwritten in
3842422

Adds test of mod1 behavior from #5570

Note: #5570 is not fixed for fld1, rem1. The documentation bug of #8108
is not fixed.
  • Loading branch information
jiahao committed Jan 6, 2015
1 parent 930cfe6 commit e5aac24
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const % = rem
const ÷ = div

# mod returns in [0,y) whereas mod1 returns in (0,y]
mod1{T<:Real}(x::T, y::T) = y-mod(y-x,y)
mod1{T<:Real}(x::T, y::T) = (m=mod(x,y); m==0 ? y : m)
rem1{T<:Real}(x::T, y::T) = rem(x-1,y)+1
fld1{T<:Real}(x::T, y::T) = fld(x-1,y)+1

Expand Down
4 changes: 4 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2086,3 +2086,7 @@ end
let x = big(-0.0)
@test signbit(x) && !signbit(abs(x))
end

#Issue #5570
@test map(x -> int(mod1(uint(x),uint(5))), 0:15) == [5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5]

0 comments on commit e5aac24

Please sign in to comment.