I think the functions should be under FloatingPoint
itself, like FloatingPoint.minimum(_:_:)
and FloatingPoint.maximum(_:_:)
.
I also think it would be a good idea to have a separate clamped(to:)
method as an extension to the Comparable
protocol, like what @jawbroken suggested.
I don’t think it’s a good idea to apply this to integers — the rounding (or Double
-converting) behavior may be unexpected to users. If a programmer really needed a function like this, then they could make it themselves.
I also don’t think it’s a good idea to use variadic parameters here — this function would be useful for any collection of floating-point numbers.
If we add a median function, we should probably add functions like arithmeticMean
, mode
, range
, and maybe geometricMean
. We might also want to consider making numerical computing more of a priority in general (do people still like the idea of a numerical/ML working group?). I think Swift has a lot of potential for numerical computing, but it doesn’t yet reach its potential. (The standard library doesn’t even have a sin
or log
function!)