# Middle(x,y) for DateTime, Char, and others

Should these methods exist?

``````  middle(x, y)

Compute the middle of two numbers x and y, which is equivalent in both value and
type to computing their mean ((x + y) / 2).

julia> middle(now(), now())
ERROR: MethodError: no method matching middle(::DateTime, ::DateTime)

julia> middle('a','c')
ERROR: MethodError: no method matching middle(::Char, ::Char)
``````
• `Char` seems likely.
• For `DateTime`, which has 1 ms precision, I’m not sure what the rounding rules are.
• For `Date`, which has 1 day precision, likewise.
• Are there other types that should have these methods?
1 Like

What would `middle('a','b')` return?

Considering that this function is in the Statistics module, I’m not sure it makes sense to define it for non-numeric types like `Char`.

1 Like

I don’t see that statistics applies only to numbers. Affine quantities like Dates and Fahrenheits can theoretically all compute midpoints by something like (though not exactly)

``````middle(x,y) = (x - y) / 2 + y
``````

``````(x + y) / 2
I propose it would give an InexactError, as would `middle(today, tomorrow)`.
On the other hand, `middle(yesterday, tomorrow) == today` and `middle(32.0°F, 33.0°F) == 32.5°F` where currently it fails on division.