We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
mean
For example, it incorrectly computes the mean of the single-element range containing the number 123 as -5 if the element type is Int8:
123
Int8
julia> using Statistics julia> mean(Int8(123):Int8(123)) -5.0
As another example, the mean of the range 126:127 is computed as -1.5 rather than the true mean, which is 126.5:
126:127
julia> mean(Int8(126):Int8(127)) -1.5
Because median delegates to mean, the median is also wrong:
median
julia> median(Int8(123):Int8(123)) -5.0
This is due to a “performance-optimized” mean implementation:
Statistics.jl/src/Statistics.jl
Lines 185 to 188 in 0588f2c
The code mishandles integer overflow, affecting all standard integer types (Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, and UInt64):
Int16
Int32
Int64
UInt8
UInt16
UInt32
UInt64
julia> mean(typemax(Int):typemax(Int)) -1.0 julia> mean(UInt8(255):UInt8(255)) 127.0
Since it also mishandles floating-point overflow, this affects all standard float types (Float16, Float32, and Float64):
Float16
Float32
Float64
julia> mean(Float16(12345):Float16(54321)) Inf16
The mean is computed incorrectly for 25% of all signed integer ranges and 50% of all unsigned integer ranges.
The text was updated successfully, but these errors were encountered:
mean(::AbstractRange)
This should be handled by #115 I think
Sorry, something went wrong.
mean(::UnitRange)
I think all these cases were fixed by #150.
Successfully merging a pull request may close this issue.
For example, it incorrectly computes the mean of the single-element range containing the number
123
as -5 if the element type isInt8
:As another example, the mean of the range
126:127
is computed as -1.5 rather than the true mean, which is 126.5:Because
median
delegates tomean
, the median is also wrong:This is due to a “performance-optimized”
mean
implementation:Statistics.jl/src/Statistics.jl
Lines 185 to 188 in 0588f2c
The code mishandles integer overflow, affecting all standard integer types (
Int8
,Int16
,Int32
,Int64
,UInt8
,UInt16
,UInt32
, andUInt64
):Since it also mishandles floating-point overflow, this affects all standard float types (
Float16
,Float32
, andFloat64
):The mean is computed incorrectly for 25% of all signed integer ranges and 50% of all unsigned integer ranges.
The text was updated successfully, but these errors were encountered: