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 committed Oct 1, 2020
1 parent b384104 commit 97b2777
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 @@ -735,15 +735,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 97b2777

Please sign in to comment.