[stdlib] Make comparison operator choices consistent

This commit is contained in:
Arsen Gasparyan
2015-12-16 14:21:33 +03:00
parent 4002758844
commit 9f728c6dbd
3 changed files with 55 additions and 50 deletions

View File

@@ -74,27 +74,15 @@ public func min<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
/// Returns the greater of `x` and `y`.
@warn_unused_result
public func max<T : Comparable>(x: T, _ y: T) -> T {
var r = y
if y < x {
r = x
}
return r
return y >= x ? y : x
}
/// Returns the greatest argument passed.
@warn_unused_result
public func max<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
var r = y
if y < x {
r = x
}
if r < z {
r = z
}
for t in rest {
if t >= r {
r = t
}
var r = max(max(x, y), z)
for t in rest where t >= r {
r = t
}
return r
}