From 97b27776aa1c937c721684e1c93818d6c4265f4e Mon Sep 17 00:00:00 2001 From: Tamas Nagy Date: Mon, 2 Mar 2020 22:35:19 -0800 Subject: [PATCH] relax type definition of middle this adds support for computing the median of unitful types, see https://github.com/PainterQubits/Unitful.jl/issues/202 --- src/Statistics.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Statistics.jl b/src/Statistics.jl index b3bf26b3..23eeeb60 100644 --- a/src/Statistics.jl +++ b/src/Statistics.jl @@ -735,7 +735,7 @@ 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) @@ -743,7 +743,7 @@ middle(x::Real) = (x + zero(x)) / 1 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)