Skip to content

Commit

Permalink
relax type definition of middle
Browse files Browse the repository at this point in the history
this adds support for computing the median of unitful types, see PainterQubits/Unitful.jl#202
  • Loading branch information
tlnagy authored Mar 3, 2020
1 parent 542f57e commit 418a096
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,15 +713,15 @@ Compute the middle of a scalar value, which is equivalent to `x` itself, but of
middle(x::Union{Bool,Int8,Int16,Int32,Int64,Int128,UInt8,UInt16,UInt32,UInt64,UInt128}) = Float64(x)
# Specialized functions for real types allow for improved performance
middle(x::AbstractFloat) = x
middle(x::Real) = (x + zero(x)) / 1
middle(x::Number) = (x + zero(x)) / 1

"""
middle(x, y)
Compute the middle of two reals `x` and `y`, which is
equivalent in both value and type to computing their mean (`(x + y) / 2`).
"""
middle(x::Real, y::Real) = x/2 + y/2
middle(x::Number, y::Number) = x/2 + y/2

"""
middle(range)
Expand Down

0 comments on commit 418a096

Please sign in to comment.