Skip to content

Instantly share code, notes, and snippets.

@fluidsonic
Last active August 29, 2015 14:20
Show Gist options
  • Save fluidsonic/4e81aa2000b7dc62b099 to your computer and use it in GitHub Desktop.
Save fluidsonic/4e81aa2000b7dc62b099 to your computer and use it in GitHub Desktop.
Randomly returns totally wrong values with Swift optimizations (-O) turned on
public func optionalMax <T: Comparable>(elements: T? ...) -> T? {
var maximumElement: T?
for element in elements {
if let element = element {
if let existingMaximumElement = maximumElement {
if element > existingMaximumElement {
maximumElement = element
}
}
else {
maximumElement = element
}
}
}
return maximumElement
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment