added minmax function (that ignores +-inf)