Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better fix for #8871 #8893

Merged
merged 1 commit into from
Nov 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mr_empty(f, op::AndFun, T) = true
mr_empty(f, op::OrFun, T) = false

function _mapreduce{T}(f, op, A::AbstractArray{T})
n = length(A)
n = Int(length(A))
if n == 0
return mr_empty(f, op, T)
elseif n == 1
Expand Down
19 changes: 11 additions & 8 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,19 @@ end

# prod

prod(Int[]) === 0
prod(Int8[]) === 0
prod(Float64[]) === 0.0
@test prod(Int[]) === 1
@test prod(Int8[]) === 1
@test prod(Float64[]) === 1.0

prod([3]) === 0
prod([int8(3)]) === 0
prod([3.0]) === 0.0
@test prod([3]) === 3
@test prod([int8(3)]) === 3
@test prod([3.0]) === 3.0

prod(z) === 120
prod(fz) === 120.0
@test prod(z) === 120
@test prod(fz) === 120.0

@test prod(1:big(16)) == big(20922789888000)
@test prod(big(typemax(Int)):big(typemax(Int))+16) == BigInt("25300281663413827620486300433089141956148633919452440329174083959168114253708467653081909888307573358090001734956158476311046124934597861626299416732205795533726326734482449215730132757595422510465791525610410023802664753402501982524443370512346073948799084936298007821432734720004795146875180123558814648586972474376192000")

# check type-stability
prod2(itr) = invoke(prod, (Any,), itr)
Expand Down