-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
mathsMathematical functionsMathematical functions
Description
Contrary to the mean(::AbstractArray) method, the mean fallback for general iterables computes the sum without promoting the element type, meaning that overflow can easily happen:
julia> mean([typemax(Int8), typemax(Int8)])
127.0
julia> mean(x for x in [typemax(Int8), typemax(Int8)])
-1.0Apart from being inconvenient/risky, it's inconsistent with sum:
julia> sum([typemax(Int8), typemax(Int8)])
254
julia> sum(x for x in [typemax(Int8), typemax(Int8)])
254I think we should use promote_sys_size_add added by #22825 to choose the accumulation type, just like sum.
Metadata
Metadata
Assignees
Labels
mathsMathematical functionsMathematical functions