According to this answer, to obtain the maximum of an array we can do:
let nums = [1, 6, 3, 9, 4, 6];
let numMax = nums.reduce(Int.min, { max($0, $1) })
You can use -FLT_MAX
which returns minimum magnitude of Float
and used for same purpose
let numMax = floats.reduce(-FLT_MAX, { max($0, $1) })
For Double
array you can use -DBL_MAX
If you want maximum magnitude value of Float
use FLT_MAX
.FLT_MIN
is Minimum representable postive floating-point number.